// src/jobs.mjs, the service's scheduled handlers, one for each schedule // manifest.json declares // // manifest.json declares one schedule, heartbeat, due once an hour. The // minute in its cron is the minute of the hour, in UTC, at which the // scaffold wrote this service, so that the services written from this // template are not all due at the same moment. Any minute serves: the cron // is yours to change, to any timetable your plan's shortest interval admits. // // A run of the same due time can reach the handler twice. This handler only // prints a line, which is safe to repeat, so it keeps no record of the runs // it has handled. A handler whose effect must not repeat records the run's // key first, in a row of a database or a file in a storage area, and skips // the effect where the key is recorded already. // // On the platform only the platform's own runs reach a handler's path with // the four headers the router admits a run by. On your machine any caller // that reaches the service's port can send them, which matters once a // handler does more than print. export const jobs = { // Prints one line, naming the schedule and the run's key, and answers // nothing, so the router answers 200 with a JSON body naming the run. heartbeat: (run) => { console.log(`schedule ${run.schedule} ran, key ${run.key}`); }, };