Skip to main content

Cron Jobs

A scheduled method or a cron job is a method that will run periodically. By using a specific cron syntax, you can define the frequency and timing for each method.

tip

The time specified in the cron strings is in UTC. You can use this converter to convert your local time to UTC.

Use scheduled methods in your project

There are two ways to declare a scheduled method:

  • Using decorators (only available for TypeScript, JavaScript and Go projects)
  • Using the genezio.yaml configuration file (available for all supported languages, including TypeScript, JavaScript, Go)
cron.ts
import { GenezioDeploy, GenezioMethod } from "@genezio/types";

@GenezioDeploy()
export class BackendService {
@GenezioMethod({ type: "cron", cronString: "* * * * *" })
sayHiEveryMinute() {
console.log("I will run every minute!");
}
}

Cron strings examples

Below, you have the most commonly used cronString examples:

Cron stringDescription
* * * * *Triggers at every minute
0/5 * * * *Triggers every 5 minutes
0 * * * *Triggers every hour
0 8 * * *Triggers every day at 8 a.m.

You can, also, use crontab.guru to build specific cron strings.

Examples using scheduled methods

info

For more details, check out an example using scheduled methods.

More details

For more information on genezio decorators, check out Genezio Decorators.

Next Steps

Also, you can find more details on deploying the backend and frontend here:

Now you are ready for some more advanced use cases: