If you have tasks that need to be performed periodically, you could set up crontab-like jobs with the builtin app.Cron() (it returns an app scoped cron.Cron value) .

The jobs scheduler is started automatically on app serve, so all you have to do is register a handler with app.Cron().Add(id, cronExpr, handler) or app.Cron().MustAdd(id, cronExpr, handler) (the latter panic if the cron expression is not valid).

Each scheduled job runs in its own goroutine and must have:

Here is one minimal example:

To remove already registered cron job you can call app.Cron().Remove(id)

All registered app level cron jobs can be also previewed and triggered from the {"Dashboard > Settings > Crons"} section.

Keep in mind that the app.Cron() is also used for running the system scheduled jobs like the logs cleanup or auto backups (the jobs id is in the format __pb*__) and replacing these system jobs or calling RemoveAll()/Stop() could have unintended side-effects.

If you want more advanced control you can initialize your own cron instance independent from the application via cron.New().