diff --git a/CHANGELOG.md b/CHANGELOG.md index 99645fa..5ebedc9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 --- +## [Unreleased] + +### Fixed +- The receiving health check's test email is sent every 10 minutes again. Before, it only went out once after each restart, so the check reported receiving as degraded when it was working + +--- + ## [0.9.3] - 2026-10-21 ### Added @@ -1082,7 +1089,8 @@ Initial public beta release of ByteSend: an all-in-one email infrastructure plat --- -[Unreleased]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.2...HEAD +[Unreleased]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.3...HEAD +[0.9.3]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.2...v0.9.3 [0.9.2]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.1...v0.9.2 [0.9.1]: https://github.com/ByteSendApp/ByteSend/compare/v0.9.0...v0.9.1 [0.9.0]: https://github.com/ByteSendApp/ByteSend/compare/v0.8.0...v0.9.0 diff --git a/apps/web/src/server/jobs/inbound-job.ts b/apps/web/src/server/jobs/inbound-job.ts index 2e6e24b..1bee7d6 100644 --- a/apps/web/src/server/jobs/inbound-job.ts +++ b/apps/web/src/server/jobs/inbound-job.ts @@ -4,7 +4,7 @@ import { DEFAULT_QUEUE_OPTIONS, INBOUND_CLEANUP_QUEUE, INBOUND_QUEUE } from "../ import { logger } from "../logger/log"; import { deleteExpiredInbound, processInbound, type SesInboundNotification } from "../service/inbound-service"; import { deleteExpiredDmarcReports } from "../service/dmarc-service"; -import { INBOUND_CANARY_INTERVAL_MS, inboundCanaryAddress, sendInboundCanary } from "../service/inbound-canary"; +import { inboundCanaryAddress, sendInboundCanaryIfDue } from "../service/inbound-canary"; let inboundQueue: Queue | null = null; let initialized = false; @@ -49,11 +49,7 @@ export async function initInboundJobs() { const cleanupQueue = new Queue(INBOUND_CLEANUP_QUEUE, { connection, prefix: BULL_PREFIX, skipVersionCheck: true }); const cleanupWorker = new Worker( INBOUND_CLEANUP_QUEUE, - async (job) => { - if (job.name === "canary") { - await sendInboundCanary(); - return; - } + async () => { const deleted = await deleteExpiredInbound(); const reports = await deleteExpiredDmarcReports(); logger.info({ deleted, reports }, "[InboundJob]: Removed expired received mail and DMARC reports"); @@ -62,14 +58,11 @@ export async function initInboundJobs() { ); cleanupWorker.on("failed", (job, err) => logger.error({ err, jobId: job?.id }, "[InboundJob]: Cleanup failed")); await cleanupQueue.upsertJobScheduler("inbound-cleanup-daily", { pattern: "40 3 * * *", tz: "UTC" }, { opts: { ...DEFAULT_QUEUE_OPTIONS } }); + await cleanupQueue.removeJobScheduler("inbound-canary"); if (inboundCanaryAddress()) { - await cleanupQueue.upsertJobScheduler( - "inbound-canary", - { every: INBOUND_CANARY_INTERVAL_MS }, - { name: "canary", opts: { ...DEFAULT_QUEUE_OPTIONS } }, - ); - } else { - await cleanupQueue.removeJobScheduler("inbound-canary"); + const tick = () => sendInboundCanaryIfDue().catch((error) => logger.error({ err: error }, "[InboundJob]: Canary failed")); + void tick(); + setInterval(tick, 60_000).unref(); } initialized = true; diff --git a/apps/web/src/server/service/inbound-canary.ts b/apps/web/src/server/service/inbound-canary.ts index 3bc59de..19ece80 100644 --- a/apps/web/src/server/service/inbound-canary.ts +++ b/apps/web/src/server/service/inbound-canary.ts @@ -38,6 +38,11 @@ export async function sendInboundCanary() { logger.info({ address }, "[InboundCanary]: Sent"); } +export async function sendInboundCanaryIfDue() { + const claimed = await getRedis().set(redisKey("inbound:canary:lock"), String(Date.now()), "PX", INBOUND_CANARY_INTERVAL_MS - 30_000, "NX"); + if (claimed) await sendInboundCanary(); +} + export async function getInboundCanaryTimes() { const [first, sent, seen] = await getRedis().mget(redisKey(FIRST_SENT_KEY), redisKey(LAST_SENT_KEY), redisKey(LAST_SEEN_KEY)); return {