Schedule

Retrying failed tasks is a powerful feature that allows you to improve the reliability of your application. In some cases, though, retrying a failed task isn't enough. In those cases, the attempts option won't suffice. That's where the repeat option comes in.

The repeat option allows you to schedule a task to run at regular intervals. You can specify the pattern in cron syntax, and the limit indicates the number of times the task should run.

Here's an example payload:

import axios from 'axios';

axios.post('https://api.nextcron.co/v1/publish', {
  "topic": "create-todo",
  "target": "https://webhook.site/07e28015-5be9-465d-8621-86d360706317",
  "method": "POST",
  "data": {
    "title": "foo",
    "body": "bar",
    "userId": 1
  },
  "options": {
    "repeat": {
	"pattern": "*/10 * * * * *",
	"limit": 5
    }
  }
}, {
  headers: {
    'X-NextCron-Token': "<insert_your_api_token>"
  }
});

In this example, the payload schedules a task to be run every 10 seconds for a total of 5 times.

This feature is particularly useful for recurring tasks, such as sending a daily summary email or processing a queue at regular intervals.

Note that, just like with the attempts option, the repeat option does not guarantee that the task will be successful. Therefore, you should always handle the case where the task fails.

Last updated