AbyssMonitor provide an easy way to setup Cron Task using a distributed manager.
From this tools, you will be able to create a secured task insuring trigger and logging.
Workflow
Setup
First, you have to create a new Cron Task on your Application interface.
A new card is added. You can edit your Cron Task and copy the secret signature.
Authentifie Cron Task request
Using the secret signature, you can authentifie the request.
import {
HEADER_SIGNATURE_NAME,
SIGNATURE_ALGORITHM,
} from '@abyss-project/monitor';
const headerSignature = req.headers[HEADER_SIGNATURE_NAME];
const hmac = crypto.createHmac(
SIGNATURE_ALGORITHM,
"my-secret-signature",
);
const signature = hmac.update(JSON.stringify(req.body)).digest('hex');
if (headerSignature !== signature) {
// Throw an error
throw new Error('Invalid Signature');
}
// The signature is correct
// Response with the requestId of the AbyssMonitor logger to link logs to the cronTask
// ex: res.status(200).json(getRequestContext().requestId);
Your Cron Task can generate logs. Logs will be linked to the Cron Task to debug easily.
Check code example above.
Workflow for distributed Cron Task on AbyssMonitor