From 877e48abedb3a3a969ddcde6a98d316e610dd126 Mon Sep 17 00:00:00 2001 From: Xevion Date: Tue, 5 Sep 2023 15:31:26 -0500 Subject: [PATCH] Implement dry run, remove ?force from README --- README.md | 1 - src/pages/api/cron.ts | 15 ++++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 26ee3b6..c55548b 100644 --- a/README.md +++ b/README.md @@ -67,7 +67,6 @@ might be easier (although I require Node APIs, I believe). - `/api/cron` is the primary cron-job endpoint. Authorization required. - `?report=true` is assumed, and when `true`, Cronitor will be notified of the job's status. - `?dry=true` will not send any notifications or effects, but will still perform all checks and logging for runtime testing. - - `?force=true` will skip configuration time checks and send notifications regardless of how long it's been since the last notification. - `/api/health` is a simple health check endpoint. Authorization optional. - `/api/check` is a simple endpoint to check authorization. - `/api/config` is the configuration endpoint. Authorization required. diff --git a/src/pages/api/cron.ts b/src/pages/api/cron.ts index 428cb63..c44c201 100644 --- a/src/pages/api/cron.ts +++ b/src/pages/api/cron.ts @@ -87,10 +87,19 @@ export default async function handler( identifier }; + const isDry = parseBoolean(req.query.dry ?? 'false'); + logger.info( + !isDry + ? 'Sending notification, marking identifier.' + : 'Dry run, not sending notification or marking identifier.', + { identifier } + ); + // Send notification, mark (expire in 1 month) - logger.info('Sending notification, marking identifier.', { identifier }); - await sendNotification(`${matching.message} (${matching.name})`); - await markIdentifier(key, true, 60 * 60 * 24 * 31); + if (!isDry) { + await sendNotification(`${matching.message} (${matching.name})`); + await markIdentifier(key, true, 60 * 60 * 24 * 31); + } return { status: 'notified', identifier }; }