Modules@robinpath/scheduler
scheduler

@robinpath/scheduler

0.1.1Node.jsPublic

Schedule and run recurring or one-time tasks with cron expressions, pause/resume support, and execution history

Scheduler

Schedule and run recurring or one-time tasks with cron expressions, pause/resume support, and execution history

Package: @robinpath/scheduler | Category: Infrastructure | Type: Utility

Authentication

No authentication required. All functions are available immediately.

Use Cases

Use the scheduler module when you need to:

  • Schedule a recurring task using a cron expression -- Use scheduler.schedule to perform this operation
  • Schedule a one-time task at a specific date/time or after a delay in ms -- Use scheduler.once to perform this operation
  • Cancel a scheduled task by id -- Use scheduler.cancel to perform this operation
  • Cancel all scheduled tasks -- Use scheduler.cancelAll to perform this operation
  • List all scheduled tasks with their next run times -- Use scheduler.list to perform this operation

Quick Reference

FunctionDescriptionReturns
scheduleSchedule a recurring task using a cron expression{ id, nextRun, type, cron }
onceSchedule a one-time task at a specific date/time or after a delay in ms{ id, nextRun, type }
cancelCancel a scheduled task by id{ cancelled, id } or { cancelled: false, reason }
cancelAllCancel all scheduled tasks{ cancelled: <count> }
listList all scheduled tasks with their next run timesArray of { id, type, cron, nextRun, paused }
getGet info about a specific scheduled taskTask details or null if not found
pausePause a scheduled task (keeps it but stops execution){ id, paused: true }
resumeResume a paused task{ id, paused: false, nextRun }
isRunningCheck if a task is currently active (not paused and scheduled)True if the task is active
nextRunGet the next run time for a scheduled taskISO date string of the next run
historyGet execution history for a taskArray of { ran, status } entries

Functions

schedule

Schedule a recurring task using a cron expression

Module: scheduler | Returns: object -- { id, nextRun, type, cron }

scheduler.schedule "cleanup" "*/5 * * * *" { action: "runCleanup" }
ParameterTypeRequiredDescription
idstringYesUnique task identifier
cronExpressionstringYesStandard 5-field cron expression
actionobjectYesCallback info object with action name

once

Schedule a one-time task at a specific date/time or after a delay in ms

Module: scheduler | Returns: object -- { id, nextRun, type }

scheduler.once "sendEmail" "2025-12-31T23:59:00Z" { action: "sendNewYearEmail" }
ParameterTypeRequiredDescription
idstringYesUnique task identifier
dateOrDelaystringYesISO date string or delay in milliseconds
actionobjectNoCallback info object with action name

cancel

Cancel a scheduled task by id

Module: scheduler | Returns: object -- { cancelled, id } or { cancelled: false, reason }

scheduler.cancel "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier to cancel

cancelAll

Cancel all scheduled tasks

Module: scheduler | Returns: object -- { cancelled: <count> }

scheduler.cancelAll
ParameterTypeRequiredDescription
(none)NoCall with no arguments

list

List all scheduled tasks with their next run times

Module: scheduler | Returns: array -- Array of { id, type, cron, nextRun, paused }

scheduler.list
ParameterTypeRequiredDescription
(none)NoCall with no arguments

get

Get info about a specific scheduled task

Module: scheduler | Returns: object -- Task details or null if not found

scheduler.get "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier

pause

Pause a scheduled task (keeps it but stops execution)

Module: scheduler | Returns: object -- { id, paused: true }

scheduler.pause "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier to pause

resume

Resume a paused task

Module: scheduler | Returns: object -- { id, paused: false, nextRun }

scheduler.resume "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier to resume

isRunning

Check if a task is currently active (not paused and scheduled)

Module: scheduler | Returns: boolean -- True if the task is active

scheduler.isRunning "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier

nextRun

Get the next run time for a scheduled task

Module: scheduler | Returns: string -- ISO date string of the next run

scheduler.nextRun "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier

history

Get execution history for a task

Module: scheduler | Returns: array -- Array of { ran, status } entries

scheduler.history "cleanup"
ParameterTypeRequiredDescription
idstringYesTask identifier

Error Handling

All functions throw on failure. Common errors:

ErrorCause
No matching cron date found within 1 yearCheck the error message for details
Task id is requiredCheck the error message for details
dateOrDelay is required (ISO string or milliseconds)Check the error message for details
@desc "Schedule and validate result"
do
  set $result as scheduler.schedule "cleanup" "*/5 * * * *" { action: "runCleanup" }
  if $result != null
    print "Success"
  else
    print "No result"
  end
enddo

Recipes

1. List and iterate

Retrieve all items and loop through them.

@desc "List and iterate results"
do
  set $result as scheduler.list
  each $item in $result
    print $item
  end
enddo

2. Multi-step Scheduler workflow

Chain multiple scheduler operations together.

@desc "Schedule, once, and more"
do
  set $r_schedule as scheduler.schedule "cleanup" "*/5 * * * *" { action: "runCleanup" }
  set $r_once as scheduler.once "sendEmail" "2025-12-31T23:59:00Z" { action: "sendNewYearEmail" }
  set $r_cancel as scheduler.cancel "cleanup"
  print "All operations complete"
enddo

3. Safe schedule with validation

Check results before proceeding.

@desc "Schedule and validate result"
do
  set $result as scheduler.schedule "cleanup" "*/5 * * * *" { action: "runCleanup" }
  if $result != null
    print "Success: " + $result
  else
    print "Operation returned no data"
  end
enddo

Related Modules

  • json -- JSON module for complementary functionality

Versions (1)

VersionTagPublished
0.1.1latest1 months ago
Install
$ robinpath add @robinpath/scheduler

Collaborators

Dumitru Balaban
Dumitru Balaban
@dumitru
View all @robinpath modules
Version0.1.1
LicenseMIT
Unpacked Size5.9 KB
Versions1
Weekly Downloads21
Total Downloads21
Stars0
Last Publish1 months ago
Created1 months ago

Category

devops