Taobin-Recipe-Manager/server/git_recipe_worker.go
2023-10-30 10:45:33 +07:00

41 lines
801 B
Go

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)
}
}