Commit Graph

14 Commits

Author SHA1 Message Date
Daniel Lockyer
c2e45b657f Removed bthreads dependency in favor of native worker_threads
fixes https://github.com/TryGhost/Toolbox/issues/370

- we no longer need `bthreads` because we can use native
  `worker_threads` now we don't have to support Node 10 any longer
- this allows us to clean up a dependency and stick with native
  libraries
- the referenced node-sqlite3 issue should be fixed (or at least, we now
  maintain it so we can fix it if not)
2022-08-09 09:04:59 +02:00
Naz
b0581c778e Added execution progress updates for one off jobs
refs https://github.com/TryGhost/Toolbox/issues/357

- Job persisted in the database need to track job's execution status such as completion, failure, execution start and end times. This changeset allows to hook into job/bree lifecycle to track job's progress.
- NOTE: only supports "offloaded" jobs at the moment. Support for "inline" jobs will be added once there's a clear usecase for it.
- The "started" status and "started_at" timestamp are assigned to a job at the moment when the worker thread is created inside of bree
- The "finished" status and "finished_at" timestamp are assigned to a job when a "done" event is passed from the job script (NOTE: using process.exit(0) will not trigger the "finished" state")
- The "failed" status is assigned when the job execution is interrupted with an error
2022-07-22 16:43:15 +01:00
Naz
6b2494a5bc Bumped bree to 6.2.0
refs 55060e323c

- This bump was meant to be done when the referenced changes landed. Without it parts of worker thread messages are lost
2021-03-03 12:26:37 +13:00
Naz
0e2c5cdb45 Fixed typo 2021-02-22 19:10:55 +13:00
Naz
55060e323c Added workerMessageHandler option to ctr options
refs https://github.com/TryGhost/Ghost/issues/12496

- `workerMessageHandler` option allows for custom worker message handling and allows to eliminate a need for loggers of any type inside of jobs.
- removing loggers from jobs solves file hanle leak which used to cause Ghost process to crash (see referenced issue)
2021-02-22 19:10:47 +13:00
Naz
0e1c2ececb Fixed a typo 2021-02-22 18:54:23 +13:00
Naz
7ece94f411 Added support for immediate offloaded jobs
closes #117

- Having immediately executable offloaded jobs is necessary to be able to run usecases like: send batched emails now, or any other job that does not need to be scheduled
- Changed "simple" job timeout to make tests run faster
2020-12-09 19:11:17 +13:00
Naz
30c9112bb5 Updated example of scheduled on off job using date 2020-12-03 15:53:10 +13:00
Naz
eb0eb2d744 Added support for one off scheduled jobs
closes #115

- When scheduling one off job for future execution you can now pass in Date as a first parameter to `scheduleJob` method
2020-12-02 21:26:15 +13:00
Naz
238ff4abdb Clarified usecases of 'done' and 'cancelled' job events
no issue

- Added docs around which events are suited best for job termination/completeion
2020-11-30 13:48:07 +13:00
Naz
d1df62f84c Added description about graceful job termination 2020-11-25 13:56:01 +13:00
Naz
d94830071d Added description for job termination best practice 2020-11-25 13:55:34 +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
e6e7dc93dd Added test coverage for graceful job queue shutdown 2020-11-17 18:14:37 +13:00