task(), in any file of src/, and exported. It says when to run and what to do; ChapterJS runs it once the bot is connected, and keeps running it for as long as the bot is online.
src/tasks/report.ts
Everything a task file declares is in the reference.
Every so often
every is a duration: a number and a unit, s, m, h or d. The task runs at that interval, counted from the moment the bot connects.
src/tasks/cleanup.ts
'30s', '10m', '2h', '1d' and '1h30m' all work; once per second is the fastest.
At given times
cron is a standard cron expression: minute, hour, day of month, month and day of week.
Without
timezone, the task follows the clock of the machine the bot runs on. With one ('Europe/Paris', 'America/New_York'…), it follows that clock, changes of daylight saving time included: a time that does not exist that day is skipped, a time that comes twice runs once.
A cron that is wrong, or that never happens ('0 0 31 2 *'), is an error when the file loads, with what to write.
Running right away
onStart: true also runs the task once as soon as the bot is connected, without waiting for its first time:
src/tasks/status.ts
What run receives
When a run takes long, or fails
A run that is still going when the next time comes is not started twice: that time is skipped, and your terminal says so.In development, in production
Inchapterjs dev, saving a task file replaces what it does without changing when: a task that runs every hour keeps its next time through the reload. Changing every or cron counts the task again from the save. In chapterjs start, a bot split over several processes runs each task once, in its first process.
task() reference
Every field of a task file, and what run receives.
Sending messages
What a task can post, and where.