Commit Graph

339 Commits

Author SHA1 Message Date
Naz
c13d8a2fa6 Added errorHandler option to customize job error logic
closes https://github.com/TryGhost/Ghost-Utils/issues/118

- Custom error handling is needed to be able to override default bree
error handling logic.
- bree bump to 4.1.0 also fixed logging errors (object Object fix in
tests)
- The handler function receives two parameters. First contains an error
that has been thrown by the job. Second, job and worker metadata
2020-12-14 16:09:36 +13:00
Renovate Bot
0aff1a305e Update dependency typescript to v4.1.3 2020-12-11 22:10:12 +00:00
Renovate Bot
c3e3935c6d Update dependency sinon to v9.2.2 2020-12-11 12:43:04 +00:00
Naz
516311aa43 Published new versions
- @tryghost/adapter-manager@0.2.4
 - @tryghost/job-manager@0.5.0
 - @tryghost/mw-session-from-token@0.1.12
 - @tryghost/session-service@0.1.13
2020-12-09 20:29:53 +13:00
Naz
13e8336de9 Updated docs around inline/offloaded jobs
no issue

- Provided more context about which type of job does what and introduced naming to be able to distinguish them
- The naming is still to be reviewed by peers
2020-12-09 20:04:09 +13:00
Naz
2462e9642e Added documentation for immediate jobs 2020-12-09 20:02:36 +13:00
Naz
7457393b5b Added jsdoc to bree job builder 2020-12-09 19:34:04 +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
Renovate Bot
9a6ed2f180 Update dependency @types/mocha to v8.2.0 2020-12-08 15:22:46 +00:00
Naz
12eb035bdc Published new versions
- @tryghost/job-manager@0.4.0
2020-12-08 16:44:24 +13:00
Naz
320e7feb0e Added ability to remove scheduled jobs
closes #119

- A future use-case which this feature caters for is allowing to migrate "post scheduler" to use job manager instead of managing scheduling itself
- removeJob method will be needed to allow "rescheduling" of the post
2020-12-08 16:43:18 +13:00
Naz
86b9f0d2ce Renamed when parameter
no issue

- Semantically "at" fits better as it matches the name of similarly purposed UNIX utility
2020-12-03 16:22:56 +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
ed29a29704 Published new versions
- @tryghost/job-manager@0.3.4
2020-12-02 00:22:20 +13:00
Naz
35f8933070 Fixed cron definition not accepting seconds parameter 2020-12-02 00:19:01 +13:00
Naz
404209ba30 Published new versions
- @tryghost/job-manager@0.3.3
2020-11-30 15:36:54 +13:00
Naz
715789406d Improved job registration logging 2020-11-30 15:35:57 +13:00
Naz
3892e57194 Added docs on how each method executes the job 2020-11-30 15:30:45 +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
6389df346c Published new versions
- @tryghost/adapter-manager@0.2.3
 - @tryghost/job-manager@0.3.2
2020-11-26 11:08:10 +13:00
Naz
73b60854cd Added documentation about bthread polyfill
refs https://github.com/TryGhost/Ghost/issues/12402
2020-11-25 15:21:02 +13:00
Naz
a2fdc69a23 Added docs about job lifecycle
refs https://github.com/orgs/TryGhost/projects/36#card-49938015
2020-11-25 15:03:54 +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
c3ab2be076 Added examples of job and job manager initialization 2020-11-25 13:44:04 +13:00
Renovate Bot
31149f3ade Update dependency @types/sinon to v9.0.9 2020-11-24 08:45:40 +00:00
Naz
bc93a166e9 Updated readme with instructions about jobs
refs https://github.com/TryGhost/Ghost/issues/12402

- Describes different types of jobs that could be executed depending on the nature of the jobs.
- Lays down ground rules on how to design scheduled jobs
2020-11-24 20:15:02 +13:00
Naz
1340306f4c Updated job manager module description documentation 2020-11-24 19:55:51 +13:00
Naz
58bc922c0e Fixed tests for cron expression validation
refs c0cecd71fe
2020-11-24 16:44:54 +13:00
Naz
67e664208a Added documentation about job scheduling
refs https://github.com/TryGhost/Ghost/issues/12402

- Adds examples on how to queue regular "immediate" and reccuring "scheduled" jobs
2020-11-24 16:40:35 +13:00
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
a8cb12250b Published new versions
- @tryghost/adapter-manager@0.2.2
 - @tryghost/job-manager@0.3.1
 - @tryghost/moleculer-service-from-class@0.2.8
 - @tryghost/mw-session-from-token@0.1.11
 - @tryghost/session-service@0.1.12
2020-11-23 16:14:42 +13:00
Naz
a7570680fb Updated type definitions files that changed with bump of typescript version
refs 295887dd24
2020-11-23 16:13:51 +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
Renovate Bot
e27b788d48 Update dependency cron-validate to v1.4.1 2020-11-23 02:06:12 +00: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
Renovate Bot
295887dd24 Update dependency typescript to v4.1.2 2020-11-19 22:44:50 +00:00
Naz
06bc47678b Published new versions
- @tryghost/adapter-manager@0.2.1
 - @tryghost/job-manager@0.3.0
 - @tryghost/mw-session-from-token@0.1.10
 - @tryghost/security@0.2.2
 - @tryghost/session-service@0.1.11
 - @tryghost/zip@1.1.6
2020-11-19 18:17:14 +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
e6e7dc93dd Added test coverage for graceful job queue shutdown 2020-11-17 18:14:37 +13:00
Renovate Bot
788014c8e0 Update dependency @types/mocha to v8.0.4 2020-11-11 01:41:25 +00:00
Renovate Bot
25bc90e615 Update dependency @tryghost/string to v0.1.14 2020-11-10 10:50:57 +00:00
Daniel Lockyer
8d9e26cb83 Switched symlink to symlinkSync
- we don't provide a callback for this so we want it synchronous
  but `symlink` is async. Switching to `symlinkSync` should now fix the
  flaky tests
2020-11-10 10:48:25 +00:00
Naz
9cbbef0398 Published new versions
- @tryghost/job-manager@0.2.0
2020-11-10 17:16:09 +13:00
Naz
7925f12fcc Fixed lint for arrow function use in beforeEach block 2020-11-10 17:15:08 +13:00
Naz
d8f7db8773 Cleaned up test 2020-11-10 17:11:31 +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
7dac72d6bf Added test coverage for basic job registration 2020-11-10 16:35:04 +13:00