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

Application Startup Synchronization System

Build a system that coordinates initialization tasks with scheduled maintenance jobs. The system should perform initial setup operations immediately when starting, then continue running those same operations on a regular schedule.

Requirements

Your system must:

  1. Execute a data synchronization task immediately when the application starts
  2. Continue running the same synchronization task every 30 seconds after startup
  3. Track all synchronization attempts in a log file with timestamps
  4. Gracefully handle shutdown by stopping all scheduled tasks

Implementation Details

Create a module that implements the following behavior:

  • Immediate Execution: When the scheduler initializes, it should immediately perform a data synchronization operation
  • Regular Schedule: After initialization, the synchronization should continue automatically every 30 seconds
  • Logging: Each synchronization event (both initial and scheduled) should write an entry to sync-log.txt with the current timestamp
  • Shutdown: Provide a mechanism to cleanly stop all scheduled operations

The synchronization operation should:

  • Append a line to sync-log.txt containing: Sync completed at: [ISO timestamp]
  • Use the current date/time in ISO 8601 format

Test Cases

  • The synchronization callback executes immediately upon system initialization @test
  • The synchronization callback executes on the scheduled interval after initialization @test
  • All synchronization events (immediate and scheduled) are logged to the file @test

API

/**
 * Initializes and starts the synchronization system
 * @returns {object} Controller object with a stop() method
 */
function startSyncScheduler() {
  // IMPLEMENTATION HERE
}

module.exports = { startSyncScheduler };

Implementation

@generates

Dependencies { .dependencies }

cron { .dependency }

Provides job scheduling capabilities for Node.js applications.

Install with Tessl CLI

npx tessl i tessl/npm-cron

tile.json