@rvoh/psychic-workers 2.6.0 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/background/BaseBackgroundedModel.js +49 -25
- package/dist/cjs/src/background/BaseBackgroundedService.js +24 -12
- package/dist/cjs/src/background/BaseScheduledService.js +1 -1
- package/dist/cjs/src/background/index.js +383 -98
- package/dist/cjs/src/error/background/DebouncedJobOutpacesRateLimit.js +64 -0
- package/dist/cjs/src/error/background/DebouncedJobRequiresMinimumDelay.js +52 -0
- package/dist/cjs/src/error/background/NamedWorkstreamRateLimitMissingMaxOrDuration.js +31 -0
- package/dist/cjs/src/error/background/RateLimitedPsychicJob.js +82 -0
- package/dist/cjs/src/error/background/RateLimitedPsychicJobThrownFromWorkerWithoutLimiter.js +51 -0
- package/dist/cjs/src/package-exports/errors.js +7 -0
- package/dist/cjs/src/test-utils/WorkerTestUtils.js +78 -13
- package/dist/esm/src/background/BaseBackgroundedModel.js +49 -25
- package/dist/esm/src/background/BaseBackgroundedService.js +24 -12
- package/dist/esm/src/background/BaseScheduledService.js +1 -1
- package/dist/esm/src/background/index.js +383 -98
- package/dist/esm/src/error/background/DebouncedJobOutpacesRateLimit.js +64 -0
- package/dist/esm/src/error/background/DebouncedJobRequiresMinimumDelay.js +52 -0
- package/dist/esm/src/error/background/NamedWorkstreamRateLimitMissingMaxOrDuration.js +31 -0
- package/dist/esm/src/error/background/RateLimitedPsychicJob.js +82 -0
- package/dist/esm/src/error/background/RateLimitedPsychicJobThrownFromWorkerWithoutLimiter.js +51 -0
- package/dist/esm/src/package-exports/errors.js +7 -0
- package/dist/esm/src/test-utils/WorkerTestUtils.js +78 -13
- package/dist/types/src/background/BaseBackgroundedModel.d.ts +49 -25
- package/dist/types/src/background/BaseBackgroundedService.d.ts +24 -12
- package/dist/types/src/background/BaseScheduledService.d.ts +1 -1
- package/dist/types/src/background/index.d.ts +109 -5
- package/dist/types/src/error/background/DebouncedJobOutpacesRateLimit.d.ts +31 -0
- package/dist/types/src/error/background/DebouncedJobRequiresMinimumDelay.d.ts +23 -0
- package/dist/types/src/error/background/NamedWorkstreamRateLimitMissingMaxOrDuration.d.ts +16 -0
- package/dist/types/src/error/background/RateLimitedPsychicJob.d.ts +73 -0
- package/dist/types/src/error/background/RateLimitedPsychicJobThrownFromWorkerWithoutLimiter.d.ts +16 -0
- package/dist/types/src/package-exports/errors.d.ts +1 -0
- package/dist/types/src/psychic-app-workers/index.d.ts +102 -53
- package/dist/types/src/test-utils/WorkerTestUtils.d.ts +32 -1
- package/dist/types/src/types/background.d.ts +88 -6
- package/package.json +1 -1
|
@@ -11,7 +11,7 @@ export default class BaseBackgroundedService {
|
|
|
11
11
|
* @returns {object} config - the background job config
|
|
12
12
|
* @returns {string} config.priority - 'default' | 'urgent' | 'not_urgent' | 'last'
|
|
13
13
|
* @returns {string} config.workstream - a workstream name. This would be the name of a workstream, as defined in conf/workers.ts
|
|
14
|
-
* @returns {string} config.
|
|
14
|
+
* @returns {string} config.queue - the name of the BullMQ queue you wish to connect to. This can only be provided if workstream is not provided.
|
|
15
15
|
* @returns {string} config.groupId - the groupId of the BullMQ queue you wish to connect to. This can only be provided if workstream is not provided.
|
|
16
16
|
*/
|
|
17
17
|
static get backgroundJobConfig() {
|
|
@@ -68,16 +68,22 @@ export default class BaseBackgroundedService {
|
|
|
68
68
|
}
|
|
69
69
|
/**
|
|
70
70
|
* runs the specified method in a background queue, driven by BullMQ,
|
|
71
|
-
* sending in the provided args,
|
|
72
|
-
*
|
|
73
|
-
* it is entered into the queue.
|
|
71
|
+
* sending in the provided args, along with a delay object — one or more of
|
|
72
|
+
* `{ seconds, minutes, hours, days }` — which holds the job off for that much
|
|
73
|
+
* time after it is entered into the queue.
|
|
74
|
+
*
|
|
75
|
+
* The delay object also accepts an optional `jobId`, which turns the delay
|
|
76
|
+
* into a **debounce**: repeated calls carrying the same `jobId` collapse into
|
|
77
|
+
* a single execution, which runs once the delay has elapsed without another
|
|
78
|
+
* call arriving. `jobId` is a deduplication key rather than a BullMQ job id.
|
|
79
|
+
*
|
|
80
|
+
* See {@link DelayedJobOpts.jobId}.
|
|
74
81
|
*
|
|
75
82
|
* ```ts
|
|
76
|
-
* await MyBackgroundableClass.backgroundWithDelay('myMethod', 'abc', 123)
|
|
83
|
+
* await MyBackgroundableClass.backgroundWithDelay({ minutes: 5 }, 'myMethod', 'abc', 123)
|
|
77
84
|
* ```
|
|
78
|
-
* though calling
|
|
79
|
-
* is an indication that
|
|
80
|
-
* completed.
|
|
85
|
+
* though calling backgroundWithDelay must be awaited, the resolution of the promise
|
|
86
|
+
* is an indication that a run is pending, not that it has completed.
|
|
81
87
|
*
|
|
82
88
|
* NOTE: in test environments, psychic will immediately invoke the underlying
|
|
83
89
|
* method, preventing you from needing to explicitly wait for queues to flush
|
|
@@ -85,7 +91,7 @@ export default class BaseBackgroundedService {
|
|
|
85
91
|
*
|
|
86
92
|
* @deprecated use `backgroundWith({ delay }, methodName, ...args)` instead. This method will be removed in a future major version.
|
|
87
93
|
*
|
|
88
|
-
* @param
|
|
94
|
+
* @param delay - how long you want to hold off before allowing the job to run, given as at least one of `seconds`, `minutes`, `hours` or `days`, plus an optional `jobId` (a deduplication key) which debounces repeated calls into a single run
|
|
89
95
|
* @param methodName - the name of the static method you wish to run in the background
|
|
90
96
|
* @param args - a variadic list of arguments to be sent to your method
|
|
91
97
|
*/
|
|
@@ -105,6 +111,13 @@ export default class BaseBackgroundedService {
|
|
|
105
111
|
* be used to delay the job and/or override the priority provided by
|
|
106
112
|
* the `backgroundJobConfig` getter on this service.
|
|
107
113
|
*
|
|
114
|
+
* Adding a `jobId` to the delay turns it into a **debounce**: repeated calls
|
|
115
|
+
* carrying the same `jobId` collapse into a single execution, which runs once
|
|
116
|
+
* the delay has elapsed without another call arriving. `jobId` is a
|
|
117
|
+
* deduplication key rather than a BullMQ job id.
|
|
118
|
+
*
|
|
119
|
+
* See {@link DelayedJobOpts.jobId}.
|
|
120
|
+
*
|
|
108
121
|
* ```ts
|
|
109
122
|
* await MyBackgroundableClass.backgroundWith(
|
|
110
123
|
* { delay: { seconds: 30, jobId: 'my-unique-job-id' }, priority: 'urgent' },
|
|
@@ -114,15 +127,14 @@ export default class BaseBackgroundedService {
|
|
|
114
127
|
* )
|
|
115
128
|
* ```
|
|
116
129
|
* though calling backgroundWith must be awaited, the resolution of the promise
|
|
117
|
-
* is an indication that
|
|
118
|
-
* completed.
|
|
130
|
+
* is an indication that a run is pending, not that it has completed.
|
|
119
131
|
*
|
|
120
132
|
* NOTE: in test environments, psychic will immediately invoke the underlying
|
|
121
133
|
* method, preventing you from needing to explicitly wait for queues to flush
|
|
122
134
|
* before making assertions.
|
|
123
135
|
*
|
|
124
136
|
* @param opts - options for backgrounding this job
|
|
125
|
-
* @param opts.delay - (optional)
|
|
137
|
+
* @param opts.delay - (optional) how long you want to hold off before allowing the job to run, given as at least one of `seconds`, `minutes`, `hours` or `days`, plus an optional `jobId` (a deduplication key) which debounces repeated calls into a single run
|
|
126
138
|
* @param opts.priority - (optional) a priority which, when provided, overrides the priority provided by `backgroundJobConfig`
|
|
127
139
|
* @param methodName - the name of the static method you wish to run in the background
|
|
128
140
|
* @param args - a variadic list of arguments to be sent to your method
|
|
@@ -10,7 +10,7 @@ export default class BaseScheduledService {
|
|
|
10
10
|
* @returns {object} config - the background job config
|
|
11
11
|
* @returns {string} config.priority - 'default' | 'urgent' | 'not_urgent' | 'last'
|
|
12
12
|
* @returns {string} config.workstream - a workstream name. This would be the name of a workstream, as defined in conf/workers.ts
|
|
13
|
-
* @returns {string} config.
|
|
13
|
+
* @returns {string} config.queue - the name of the BullMQ queue you wish to connect to. This can only be provided if workstream is not provided.
|
|
14
14
|
* @returns {string} config.groupId - the groupId of the BullMQ queue you wish to connect to. This can only be provided if workstream is not provided.
|
|
15
15
|
*/
|
|
16
16
|
static get backgroundJobConfig() {
|