nestjs cron job is not triggered

I've a nestjs cron job that runs OK locally but it is not triggered in GCP.  My code is delivered as docker. See the implementation below.
Any special service that I should activate or configuration I should do in GCP?
My Cron code:
 

@Cron(CronExpression.EVERY_DAY_AT_9AM)
  myCronMethod() {
    console.log("Called my cron method");
  }
2 1 77
1 REPLY 1

Hi @mailhaim,

Welcome to Google Cloud Community!

Your NestJS cron job defined with @Cron(CronExpression.EVERY_DAY_AT_9AM) works locally but not on GCP when deployed as a Docker container.

Causes:

  • Cron Expression: Double-check its accuracy. Use a validator online.
  • Logging and Errors: Implement robust logging in myCronMethod and ensure logs are stored persistently in GCP.
  • GCP Environment: Verify cron job registration in the container using crontab -l. Consider using Cloud Scheduler if you're on App Engine Flexible.
  • Docker Image: Ensure the image has crontab installed.

Solutions:

  • Follow troubleshooting steps: verify expression, check logs, debug in GCP.
  • Test thoroughly after making changes.
  • Consider using CI/CD for automated deployments.
Top Labels in this Space