Commit Graph

15 Commits

Author SHA1 Message Date
Naz
c0cecd71fe 🐛 Fixed cron expression to read seconds parameter
no issue

- When providing a crontab schedule expression it should always contain 6 elements first one of them being a "seconds" schedule description . For example: '0/5 * * * * *' - meaning to run every 5 seconds
2020-11-24 16:37:46 +13:00
Naz
a7b523e0f3 Bumped bree version to 4.0.0
refs https://github.com/breejs/bree/issues/50
refs f1ab159

- This bree version allows to avoid additional flag setting when initializing scheduled job
2020-11-23 16:03:36 +13:00
Naz
f1ab1597e8 Changed scheduled jobs not run immediately after initialization
refs https://github.com/breejs/bree/issues/50
2020-11-23 14:24:24 +13:00
Naz
986a59abda Moved job metadata attribute to global bree config
no issue

- Because every job is getting this attribute anyways there's no need to keep it nested on per-job bases
2020-11-19 18:15:52 +13:00
Naz
4b18cbcbdb Added support for worker threads in scheduled jobs
no issue

- When jobs are performing CPU intensive tasks they block main process'
event loop. They also can cause memory leaks or unexpected crashes
effectively crashing the parent proccess. To address these issues jobs need to be performed off of main
process. Worker Threads (https://nodejs.org/dist/latest-v12.x/docs/api/worker_threads.html)
are the best candidate for such work.
- These changes introduce an integration on top of bree
(https://github.com/breejs/bree/) which allows to run recurring
jobs in worker thereads. It falls back to child process execution for
Node v10 running without `--experimental-worker` flag.
- bree was chosen not only because it gives a polyfill for older Node
versions. It has support for some of the future use-cases Ghost is looking to
implement, like scheduled jobs.
- This changeset also includes a complete example of job running on an
interval with a possibility for graceful shutdown
2020-11-19 17:59:36 +13:00
Naz
85b51524c9 Added loggign and more graceful error handling
no issue

- This is a quick implementation change to prevent from queue stalling and never becoming idle in case there's an error thrown from within the job function/module
- More robust error handling should be designed soon!
2020-11-10 17:11:24 +13:00
Naz
c85ec6aaa5 Added support for job execution from module path
no issue

- Jobs should not always be functions, one of the standard practices is having a job defined in a module as a self contained executable function
- First parameter of `addJob` function now also handles path to modules which it imports and executes
2020-11-10 16:32:47 +13:00
Naz
70b42e3a75 Switched cron validation library to cron-validate
no issue

- Previous library was relyting on try/catch block to check if the expression is valid. Flow control through error catching is not considered a good practice and can effect performance (https://riptutorial.com/javascript/example/5297/avoid-try-catch-in-performance-critical-functions)
2020-11-10 13:33:01 +13:00
Naz
ae4f35ddd8 Changed scheduleJob method signature to take when parameter first
no issue

- Accepting the schedule or a data when scheduled job should be run would follow a signature used in other established frameworks: (1) https://github.com/mperham/sidekiq/wiki/Ent-Periodic-Jobs#definition
- Another reason to put scheduling parameter first is this would allow leaving an optional "data" parameter as last
2020-11-10 13:15:10 +13:00
Naz
d1bbd79ece Updated JSDoc 2020-11-05 17:36:51 +13:00
Naz
1b1794063f Added experimental job scheduling feature
no issue

- This method should be used with caution and should serve as a playground for upcoming new feature of scheduled jobs support
2020-11-05 17:36:29 +13:00
Naz
3da365999d Added cron expression validation
no issue

- CRON format is the most common one used for job scheduling and is well known to most developers
- This will become one of supported formats for job scheduling
2020-11-05 17:07:27 +13:00
Naz
5506c64ae4 Added logging 2020-11-05 16:42:23 +13:00
Naz
48597b0056 Added JSDoc description 2020-11-05 16:41:16 +13:00
Hannah Wolfe
2c1417da88 Added new job manager package
- Minimal working version of a job manager
- Uses fastq for handling the queue
- Exposes 2 methods: addJob and shutdown
2020-08-11 21:17:52 +01:00