Quang Lê
Quang Lê

Reputation: 53

Cron Job is run multiple time on google cloud

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?

Upvotes: 2

Views: 689

Answers (1)

Quang Lê
Quang Lê

Reputation: 53

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.

Upvotes: 1

Related Questions