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-4/

Task Scheduler with Metrics Tracking

Build a task scheduler that executes scheduled tasks and tracks execution metrics using multiple callbacks.

Requirements

Create a scheduler system that:

  1. Schedules a task to run every 5 seconds
  2. Executes a primary task action when the schedule triggers
  3. Tracks execution metrics (count, timestamps) using additional callbacks
  4. Logs summary statistics when the scheduler is stopped
  5. Properly manages the task lifecycle (start and stop)

Your implementation should:

  • Create a scheduled job that runs every 5 seconds
  • Execute a main task callback that increments a counter
  • Add a metrics tracking callback that records execution timestamps
  • Execute a cleanup callback when the job stops that displays:
    • Total number of executions
    • List of all execution timestamps
  • Provide functions to start and stop the scheduler
  • Ensure the scheduler can run for a specified duration and then stop automatically

Test Cases

  • The scheduler executes the main task at the scheduled interval @test
  • Multiple callbacks are executed for each scheduled trigger @test
  • The cleanup callback executes when the scheduler stops @test

Implementation

@generates

API

/**
 * Creates and configures a task scheduler with metrics tracking
 * @param {Object} config - Configuration object
 * @param {Function} config.taskCallback - Main task to execute on schedule
 * @param {Function} config.metricsCallback - Callback to track execution metrics
 * @param {Function} config.onComplete - Callback executed when scheduler stops
 * @returns {Object} Scheduler instance with start() and stop() methods
 */
function createScheduler(config) {
  // IMPLEMENTATION HERE
}

module.exports = { createScheduler };

Dependencies { .dependencies }

cron { .dependency }

Provides job scheduling capabilities for executing callbacks on a time-based schedule.

Install with Tessl CLI

npx tessl i tessl/npm-cron

tile.json