Bars Icon

Deno adds Deno Cron for job scheduling

18-12-2023 11:51 AM

Deno Land, the developers of the Deno TypeScript/JavaScript runtime, have introduced Deno Cron, a feature the company describes as an easy way to create scheduled jobs.

Announced November 29 and available behind the –unstable flag in Deno 1.38, Deno.cron() is a function that takes three parameters: the name of the scheduled job, the schedule, and the handler, the latter being the function executed on the schedule provided. Deno Cron’s schedule uses the Unix cron format and the UTC time zone. Deno Cron handlers can perform actions such as updating state in Deno KV, pinging a website, sending email, initiating a database backup, and calling an API at regular intervals. Unlike cron jobs on Unix and Linux, Deno Cron executions do not overlap. Hence, if an operator schedules a job to run every 10 minutes but the task takes 30 minutes, Deno Cron automatically skips the next scheduled run until the task is finished. Overlapping cron jobs can lead to unintended issues and require extra logic to avoid, Deno Land said; Deno Deno Cron sidesteps that. Deno Land also is working to support a JavaScript-friendly API to specify the cron schedule.
In explaining the rationale behind Deno Cron, Deno Land said building for the web has become increasingly complex. Modern software uses cloud infrastructure, dissects boilerplate code, and manages intricate configurations. But developers just want to focus on business logic. Deno Land strives to ease web development by removing config and unnecessary boilerplate. Like Deno KV and Deno Queues, which can be added to an application with only a few lines of code, Deno Cron is designed to make web development simpler, the company said.

On the Deno Deploy serverless JavaScript platform, Deno.cron() is automatically managed, allowing users to run cron jobs without a web server or even consistent requests to keep an isolate alive. Whenever a project is deployed, Deno Deploy automatically detects cron jobs and evaluates them. When it is time for a handler to run, Deno Deploy automatically spins an isolate on-demand to run it. A Cron tab has been added to the Deno Deploy dashboard to show active cron jobs in a project.