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

Task Reminder System

Build a simple task reminder system that executes scheduled tasks at specific times using cron-based scheduling.

Requirements

Create a task reminder system with the following functionality:

Core Features

  1. Task Scheduling: The system should allow scheduling tasks to run at specific intervals defined by cron expressions.

  2. Task Execution: When a scheduled time arrives, the system should execute a callback function that logs a reminder message to the console with the format: "REMINDER: [task name] - [message]".

  3. Task Control: The system should support:

    • Starting a scheduled task
    • Stopping a scheduled task
    • Automatic start option when creating a task
  4. Multiple Tasks: The system should be able to manage multiple independent scheduled tasks simultaneously.

Implementation Details

Create a module that exports the following:

  • A function createReminder(name, message, schedule, autoStart) that creates a new task reminder

    • name: string identifier for the task
    • message: the reminder message to display
    • schedule: a cron expression string (e.g., "*/5 * * * * *" for every 5 seconds)
    • autoStart: boolean indicating whether to start the task immediately (default: false)
    • Returns an object with start() and stop() methods
  • A function createDailyReminder(name, message, hour, minute) that creates a daily reminder at a specific time

    • name: string identifier for the task
    • message: the reminder message to display
    • hour: hour of day (0-23)
    • minute: minute of hour (0-59)
    • Should auto-start by default
    • Returns an object with start() and stop() methods

Test Cases

  • Creating a reminder with autoStart=false does not execute the callback immediately @test
  • Creating a reminder with autoStart=true and schedule "*/2 * * * * *" logs the reminder message within 2.5 seconds @test
  • Calling stop() on a running reminder prevents further scheduled executions @test
  • Creating a daily reminder for 14:30 generates appropriate output and starts automatically @test

Implementation

@generates

API

/**
 * Creates a task reminder that executes on a schedule
 * @param {string} name - The task identifier
 * @param {string} message - The reminder message
 * @param {string} schedule - Cron expression for scheduling
 * @param {boolean} autoStart - Whether to start immediately (default: false)
 * @returns {{start: Function, stop: Function}} Control object with start and stop methods
 */
function createReminder(name, message, schedule, autoStart = false) {
  // Implementation here
}

/**
 * Creates a daily reminder at a specific time
 * @param {string} name - The task identifier
 * @param {string} message - The reminder message
 * @param {number} hour - Hour of day (0-23)
 * @param {number} minute - Minute of hour (0-59)
 * @returns {{start: Function, stop: Function}} Control object with start and stop methods
 */
function createDailyReminder(name, message, hour, minute) {
  // Implementation here
}

module.exports = {
  createReminder,
  createDailyReminder
};

Dependencies { .dependencies }

cron { .dependency }

Provides job scheduling functionality with cron expressions.

@satisfied-by

Install with Tessl CLI

npx tessl i tessl/npm-cron

tile.json