api/docs/content/doc/development/cron.md
Dominik Pschenitschni aaa0593289 feat(docs): various improvements
- removing spaces at end of line
- fixing spelling and grammar mistakes
- making sure 'Vikunja' is spelled the same way everywhere
- prefer using editors word wrap instead of hardcoding word wrap in markdown (reason: different word wrap per editor & end of line space)
- add newline add end where missing
- remove double colon at end of headlines
- remove unnecessary indention
- make sure code blocks and headlines etc always have an empty line around
2023-04-11 16:42:59 +00:00

1.1 KiB

title date draft menu
Cron Tasks 2021-07-13T23:21:52+02:00 false
sidebar
parent
development

How to add a cron job task

Cron jobs are tasks which run on a predefined schedule. Vikunja uses these through a light wrapper package around the excellent github.com/robfig/cron package.

The package exposes a cron.Schedule method with two arguments: The first one to define the schedule when the cron task should run, and the second one with the actual function to run at the schedule. You would then create a new function to register your the actual cron task in your package.

A basic function to register a cron task looks like this:

{{< highlight golang >}} func RegisterSomeCronTask() { err := cron.Schedule("0 * * * *", func() { // Do something every hour } } {{< /highlight >}}

Call the register method in the FullInit() method of the init package to actually register it.

Schedule Syntax

The cron syntax uses the same on you may know from unix systems.

It is described in detail here.