1.0.6 • Published 11 months ago

cron-worker-threads v1.0.6

Weekly downloads
-
License
ISC
Repository
-
Last release
11 months ago

Node Cron Worker Lib

  • Write cron jobs with typescript
  • Run jobs in parallel with worker_threads

Github repository

Based on node-cron scheduler + time parser (classic cron times like 0/5 * * * *) and worker_threads.

Try this at your own risk! npm i cron-worker-threads

Examples can be found in ./example

Basic usage

You can also add job to executing after starting the scheduler

If job property enabled is set to true, it's immediately added to execution.

If you want to use your custom logger, just pass it to Supervisor constructor after options

Logger should implement ILogger interface

Default logger output

Job communication with parent thread

1) To indicate that job is finished successfully, just return something you want to see in logs that describes job's finish 2) To indicate an error, throw an exception inside run function with error description

Worker status

You can easily get worker status by invoking supervisor method getStat()

It returns object with following fields: 1) poolSize - count of active/waiting worker threads 2) taskPoolSize - count of tasks in processing queue 3) taskProcessing - count of tasks currently processing by workers

Should you use it?

Advantages

  • Cron scheduler starts in separate thread and thus doesn't affect main thread and doesn't depend on its event loop
  • Every cron job implements as a separate TypeScript file that allows you to use all power of typing
  • Every cron job starts in its own thread that allows you to perform complex calculations and CPU intensive tasks with no effect on your server performance
  • Get worker status at every moment of execution

Disadvantages

  • Still in alpha
  • No tests
  • Not all bugs are found
1.0.6

11 months ago

1.0.5

12 months ago

1.0.4

12 months ago

1.0.3

12 months ago

1.0.2

12 months ago

1.0.1

12 months ago

1.0.0

12 months ago