@h3ravel/queue 11.15.0-alpha.16 → 11.17.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/index.d.ts +1 -1
- package/package.json +4 -6
- package/dist/index.cjs +0 -355
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference path="./app.globals.d.ts" />
|
|
2
|
+
import { RuntimeException } from "@h3ravel/support";
|
|
2
3
|
import { ClassConstructor, JobPayload } from "@h3ravel/contracts";
|
|
3
4
|
import { Container, ServiceProvider } from "@h3ravel/core";
|
|
4
|
-
import { RuntimeException } from "@h3ravel/support";
|
|
5
5
|
|
|
6
6
|
//#region src/Contracts/JobContract.d.ts
|
|
7
7
|
type JobClassConstructor = (new (...args: any) => any);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@h3ravel/queue",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.17.0",
|
|
4
4
|
"description": "Job queues, workers and broadcasting support system for H3ravel.",
|
|
5
5
|
"h3ravel": {
|
|
6
6
|
"providers": [
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
]
|
|
9
9
|
},
|
|
10
10
|
"type": "module",
|
|
11
|
-
"main": "./dist/index.cjs",
|
|
12
11
|
"types": "./dist/index.d.ts",
|
|
13
|
-
"module": "./dist/index.js",
|
|
14
12
|
"exports": {
|
|
15
13
|
".": {
|
|
16
14
|
"import": "./dist/index.js",
|
|
@@ -41,15 +39,15 @@
|
|
|
41
39
|
"laravel"
|
|
42
40
|
],
|
|
43
41
|
"peerDependencies": {
|
|
44
|
-
"@h3ravel/core": "^
|
|
45
|
-
"@h3ravel/contracts": "^
|
|
42
|
+
"@h3ravel/core": "^2.0.0",
|
|
43
|
+
"@h3ravel/contracts": "^2.0.0"
|
|
46
44
|
},
|
|
47
45
|
"devDependencies": {
|
|
48
46
|
"typescript": "^6.0.0"
|
|
49
47
|
},
|
|
50
48
|
"scripts": {
|
|
51
49
|
"build": "tsdown --config-loader unrun",
|
|
52
|
-
"dev": "
|
|
50
|
+
"dev": "tsdown --watch --config-loader unrun",
|
|
53
51
|
"start": "node dist/index.js",
|
|
54
52
|
"lint": "eslint . --ext .ts",
|
|
55
53
|
"test": "jest --passWithNoTests",
|
package/dist/index.cjs
DELETED
|
@@ -1,355 +0,0 @@
|
|
|
1
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
let _h3ravel_support = require("@h3ravel/support");
|
|
3
|
-
let _h3ravel_contracts = require("@h3ravel/contracts");
|
|
4
|
-
let _h3ravel_core = require("@h3ravel/core");
|
|
5
|
-
//#region src/Events/JobFailed.ts
|
|
6
|
-
var JobFailed = class {
|
|
7
|
-
connectionName;
|
|
8
|
-
job;
|
|
9
|
-
exception;
|
|
10
|
-
/**
|
|
11
|
-
* Create a new event instance.
|
|
12
|
-
*
|
|
13
|
-
* @param connectionName The connection name.
|
|
14
|
-
* @param job The job instance.
|
|
15
|
-
* @param exception The exception that caused the job to fail.
|
|
16
|
-
*/
|
|
17
|
-
constructor(connectionName, job, exception) {
|
|
18
|
-
this.connectionName = connectionName;
|
|
19
|
-
this.job = job;
|
|
20
|
-
this.exception = exception;
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
//#endregion
|
|
24
|
-
//#region src/Exceptions/ManuallyFailedException.ts
|
|
25
|
-
var ManuallyFailedException = class extends _h3ravel_support.RuntimeException {};
|
|
26
|
-
//#endregion
|
|
27
|
-
//#region src/Exceptions/MaxAttemptsExceededException.ts
|
|
28
|
-
var MaxAttemptsExceededException = class MaxAttemptsExceededException extends _h3ravel_support.RuntimeException {
|
|
29
|
-
/**
|
|
30
|
-
* The job instance.
|
|
31
|
-
*/
|
|
32
|
-
job;
|
|
33
|
-
/**
|
|
34
|
-
* Create a new instance for the job.
|
|
35
|
-
*
|
|
36
|
-
* @param job
|
|
37
|
-
*/
|
|
38
|
-
static forJob(job) {
|
|
39
|
-
return (0, _h3ravel_support.tap)(new MaxAttemptsExceededException(job.resolveName() + " has been attempted too many times."), (e) => {
|
|
40
|
-
e.job = job;
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
//#endregion
|
|
45
|
-
//#region src/Exceptions/TimeoutExceededException.ts
|
|
46
|
-
var TimeoutExceededException = class TimeoutExceededException extends MaxAttemptsExceededException {
|
|
47
|
-
/**
|
|
48
|
-
* Create a new instance for the job.
|
|
49
|
-
*
|
|
50
|
-
* @param job
|
|
51
|
-
*/
|
|
52
|
-
static forJob(job) {
|
|
53
|
-
return (0, _h3ravel_support.tap)(new TimeoutExceededException(job.resolveName() + " has timed out."), (e) => {
|
|
54
|
-
e.job = job;
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
//#endregion
|
|
59
|
-
//#region src/Jobs/JobName.ts
|
|
60
|
-
var JobName = class {
|
|
61
|
-
/**
|
|
62
|
-
* Parse the given job name into a class / method array.
|
|
63
|
-
*
|
|
64
|
-
* @param job
|
|
65
|
-
*/
|
|
66
|
-
static parse(_job) {
|
|
67
|
-
return [{}, ""];
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Get the resolved name of the queued job class.
|
|
71
|
-
*
|
|
72
|
-
* @param name
|
|
73
|
-
* @param payload
|
|
74
|
-
*/
|
|
75
|
-
static resolve(name, payload) {
|
|
76
|
-
if (!payload.displayName) return payload.displayName;
|
|
77
|
-
return name;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Get the class name for queued job class.
|
|
81
|
-
*
|
|
82
|
-
* @param name
|
|
83
|
-
* @param payload
|
|
84
|
-
*/
|
|
85
|
-
static resolveClassName(name, payload) {
|
|
86
|
-
if (typeof payload.data.commandName === "string") return payload.data.commandName;
|
|
87
|
-
return name;
|
|
88
|
-
}
|
|
89
|
-
};
|
|
90
|
-
//#endregion
|
|
91
|
-
//#region src/Jobs/Job.ts
|
|
92
|
-
var Job = class {
|
|
93
|
-
/**
|
|
94
|
-
* The job handler instance.
|
|
95
|
-
*/
|
|
96
|
-
instance;
|
|
97
|
-
/**
|
|
98
|
-
* The IoC container instance.
|
|
99
|
-
*/
|
|
100
|
-
container;
|
|
101
|
-
/**
|
|
102
|
-
* Indicates if the job has been deleted.
|
|
103
|
-
*/
|
|
104
|
-
deleted = false;
|
|
105
|
-
/**
|
|
106
|
-
* Indicates if the job has been released.
|
|
107
|
-
*/
|
|
108
|
-
released = false;
|
|
109
|
-
/**
|
|
110
|
-
* Indicates if the job has failed.
|
|
111
|
-
*/
|
|
112
|
-
failed = false;
|
|
113
|
-
/**
|
|
114
|
-
* The name of the connection the job belongs to.
|
|
115
|
-
*/
|
|
116
|
-
connectionName;
|
|
117
|
-
/**
|
|
118
|
-
* The name of the queue the job belongs to.
|
|
119
|
-
*/
|
|
120
|
-
queue;
|
|
121
|
-
/**
|
|
122
|
-
* Get the UUID of the job.
|
|
123
|
-
*
|
|
124
|
-
* @return string|null
|
|
125
|
-
*/
|
|
126
|
-
uuid() {
|
|
127
|
-
return this.payload()["uuid"] ?? null;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Fire the job.
|
|
131
|
-
*
|
|
132
|
-
* @return void
|
|
133
|
-
*/
|
|
134
|
-
fire() {
|
|
135
|
-
const payload = this.payload();
|
|
136
|
-
const [instance, method] = JobName.parse(payload["job"]);
|
|
137
|
-
(this.instance = this.resolve(instance))[method](this, payload["data"]);
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Delete the job from the queue.
|
|
141
|
-
*/
|
|
142
|
-
delete() {
|
|
143
|
-
this.deleted = true;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* Determine if the job has been deleted.
|
|
147
|
-
*/
|
|
148
|
-
isDeleted() {
|
|
149
|
-
return this.deleted;
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Release the job back into the queue after (n) seconds.
|
|
153
|
-
*
|
|
154
|
-
* @param delay
|
|
155
|
-
*/
|
|
156
|
-
release(_delay = 0) {
|
|
157
|
-
this.released = true;
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Determine if the job was released back into the queue.
|
|
161
|
-
*
|
|
162
|
-
* @return bool
|
|
163
|
-
*/
|
|
164
|
-
isReleased() {
|
|
165
|
-
return this.released;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Determine if the job has been deleted or released.
|
|
169
|
-
*/
|
|
170
|
-
isDeletedOrReleased() {
|
|
171
|
-
return this.isDeleted() || this.isReleased();
|
|
172
|
-
}
|
|
173
|
-
/**
|
|
174
|
-
* Determine if the job has been marked as a failure.
|
|
175
|
-
*/
|
|
176
|
-
hasFailed() {
|
|
177
|
-
return this.failed;
|
|
178
|
-
}
|
|
179
|
-
/**
|
|
180
|
-
* Mark the job as "failed".
|
|
181
|
-
*/
|
|
182
|
-
markAsFailed() {
|
|
183
|
-
this.failed = true;
|
|
184
|
-
}
|
|
185
|
-
/**
|
|
186
|
-
* Delete the job, call the "failed" method, and raise the failed job event.
|
|
187
|
-
*
|
|
188
|
-
* @param e
|
|
189
|
-
*/
|
|
190
|
-
fail(e) {
|
|
191
|
-
this.markAsFailed();
|
|
192
|
-
if (this.isDeleted()) return;
|
|
193
|
-
if (this.shouldRollBackDatabaseTransaction(e)) this.container.make("db").connection(this.container.make("config").get("queue.failed.database")).rollBack(0);
|
|
194
|
-
try {
|
|
195
|
-
this.delete();
|
|
196
|
-
this.failedJob(e);
|
|
197
|
-
} finally {
|
|
198
|
-
this.resolve(_h3ravel_contracts.IDispatcher).dispatch(new JobFailed(this.connectionName, this, e || new ManuallyFailedException()));
|
|
199
|
-
}
|
|
200
|
-
}
|
|
201
|
-
/**
|
|
202
|
-
* Determine if the current database transaction should be rolled back to level zero.
|
|
203
|
-
*
|
|
204
|
-
* @param e
|
|
205
|
-
*/
|
|
206
|
-
shouldRollBackDatabaseTransaction(e) {
|
|
207
|
-
return e instanceof TimeoutExceededException && this.container.make("config").get("queue.failed.database") && ["database", "database-uuids"].includes(this.container.make("config").get("queue.failed.driver")) && this.container.has("db");
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Process an exception that caused the job to fail.
|
|
211
|
-
*
|
|
212
|
-
* @param e
|
|
213
|
-
*/
|
|
214
|
-
failedJob(e, ..._args) {
|
|
215
|
-
const payload = this.payload();
|
|
216
|
-
const [classInstance] = JobName.parse(payload.job);
|
|
217
|
-
this.instance = this.resolve(classInstance);
|
|
218
|
-
if (typeof this.instance.failed === "function") this.instance.failedJob(payload.data, e, payload.uuid ?? "", this);
|
|
219
|
-
}
|
|
220
|
-
/**
|
|
221
|
-
* Resolve the given class.
|
|
222
|
-
*/
|
|
223
|
-
resolve(className) {
|
|
224
|
-
return this.container.make(className);
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* Get the resolved job handler instance.
|
|
228
|
-
*
|
|
229
|
-
* @return mixed
|
|
230
|
-
*/
|
|
231
|
-
getResolvedJob() {
|
|
232
|
-
return this.instance;
|
|
233
|
-
}
|
|
234
|
-
/**
|
|
235
|
-
* Get the decoded body of the job.
|
|
236
|
-
*/
|
|
237
|
-
payload() {
|
|
238
|
-
return JSON.parse(this.getRawBody());
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* Get the number of times to attempt a job.
|
|
242
|
-
*
|
|
243
|
-
* @return int|null
|
|
244
|
-
*/
|
|
245
|
-
maxTries() {
|
|
246
|
-
return this.payload()["maxTries"] ?? null;
|
|
247
|
-
}
|
|
248
|
-
/**
|
|
249
|
-
* Get the number of times to attempt a job after an exception.
|
|
250
|
-
*
|
|
251
|
-
* @return int|null
|
|
252
|
-
*/
|
|
253
|
-
maxExceptions() {
|
|
254
|
-
return this.payload()["maxExceptions"] ?? null;
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Determine if the job should fail when it timeouts.
|
|
258
|
-
*
|
|
259
|
-
* @return bool
|
|
260
|
-
*/
|
|
261
|
-
shouldFailOnTimeout() {
|
|
262
|
-
return this.payload()["failOnTimeout"] ?? false;
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* The number of seconds to wait before retrying a job that encountered an uncaught exception.
|
|
266
|
-
*
|
|
267
|
-
* @return int|int[]|null
|
|
268
|
-
*/
|
|
269
|
-
backoff() {
|
|
270
|
-
return this.payload()["backoff"] ?? this.payload()["delay"] ?? null;
|
|
271
|
-
}
|
|
272
|
-
/**
|
|
273
|
-
* Get the number of seconds the job can run.
|
|
274
|
-
*
|
|
275
|
-
* @return int|null
|
|
276
|
-
*/
|
|
277
|
-
timeout() {
|
|
278
|
-
return this.payload()["timeout"] ?? null;
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* Get the timestamp indicating when the job should timeout.
|
|
282
|
-
*
|
|
283
|
-
* @return int|null
|
|
284
|
-
*/
|
|
285
|
-
retryUntil() {
|
|
286
|
-
return this.payload()["retryUntil"] ?? null;
|
|
287
|
-
}
|
|
288
|
-
/**
|
|
289
|
-
* Get the name of the queued job class.
|
|
290
|
-
*
|
|
291
|
-
* @return string
|
|
292
|
-
*/
|
|
293
|
-
getName() {
|
|
294
|
-
return this.payload()["job"];
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* Get the resolved display name of the queued job class.
|
|
298
|
-
*
|
|
299
|
-
* Resolves the name of "wrapped" jobs such as class-based handlers.
|
|
300
|
-
*/
|
|
301
|
-
resolveName() {
|
|
302
|
-
return JobName.resolve(this.getName(), this.payload());
|
|
303
|
-
}
|
|
304
|
-
/**
|
|
305
|
-
* Get the class of the queued job.
|
|
306
|
-
*
|
|
307
|
-
* Resolves the class of "wrapped" jobs such as class-based handlers.
|
|
308
|
-
*
|
|
309
|
-
* @return string
|
|
310
|
-
*/
|
|
311
|
-
resolveQueuedJobClass() {
|
|
312
|
-
return JobName.resolveClassName(this.getName(), this.payload());
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Get the name of the connection the job belongs to.
|
|
316
|
-
*/
|
|
317
|
-
getConnectionName() {
|
|
318
|
-
return this.connectionName;
|
|
319
|
-
}
|
|
320
|
-
/**
|
|
321
|
-
* Get the name of the queue the job belongs to.
|
|
322
|
-
*/
|
|
323
|
-
getQueue() {
|
|
324
|
-
return this.queue;
|
|
325
|
-
}
|
|
326
|
-
/**
|
|
327
|
-
* Get the service container instance.
|
|
328
|
-
*/
|
|
329
|
-
getContainer() {
|
|
330
|
-
return this.container;
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
//#endregion
|
|
334
|
-
//#region src/Providers/QueueServiceProvider.ts
|
|
335
|
-
/**
|
|
336
|
-
* Queues and workers.
|
|
337
|
-
*
|
|
338
|
-
* Register QueueManager.
|
|
339
|
-
* Load drivers (Redis, in-memory).
|
|
340
|
-
* Register job dispatcher and workers.
|
|
341
|
-
*
|
|
342
|
-
* Auto-Registered if @h3ravel/queue is installed
|
|
343
|
-
*/
|
|
344
|
-
var QueueServiceProvider = class extends _h3ravel_core.ServiceProvider {
|
|
345
|
-
static priority = 991;
|
|
346
|
-
register() {}
|
|
347
|
-
};
|
|
348
|
-
//#endregion
|
|
349
|
-
exports.Job = Job;
|
|
350
|
-
exports.JobFailed = JobFailed;
|
|
351
|
-
exports.JobName = JobName;
|
|
352
|
-
exports.ManuallyFailedException = ManuallyFailedException;
|
|
353
|
-
exports.MaxAttemptsExceededException = MaxAttemptsExceededException;
|
|
354
|
-
exports.QueueServiceProvider = QueueServiceProvider;
|
|
355
|
-
exports.TimeoutExceededException = TimeoutExceededException;
|