add git pull worker
This commit is contained in:
parent
70cfd89fc4
commit
15e74d47e3
5 changed files with 71 additions and 37 deletions
41
server/git_recipe_worker.go
Normal file
41
server/git_recipe_worker.go
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"os/exec"
|
||||
"recipe-manager/services/logger"
|
||||
"time"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
func pull_request() error {
|
||||
contextCommand, cancelCommand := context.WithTimeout(context.Background(), 30*time.Second)
|
||||
defer cancelCommand()
|
||||
pull_command := exec.CommandContext(contextCommand, "./git_pull.sh")
|
||||
|
||||
output, err := pull_command.CombinedOutput()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(output) > 0 {
|
||||
if string(output) == "Already up to date." || string(output) == "Coffee recipe updated." {
|
||||
logger.GetInstance().Info("Git pull successful", zap.String("output", string(output)))
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RunGitRecipeWorker() {
|
||||
//pull every 10 minutes
|
||||
for {
|
||||
err := pull_request()
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
}
|
||||
time.Sleep(10 * time.Minute)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue