Distributed Cron Task
Abyss Monitor provides an easy way to trigger distributed Cron Tasks. Each Cron Task is scheduled on the Abyss Monitor side and calls your endpoint at the configured time. This guarantees the trigger and automatically traces every run.
How it works
Abyss Monitor maintains a centralized scheduler. At each tick, it calls the configured URL on your server with a signed request. Your server validates the signature, runs the task, and can return the Abyss Monitor logger request id so any logs produced during the run are attached to the Cron Task.
Create a Cron Task
- Open your Application in Abyss Monitor and go to the Cron Tasks tab.
- Click Create and fill in:
- Name and description,
- Cron expression (e.g.
0 * * * *for every hour), - URL to call on your server,
- HTTP method and optional headers.
- Confirm. A card appears with the Cron Task and its signing secret: copy it to your server.
Authenticate the Cron Task request
The secret signs the request body using HMAC SHA-256. The signature header is abyss-monitor-cron-task-signature.
import crypto from 'crypto';
import {
HEADER_CRON_TASK_SIGNATURE_NAME,
CRON_TASK_SIGNATURE_ALGORITHM,
} from '@abyss-project/monitor';
const headerSignature = req.headers[HEADER_CRON_TASK_SIGNATURE_NAME];
const hmac = crypto.createHmac(
CRON_TASK_SIGNATURE_ALGORITHM,
'my-secret-signature',
);
const signature = hmac.update(JSON.stringify(req.body)).digest('hex');
if (headerSignature !== signature) {
throw new Error('Invalid Signature');
}
// The signature is correct.
// Respond with the requestId of the AbyssMonitor logger to link
// the task's logs to this execution:
// res.status(200).json(getRequestContext().requestId);
Your Cron Task can produce logs through the Abyss Monitor logger. Returning the request id in the response links those logs to the execution so you can inspect them from the Cron Task page.
Run history
Every execution is stored in the Cron Task history: status (success / failure), duration, returned HTTP code, linked logs. It's the place to quickly diagnose a run that didn't succeed.