Taobin-Recipe-Manager/server/git_recipe_worker.go
2023-12-06 20:21:25 +07:00

38 lines
749 B
Go

package main
import (
"context"
"fmt"
"os/exec"
"time"
)
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)
}
}