Appwrite tasks allow you to schedule any repeating tasks your app might need to run in the background. Each appwrite task is set by defining a schedule in CRON syntax format and submitting an HTTP endpoint to be executed in a given time.
Each task can define any HTTP endpoint with any given HTTP method, headers or basic HTTP authentication. It is recommended to password protect your HTTP endpoint to make sure only authorized client can access and execute it.
Inside your Appwrite console, you can view all your tasks, their current statuses, previous and next runtime and a response log to view the result of previous executions.
Cron format is a simple, yet powerful and flexible way to define the time and frequency of various actions. The create a new task, you need to supply Appwrite with a valid CRON syntax.
The Appwrite cron parser can handle increments of ranges (e.g. */12, 2-59/3), intervals (e.g. 0-9), lists (e.g. 1,2,3), W to find the nearest weekday for a given day of the month, L to find the last day of the month, L to find the last given weekday of a month, and hash (#) to find the nth weekday of a given month. Learn more about the CRON syntax.
ExamplesSchedule task to execute every 5 minutes
If you want to run your script on 5 minutes interval, configure like below.
5 * * * *
This will be useful for scheduling email reports on daily basis.
0 2 * * *
This type of cron is useful for doing weekly tasks, like log rotation etc.
0 17 * * sun
If you required scheduling a task to be executed for selected days only. Below example will run on each Sunday and Friday at 5 PM.
0 17 * * sun,fri
HTTP payloads that are delivered to your task's configured URL endpoint will contain several special headers:
|X-Appwrite-Task-Name||Name of the task that triggered this delivery.|
|X-Appwrite-Webhook-Name||UID of the task that triggered this delivery.|
|User-Agent||Each request made by Appwrite will be 'Appwrite-Server'|
Appwrite tasks server will treat any none 2** status code resulted from a task execution as an error or a failed task. The server will attempt to execute the failed tasks for 5 more times before changing tasks status to paused and stop future executions.
When a task is paused you should fix the issue resulting on your endpoint and manually change the task status in the Appwrite console. You can use the execution logs in the console to debug your server response.