cron-worker-threads v1.0.6
Node Cron Worker Lib
- Write cron jobs with typescript
- Run jobs in parallel with worker_threads
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