1
votes

i'm having a website that deploy on Google Cloud. The backend server has a cronjob.

func (s *server) startCronJob() error {
    err := s.cron.AddFunc("CRON_TZ=Asia/Saigon 0 9 * * *", s.cronJobFunc)
    if err != nil {
        return err
    }
    s.cron.Start()
    return nil
}
func (s *FBWebHookServer) sendCronProblemToSubscribedUsers() {
    log.Println("Start cron job")
    // DO Smt
    log.Println("Done cron job")
}

The startCronJob is only run once after the deployment. But the cron job was ran multiple time.

A 2020-03-11T02:00:00.000507Z 2020/03/11 02:00:00 Start cron job 
A 2020-03-11T02:00:00.000513Z 2020/03/11 02:00:00 Start cron job 
A 2020-03-11T02:00:00.000584Z 2020/03/11 02:00:00 Start cron job 
A 2020-03-11T02:00:00.000663Z 2020/03/11 02:00:00 Start cron job

I guess it's because of multiple deploy. As I dig into this problem, the number of cron job runs is equal the number of deploy time (gcloud app deploy).

Is there any solution to solve this issue?

1
Which GCP product do you use? Cloud Functions? App Engine? - Serhii Rohoza
I'm using App Engine - Quang Lê
What is your main ? WHat is your app.yaml file? - guillaume blaquiere
I init *server in main.go and app.yaml only has the go version runtime: go113 - Quang Lê
Are you saying that each time you deploy your app another instance of the cron job is started or if you deploy multiple services using gcloud app deploy a cron job is started for each of them. - Gustavo

1 Answers

1
votes

I figured out myself. GCP keeps every old versions of deployment. It doesn't kill old version when i deploy new version. https://cloud.google.com/sdk/gcloud/reference/app/deploy To solve this i have to go to version page and delete all old version.