Urgent.News

What's breaking now, across thousands of outlets.

Tech

Node.js Scheduled Enqueue Example: A Queue Alternative for Background Reports

Put the schedule and the work in separate processes: let a cron trigger enqueue a small, idempotent job record, then let queue workers claim that record and run the long cleanup or report outside the scheduler's 15-minute limit. The deciding constraint is ownership of execution time. A scheduler should own when a job becomes eligible, not the entire lifetime of the job. Short answer: use cron as…

In Node.js applications, handling long-running background jobs efficiently can be achieved by separating the schedule from the work. This can be accomplished by utilizing a cron trigger to enqueue a small, idempotent job record, which is then picked up by queue workers to perform the lengthy cleanup or report generation. The key constraint is that the scheduler should own when a job becomes eligible, rather than managing the entirety of the job's lifecycle.

To implement this pattern in a Node.js service, the focus should be on the message envelope and claim protocol, rather than relying on a specific SDK. The web process should not have to wait for report generation, as it must be capable of restarting without losing the schedule or initiating a new logical run. Each scheduled occurrence should be treated as data, with a stable key derived for cleanup jobs, such as cleanup:2026-08-07T02:00:00Z.

This key should be inserted into the queue atomically, ensuring that even if the trigger runs multiple times, only one insert will succeed, maintaining idempotency.

The message sent to the queue should be concise, containing only the necessary details like job type, logical run time, schema version, tenant or shard identifier, and an idempotency key. Any larger inputs or mutable data should be stored in a durable storage system. It's crucial to avoid placing the entire report dataset within the queue message, as this can lead to issues such as missed jobs and duplicate deliveries.

By maintaining clear states for each runbook stage—whether the occurrence has been recorded, published, claimed, or whether the side effect has been committed—recovery becomes more manageable and less prone to guesswork.

For a Node.js deployment, the trigger can be a minimal script or a dedicated process, ideally isolated from every web replica unless necessary for leader election or uniqueness constraints. The worker could also be implemented in Node.js, consuming the same message envelope and following the same state transitions. The provided Go example demonstrates an interface-driven approach, emphasizing the importance of the protocol's visibility.

The Trigger function sets up the job key and enqueues it, while the WorkOne function claims a job, processes it, and updates its status. This approach ensures that web processes are not burdened with report generation, allowing for seamless restarts and avoiding duplicate runs.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

$30 to $8,880MRR in Six Months: How a PM Who Can't Code Runs an API Gateway Doing 300K Calls a Month

I'm a product manager. I can't write code — not "I'm rusty," not "I know some Python." I cannot write the code that runs my business. Six months ago my product made $30.32. This month it made $8,880.

  • Product manager transformed business from $30 to $8,880 MRR in six months
  • API gateway handles 300,000 calls/month with 95.5% success rate
  • Focus on cheaper models, stability, and heavy user renewals for revenue

How to Test Receipt Templates — Custom-Domain Transactional Email API Ownership

A beginner comparing MailerSend with Amazon SES or another simple transactional email API should not pick the cheapest option for welcome emails until custom-domain authentication and suppression-list…

  • Custom-domain authentication required for transactional email APIs
  • Receipt templates must include order reference, payment state, amount, and support path
  • Testing focuses on final customer artifact and state transitions

More from Saturday 29 August →