CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-cron

Cron jobs for Node.js applications that enables developers to execute functions or system commands on schedules defined using standard cron syntax

94

1.20x
Overview
Eval results
Files

task.mdevals/scenario-1/

Job Scheduler Status Dashboard

Build a status dashboard utility for scheduled jobs that displays when jobs will execute next and provides timing information.

Requirements

Your implementation should:

  1. 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 time
    • upcoming: an array of the next 5 execution times
    • millisecondsUntilNext: the number of milliseconds until the next execution
  2. Create a function getJobHistory(job) that takes an active job object and returns the last execution time (if available)

  3. Create a function formatJobSummary(cronExpression, timezone) that returns a human-readable string showing:

    • The cron expression
    • The timezone (or "local" if not specified)
    • The next execution time
    • Time remaining until next execution (in seconds)

Implementation Details

  • Support standard cron expressions (5-field format)
  • Handle timezone-aware scheduling
  • All functions should handle cases where the job has not run yet
  • Times should be returned in appropriate formats for display

Dependencies { .dependencies }

cron { .dependency }

Provides job scheduling and cron expression handling capabilities.

Test Cases

Test 1: Get Status for Hourly Job { .test }

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');

Test 2: Get Status with Timezone { .test }

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');

Test 3: Format Job Summary { .test }

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-cron

tile.json