Cron jobs for Node.js applications that enables developers to execute functions or system commands on schedules defined using standard cron syntax
94
Build a status dashboard utility for scheduled jobs that displays when jobs will execute next and provides timing information.
Your implementation should:
Create a function getJobStatus(cronExpression, timezone) that takes a cron expression string and optional timezone string, and returns an object containing:
next: the next execution timeupcoming: an array of the next 5 execution timesmillisecondsUntilNext: the number of milliseconds until the next executionCreate a function getJobHistory(job) that takes an active job object and returns the last execution time (if available)
Create a function formatJobSummary(cronExpression, timezone) that returns a human-readable string showing:
Provides job scheduling and cron expression handling capabilities.
File: scheduler.test.js
const { getJobStatus } = require('./scheduler');
const status = getJobStatus('0 * * * *'); // Run at minute 0 of every hour
console.assert(status.next !== undefined, 'Should return next execution time');
console.assert(Array.isArray(status.upcoming), 'Should return upcoming times array');
console.assert(status.upcoming.length === 5, 'Should return 5 upcoming times');
console.assert(status.millisecondsUntilNext > 0, 'Should return positive milliseconds');
console.log('Test 1 passed');File: scheduler.test.js
const { getJobStatus } = require('./scheduler');
const status = getJobStatus('30 14 * * *', 'America/New_York'); // 2:30 PM EST daily
console.assert(status.next !== undefined, 'Should return next execution time');
console.assert(status.upcoming.length === 5, 'Should return 5 upcoming times');
console.log('Test 2 passed');File: scheduler.test.js
const { formatJobSummary } = require('./scheduler');
const summary = formatJobSummary('0 12 * * *', 'UTC'); // Noon UTC daily
console.assert(typeof summary === 'string', 'Should return a string');
console.assert(summary.includes('0 12 * * *'), 'Should include cron expression');
console.assert(summary.includes('UTC'), 'Should include timezone');
console.log('Test 3 passed');Install with Tessl CLI
npx tessl i tessl/npm-cronevals
scenario-1
scenario-2
scenario-3
scenario-4
scenario-5
scenario-6
scenario-7
scenario-8
scenario-9
scenario-10