@cedarjs/jobs 5.0.7-next.338 → 5.0.7-rc.3
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/adapters/BaseAdapter/BaseAdapter.d.ts +1 -24
- package/dist/adapters/BaseAdapter/BaseAdapter.d.ts.map +1 -1
- package/dist/adapters/BaseAdapter/BaseAdapter.js +28 -4
- package/dist/adapters/PrismaAdapter/PrismaAdapter.d.ts +7 -20
- package/dist/adapters/PrismaAdapter/PrismaAdapter.d.ts.map +1 -1
- package/dist/adapters/PrismaAdapter/PrismaAdapter.js +48 -80
- package/dist/adapters/PrismaAdapter/errors.js +28 -4
- package/dist/bins/cedar-jobs-worker.js +60 -25
- package/dist/bins/cedar-jobs.js +72 -35
- package/dist/bins/rw-jobs-worker.js +2 -1
- package/dist/consts.d.ts +0 -9
- package/dist/consts.d.ts.map +1 -1
- package/dist/consts.js +52 -6
- package/dist/core/Executor.d.ts +0 -7
- package/dist/core/Executor.d.ts.map +1 -1
- package/dist/core/Executor.js +52 -79
- package/dist/core/JobManager.d.ts +1 -3
- package/dist/core/JobManager.d.ts.map +1 -1
- package/dist/core/JobManager.js +33 -12
- package/dist/core/Scheduler.d.ts +1 -11
- package/dist/core/Scheduler.d.ts.map +1 -1
- package/dist/core/Scheduler.js +38 -40
- package/dist/core/Worker.d.ts.map +1 -1
- package/dist/core/Worker.js +40 -24
- package/dist/errors.d.ts +0 -14
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +41 -16
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +38 -13
- package/dist/loaders.d.ts +1 -6
- package/dist/loaders.d.ts.map +1 -1
- package/dist/loaders.js +55 -29
- package/dist/setupEnv.js +28 -4
- package/dist/types.d.ts +5 -10
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +16 -0
- package/dist/util.js +28 -4
- package/package.json +14 -12
- package/dist/core/executionContext.d.ts +0 -33
- package/dist/core/executionContext.d.ts.map +0 -1
- package/dist/core/executionContext.js +0 -9
|
@@ -29,17 +29,6 @@ export interface ErrorOptions<TJob extends BaseJob = BaseJob> {
|
|
|
29
29
|
export interface FailureOptions<TJob extends BaseJob = BaseJob> {
|
|
30
30
|
job: TJob;
|
|
31
31
|
deleteJob?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Present when the job is failed directly, without a preceding `error()`
|
|
34
|
-
* call for the same attempt (currently: when the job exceeded
|
|
35
|
-
* `maxRuntime`), so the adapter can record what went wrong in a single
|
|
36
|
-
* write
|
|
37
|
-
*/
|
|
38
|
-
error?: Error;
|
|
39
|
-
}
|
|
40
|
-
export interface CancelOptions {
|
|
41
|
-
/** The id of the job to cancel, as returned by `schedule()` */
|
|
42
|
-
jobId: string | number;
|
|
43
32
|
}
|
|
44
33
|
/**
|
|
45
34
|
* Base class for all job adapters. Provides a common interface for scheduling
|
|
@@ -69,24 +58,12 @@ export declare abstract class BaseAdapter<TOptions extends BaseAdapterOptions =
|
|
|
69
58
|
*/
|
|
70
59
|
abstract error(options: ErrorOptions): void | Promise<void>;
|
|
71
60
|
/**
|
|
72
|
-
* Called when a job
|
|
73
|
-
* maxAttempts times, or exceeded maxRuntime (in which case
|
|
74
|
-
* `options.error` contains the timeout error to record)
|
|
61
|
+
* Called when a job has errored more than maxAttempts and will not be retried
|
|
75
62
|
*/
|
|
76
63
|
abstract failure(options: FailureOptions): void | Promise<void>;
|
|
77
64
|
/**
|
|
78
65
|
* Clear all jobs from storage
|
|
79
66
|
*/
|
|
80
67
|
abstract clear(): void | Promise<void>;
|
|
81
|
-
/**
|
|
82
|
-
* Cancel a job so that it will not be run (if it's still queued) or not be
|
|
83
|
-
* retried or picked up by another worker (if it's currently running).
|
|
84
|
-
* Should return `true` if a job was cancelled and `false` if no cancellable
|
|
85
|
-
* job with the given id was found.
|
|
86
|
-
*
|
|
87
|
-
* This method is optional: adapters that don't implement it don't support
|
|
88
|
-
* cancellation and `later.cancel()` will throw a `CancelNotImplementedError`
|
|
89
|
-
*/
|
|
90
|
-
cancel?(options: CancelOptions): boolean | Promise<boolean>;
|
|
91
68
|
}
|
|
92
69
|
//# sourceMappingURL=BaseAdapter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/BaseAdapter/BaseAdapter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAA;AAG3E,MAAM,WAAW,eAAe;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,EAAE,OAAO,EAAE,CAAA;IACf,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,KAAK,EAAE,IAAI,CAAA;IACX,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,QAAQ;IACvB,WAAW,EAAE,MAAM,CAAA;IACnB,UAAU,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,MAAM,EAAE,CAAA;CACjB;AAED,MAAM,WAAW,kBAAkB;IACjC,MAAM,CAAC,EAAE,WAAW,CAAA;CACrB;AAED,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,OAAO,GAAG,OAAO;IAC5D,GAAG,EAAE,IAAI,CAAA;IACT,KAAK,EAAE,IAAI,GAAG,SAAS,CAAA;IACvB,SAAS,CAAC,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,YAAY,CAAC,IAAI,SAAS,OAAO,GAAG,OAAO;IAC1D,GAAG,EAAE,IAAI,CAAA;IACT,KAAK,EAAE,IAAI,CAAA;IACX,KAAK,EAAE,KAAK,CAAA;CACb;AAED,MAAM,WAAW,cAAc,CAAC,IAAI,SAAS,OAAO,GAAG,OAAO;IAC5D,GAAG,EAAE,IAAI,CAAA;IACT,SAAS,CAA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AAO,CAAC,IAAI,CAAC;IAEtC,OAAO,EAAE,QAAQ,CAAA;IACjB,MAAM,EAAE,WAAW,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAA;gBAE3B,OAAO,EAAE,QAAQ;IAU7B,QAAQ,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,eAAe;IAE5D;;OAEG;IACH,QAAQ,CAAC,IAAI,CAAC,IAAI,EAAE,QAAQ,GAAG,eAAe,GAAG,OAAO,CAAC,eAAe,CAAC;IAEzE;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE/D;;;;OAIG;IACH,QAAQ,CAAC,KAAK,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3D;;OAEG;IACH,QAAQ,CAAC,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAE/D;;OAEG;IACH,QAAQ,CAAC,KAAK,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;CACvC"}
|
|
@@ -1,12 +1,36 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var BaseAdapter_exports = {};
|
|
20
|
+
__export(BaseAdapter_exports, {
|
|
21
|
+
BaseAdapter: () => BaseAdapter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(BaseAdapter_exports);
|
|
24
|
+
var import_consts = require("../../consts.js");
|
|
2
25
|
class BaseAdapter {
|
|
3
26
|
options;
|
|
4
27
|
logger;
|
|
5
28
|
constructor(options) {
|
|
6
29
|
this.options = options;
|
|
7
|
-
this.logger = options?.logger ?? DEFAULT_LOGGER;
|
|
30
|
+
this.logger = options?.logger ?? import_consts.DEFAULT_LOGGER;
|
|
8
31
|
}
|
|
9
32
|
}
|
|
10
|
-
export
|
|
33
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
34
|
+
0 && (module.exports = {
|
|
11
35
|
BaseAdapter
|
|
12
|
-
};
|
|
36
|
+
});
|
|
@@ -1,16 +1,13 @@
|
|
|
1
1
|
import type { BaseJob } from '../../types.js';
|
|
2
|
-
import type { BaseAdapterOptions, SchedulePayload, FindArgs, SuccessOptions, ErrorOptions, FailureOptions
|
|
2
|
+
import type { BaseAdapterOptions, SchedulePayload, FindArgs, SuccessOptions, ErrorOptions, FailureOptions } from '../BaseAdapter/BaseAdapter.js';
|
|
3
3
|
import { BaseAdapter } from '../BaseAdapter/BaseAdapter.js';
|
|
4
4
|
export interface PrismaJob extends BaseJob {
|
|
5
5
|
id: number;
|
|
6
6
|
handler: string;
|
|
7
|
-
|
|
8
|
-
runAt: Date | null;
|
|
7
|
+
runAt: Date;
|
|
9
8
|
cron: string | null | undefined;
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
/** Null unless the job is currently locked by a worker */
|
|
13
|
-
lockedBy: string | null;
|
|
9
|
+
lockedAt: Date;
|
|
10
|
+
lockedBy: string;
|
|
14
11
|
lastError: string | null;
|
|
15
12
|
failedAt: Date | null;
|
|
16
13
|
createdAt: Date;
|
|
@@ -86,7 +83,7 @@ export interface PrismaAdapterOptions<TDb extends object = object> extends BaseA
|
|
|
86
83
|
* }
|
|
87
84
|
* ```
|
|
88
85
|
*/
|
|
89
|
-
export declare class PrismaAdapter<TDb extends object = object> extends BaseAdapter<PrismaAdapterOptions<TDb
|
|
86
|
+
export declare class PrismaAdapter<TDb extends object = object> extends BaseAdapter<PrismaAdapterOptions<TDb>> {
|
|
90
87
|
db: TDb;
|
|
91
88
|
model: DelegateKey<TDb> | string;
|
|
92
89
|
accessor: PrismaAdapterDelegate;
|
|
@@ -101,18 +98,8 @@ export declare class PrismaAdapter<TDb extends object = object> extends BaseAdap
|
|
|
101
98
|
find({ processName, maxRuntime, queues, }: FindArgs): Promise<PrismaJob | undefined>;
|
|
102
99
|
success({ job, runAt, deleteJob }: SuccessOptions<PrismaJob>): Promise<void>;
|
|
103
100
|
error({ job, runAt, error }: ErrorOptions<PrismaJob>): Promise<void>;
|
|
104
|
-
failure({ job, deleteJob
|
|
105
|
-
schedule({ name, path, args, runAt, cron, queue, priority, }: SchedulePayload): Promise<
|
|
106
|
-
/**
|
|
107
|
-
* Cancels a job by marking it as permanently failed so no worker will pick
|
|
108
|
-
* it up (or retry it, if it's currently being worked on).
|
|
109
|
-
*
|
|
110
|
-
* If the job is currently running, the in-progress attempt is not
|
|
111
|
-
* interrupted (the worker will stop it when `maxRuntime` is exceeded), but
|
|
112
|
-
* it will not be retried and will not be picked up by another worker once
|
|
113
|
-
* its lock goes stale.
|
|
114
|
-
*/
|
|
115
|
-
cancel({ jobId }: CancelOptions): Promise<boolean>;
|
|
101
|
+
failure({ job, deleteJob }: FailureOptions<PrismaJob>): Promise<void>;
|
|
102
|
+
schedule({ name, path, args, runAt, cron, queue, priority, }: SchedulePayload): Promise<void>;
|
|
116
103
|
clear(): Promise<void>;
|
|
117
104
|
}
|
|
118
105
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PrismaAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/PrismaAdapter/PrismaAdapter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"PrismaAdapter.d.ts","sourceRoot":"","sources":["../../../src/adapters/PrismaAdapter/PrismaAdapter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAA;AAC7C,OAAO,KAAK,EACV,kBAAkB,EAClB,eAAe,EACf,QAAQ,EACR,cAAc,EACd,YAAY,EACZ,cAAc,EACf,MAAM,+BAA+B,CAAA;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAA;AAI3D,MAAM,WAAW,SAAU,SAAQ,OAAO;IACxC,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,IAAI,CAAA;IACX,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,CAAA;IAC/B,QAAQ,EAAE,IAAI,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAA;IACxB,QAAQ,EAAE,IAAI,GAAG,IAAI,CAAA;IACrB,SAAS,EAAE,IAAI,CAAA;IACf,SAAS,EAAE,IAAI,CAAA;CAChB;AAED,UAAU,qBAAqB;IAC7B,SAAS,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC,CAAA;IACtD,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAA;IACrE,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,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A;CAClC;AAUD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,qBAAa,aAAa,CAAC,GAAG,SAAS,MAAM,GAAG,MAAM,CAAE,SAAQ,WAAW,CACzE,oBAAoB,CAAC,GAAG,CAAC,CAC1B;IACC,EAAE,EAAE,GAAG,CAAA;IACP,KAAK,EAAE,WAAW,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;IAChC,QAAQ,EAAE,qBAAqB,CAAA;IAC/B,QAAQ,EAAE,MAAM,CAAA;gBAEJ,OAAO,EAAE,oBAAoB,CAAC,GAAG,CAAC;IAqB9C;;;;;OAKG;IACY,IAAI,CAAC,EAClB,WAAW,EACX,UAAU,EACV,MAAM,GACP,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IA6F7B,OAAO,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC;IAoB5D,KAAK,CAAC,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,YAAY,CAAC,SAAS,CAAC;IAiBpD,OAAO,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,EAAE,cAAc,CAAC,SAAS,CAAC;IAYrD,QAAQ,CAAC,EACtB,IAAI,EACJ,IAAI,EACJ,IAAI,EACJ,KAAK,EACL,IAAI,EACJ,KAAK,EACL,QAAQ,GACT,EAAE,eAAe;IAYH,KAAK;CAGrB"}
|
|
@@ -1,11 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var PrismaAdapter_exports = {};
|
|
20
|
+
__export(PrismaAdapter_exports, {
|
|
21
|
+
PrismaAdapter: () => PrismaAdapter
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(PrismaAdapter_exports);
|
|
24
|
+
var import_change_case = require("change-case");
|
|
25
|
+
var import_consts = require("../../consts.js");
|
|
26
|
+
var import_BaseAdapter = require("../BaseAdapter/BaseAdapter.js");
|
|
27
|
+
var import_errors = require("./errors.js");
|
|
9
28
|
function isPrismaAdapterDelegate(value) {
|
|
10
29
|
const candidate = value;
|
|
11
30
|
return candidate !== null && typeof candidate === "object" && typeof candidate.findFirst === "function" && typeof candidate.updateMany === "function" && typeof candidate.delete === "function" && typeof candidate.update === "function" && typeof candidate.create === "function" && typeof candidate.deleteMany === "function";
|
|
@@ -13,7 +32,7 @@ function isPrismaAdapterDelegate(value) {
|
|
|
13
32
|
function getDelegate(db, model) {
|
|
14
33
|
const delegate = db[model];
|
|
15
34
|
if (!isPrismaAdapterDelegate(delegate)) {
|
|
16
|
-
throw new ModelNameError(model);
|
|
35
|
+
throw new import_errors.ModelNameError(model);
|
|
17
36
|
}
|
|
18
37
|
return delegate;
|
|
19
38
|
}
|
|
@@ -27,7 +46,7 @@ function getActiveProvider(db) {
|
|
|
27
46
|
}
|
|
28
47
|
return provider;
|
|
29
48
|
}
|
|
30
|
-
class PrismaAdapter extends BaseAdapter {
|
|
49
|
+
class PrismaAdapter extends import_BaseAdapter.BaseAdapter {
|
|
31
50
|
db;
|
|
32
51
|
model;
|
|
33
52
|
accessor;
|
|
@@ -35,8 +54,8 @@ class PrismaAdapter extends BaseAdapter {
|
|
|
35
54
|
constructor(options) {
|
|
36
55
|
super(options);
|
|
37
56
|
this.db = options.db;
|
|
38
|
-
this.model = options.model || DEFAULT_MODEL_NAME;
|
|
39
|
-
const camelName = camelCase(String(this.model));
|
|
57
|
+
this.model = options.model || import_consts.DEFAULT_MODEL_NAME;
|
|
58
|
+
const camelName = (0, import_change_case.camelCase)(String(this.model));
|
|
40
59
|
this.accessor = getDelegate(this.db, camelName);
|
|
41
60
|
this.provider = getActiveProvider(options.db);
|
|
42
61
|
}
|
|
@@ -52,7 +71,7 @@ class PrismaAdapter extends BaseAdapter {
|
|
|
52
71
|
queues
|
|
53
72
|
}) {
|
|
54
73
|
const maxRuntimeExpire = new Date(
|
|
55
|
-
(/* @__PURE__ */ new Date()).getTime()
|
|
74
|
+
(/* @__PURE__ */ new Date()).getTime() + (maxRuntime || import_consts.DEFAULT_MAX_RUNTIME * 1e3)
|
|
56
75
|
);
|
|
57
76
|
const where = {
|
|
58
77
|
AND: [
|
|
@@ -114,27 +133,13 @@ class PrismaAdapter extends BaseAdapter {
|
|
|
114
133
|
// Prisma queries are lazily evaluated and only sent to the db when they are
|
|
115
134
|
// awaited, so do the await here to ensure they actually run (if the user
|
|
116
135
|
// doesn't await the Promise then the queries will never be executed!)
|
|
117
|
-
//
|
|
118
|
-
// All of these updates/deletes are done with updateMany/deleteMany guarded
|
|
119
|
-
// on `failedAt: null` and on `attempts` still being this attempt's value,
|
|
120
|
-
// so the in-flight attempt's outcome can't overwrite or delete the row
|
|
121
|
-
// when:
|
|
122
|
-
// - the job was cancelled (or otherwise permanently failed) while this
|
|
123
|
-
// attempt was running (`failedAt` is no longer null), or
|
|
124
|
-
// - the job was reclaimed by another worker because this attempt stalled
|
|
125
|
-
// past `maxRuntime` plus the grace period (relocking increments
|
|
126
|
-
// `attempts`, so this attempt's remembered value no longer matches).
|
|
127
|
-
// `lockedBy` can't serve as that second fence because worker process names
|
|
128
|
-
// are deterministic and reused across restarts
|
|
129
136
|
async success({ job, runAt, deleteJob }) {
|
|
130
137
|
this.logger.debug(`[CedarJS Jobs] Job ${job.id} success`);
|
|
131
138
|
if (deleteJob) {
|
|
132
|
-
await this.accessor.
|
|
133
|
-
where: { id: job.id, failedAt: null, attempts: job.attempts }
|
|
134
|
-
});
|
|
139
|
+
await this.accessor.delete({ where: { id: job.id } });
|
|
135
140
|
} else {
|
|
136
|
-
await this.accessor.
|
|
137
|
-
where: { id: job.id
|
|
141
|
+
await this.accessor.update({
|
|
142
|
+
where: { id: job.id },
|
|
138
143
|
data: {
|
|
139
144
|
lockedAt: null,
|
|
140
145
|
lockedBy: null,
|
|
@@ -156,38 +161,23 @@ class PrismaAdapter extends BaseAdapter {
|
|
|
156
161
|
${error.stack}`,
|
|
157
162
|
runAt
|
|
158
163
|
};
|
|
159
|
-
await this.accessor.
|
|
160
|
-
where: { id: job.id
|
|
164
|
+
await this.accessor.update({
|
|
165
|
+
where: { id: job.id },
|
|
161
166
|
data
|
|
162
167
|
});
|
|
163
168
|
}
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
// recorded in the same single write that marks the job as failed)
|
|
167
|
-
async failure({ job, deleteJob, error }) {
|
|
169
|
+
// Job has had too many attempts, it has now permanently failed.
|
|
170
|
+
async failure({ job, deleteJob }) {
|
|
168
171
|
if (deleteJob) {
|
|
169
|
-
await this.accessor.
|
|
170
|
-
where: { id: job.id, failedAt: null, attempts: job.attempts }
|
|
171
|
-
});
|
|
172
|
+
await this.accessor.delete({ where: { id: job.id } });
|
|
172
173
|
} else {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
};
|
|
177
|
-
if (error) {
|
|
178
|
-
data.lastError = `${error.message}
|
|
179
|
-
|
|
180
|
-
${error.stack}`;
|
|
181
|
-
}
|
|
182
|
-
await this.accessor.updateMany({
|
|
183
|
-
where: { id: job.id, failedAt: null, attempts: job.attempts },
|
|
184
|
-
data
|
|
174
|
+
await this.accessor.update({
|
|
175
|
+
where: { id: job.id },
|
|
176
|
+
data: { failedAt: /* @__PURE__ */ new Date() }
|
|
185
177
|
});
|
|
186
178
|
}
|
|
187
179
|
}
|
|
188
|
-
// Schedules a job by creating a new record in the background job table
|
|
189
|
-
// Returns the created job so that callers get access to its `id` (to cancel
|
|
190
|
-
// it later, poll its status, etc.)
|
|
180
|
+
// Schedules a job by creating a new record in the background job table
|
|
191
181
|
async schedule({
|
|
192
182
|
name,
|
|
193
183
|
path,
|
|
@@ -197,7 +187,7 @@ ${error.stack}`;
|
|
|
197
187
|
queue,
|
|
198
188
|
priority
|
|
199
189
|
}) {
|
|
200
|
-
|
|
190
|
+
await this.accessor.create({
|
|
201
191
|
data: {
|
|
202
192
|
handler: JSON.stringify({ name, path, args }),
|
|
203
193
|
runAt,
|
|
@@ -206,34 +196,12 @@ ${error.stack}`;
|
|
|
206
196
|
priority
|
|
207
197
|
}
|
|
208
198
|
});
|
|
209
|
-
const row = data;
|
|
210
|
-
return { ...row, name, path, args };
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Cancels a job by marking it as permanently failed so no worker will pick
|
|
214
|
-
* it up (or retry it, if it's currently being worked on).
|
|
215
|
-
*
|
|
216
|
-
* If the job is currently running, the in-progress attempt is not
|
|
217
|
-
* interrupted (the worker will stop it when `maxRuntime` is exceeded), but
|
|
218
|
-
* it will not be retried and will not be picked up by another worker once
|
|
219
|
-
* its lock goes stale.
|
|
220
|
-
*/
|
|
221
|
-
async cancel({ jobId }) {
|
|
222
|
-
this.logger.debug(`[CedarJS Jobs] Cancelling job ${jobId}`);
|
|
223
|
-
const { count } = await this.accessor.updateMany({
|
|
224
|
-
where: { id: jobId, failedAt: null, runAt: { not: null } },
|
|
225
|
-
data: {
|
|
226
|
-
failedAt: /* @__PURE__ */ new Date(),
|
|
227
|
-
lastError: "Job cancelled by user",
|
|
228
|
-
runAt: null
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
return count > 0;
|
|
232
199
|
}
|
|
233
200
|
async clear() {
|
|
234
201
|
await this.accessor.deleteMany();
|
|
235
202
|
}
|
|
236
203
|
}
|
|
237
|
-
export
|
|
204
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
205
|
+
0 && (module.exports = {
|
|
238
206
|
PrismaAdapter
|
|
239
|
-
};
|
|
207
|
+
});
|
|
@@ -1,9 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var errors_exports = {};
|
|
20
|
+
__export(errors_exports, {
|
|
21
|
+
ModelNameError: () => ModelNameError
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(errors_exports);
|
|
24
|
+
var import_errors = require("../../errors.js");
|
|
25
|
+
class ModelNameError extends import_errors.CedarJSJobsError {
|
|
3
26
|
constructor(name) {
|
|
4
27
|
super(`Model \`${name}\` not found in PrismaClient`);
|
|
5
28
|
}
|
|
6
29
|
}
|
|
7
|
-
export
|
|
30
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
31
|
+
0 && (module.exports = {
|
|
8
32
|
ModelNameError
|
|
9
|
-
};
|
|
33
|
+
});
|
|
@@ -1,14 +1,48 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
2
|
+
"use strict";
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
var cedar_jobs_worker_exports = {};
|
|
31
|
+
__export(cedar_jobs_worker_exports, {
|
|
32
|
+
getWorker: () => getWorker,
|
|
33
|
+
processName: () => processName
|
|
34
|
+
});
|
|
35
|
+
module.exports = __toCommonJS(cedar_jobs_worker_exports);
|
|
36
|
+
var import_node_process = __toESM(require("node:process"));
|
|
37
|
+
var import_helpers = require("yargs/helpers");
|
|
38
|
+
var import_yargs = __toESM(require("yargs/yargs"));
|
|
39
|
+
var import_consts = require("../consts.js");
|
|
40
|
+
var import_errors = require("../errors.js");
|
|
41
|
+
var import_loaders = require("../loaders.js");
|
|
42
|
+
var import_setupEnv = require("../setupEnv.js");
|
|
43
|
+
(0, import_setupEnv.setupEnv)();
|
|
10
44
|
const parseArgs = (argv) => {
|
|
11
|
-
return
|
|
45
|
+
return (0, import_yargs.default)((0, import_helpers.hideBin)(argv)).usage(
|
|
12
46
|
"Starts a single CedarJS Jobs worker to process background jobs\n\nUsage: $0 [options]"
|
|
13
47
|
).option("index", {
|
|
14
48
|
type: "number",
|
|
@@ -32,20 +66,20 @@ const processName = ({
|
|
|
32
66
|
id,
|
|
33
67
|
queues
|
|
34
68
|
}) => {
|
|
35
|
-
return `${PROCESS_TITLE_PREFIX}.${[queues].flat().join("-")}.${id}`;
|
|
69
|
+
return `${import_consts.PROCESS_TITLE_PREFIX}.${[queues].flat().join("-")}.${id}`;
|
|
36
70
|
};
|
|
37
71
|
const setupSignals = ({ worker }) => {
|
|
38
|
-
|
|
72
|
+
import_node_process.default.on("SIGINT", () => {
|
|
39
73
|
worker.logger.warn(
|
|
40
|
-
`[${
|
|
74
|
+
`[${import_node_process.default.title}] SIGINT received at ${(/* @__PURE__ */ new Date()).toISOString()}, finishing work...`
|
|
41
75
|
);
|
|
42
76
|
worker.forever = false;
|
|
43
77
|
});
|
|
44
|
-
|
|
78
|
+
import_node_process.default.on("SIGTERM", () => {
|
|
45
79
|
worker.logger.warn(
|
|
46
|
-
`[${
|
|
80
|
+
`[${import_node_process.default.title}] SIGTERM received at ${(/* @__PURE__ */ new Date()).toISOString()}, exiting now!`
|
|
47
81
|
);
|
|
48
|
-
|
|
82
|
+
import_node_process.default.exit(0);
|
|
49
83
|
});
|
|
50
84
|
};
|
|
51
85
|
const getWorker = async ({
|
|
@@ -56,14 +90,14 @@ const getWorker = async ({
|
|
|
56
90
|
}) => {
|
|
57
91
|
let manager;
|
|
58
92
|
try {
|
|
59
|
-
manager = await loadJobsManager();
|
|
93
|
+
manager = await (0, import_loaders.loadJobsManager)();
|
|
60
94
|
} catch (e) {
|
|
61
95
|
console.error(e);
|
|
62
|
-
|
|
96
|
+
import_node_process.default.exit(1);
|
|
63
97
|
}
|
|
64
98
|
const workerConfig = manager.workers[index];
|
|
65
99
|
if (!workerConfig) {
|
|
66
|
-
throw new WorkerConfigIndexNotFoundError(index);
|
|
100
|
+
throw new import_errors.WorkerConfigIndexNotFoundError(index);
|
|
67
101
|
}
|
|
68
102
|
return manager.createWorker({
|
|
69
103
|
index,
|
|
@@ -73,19 +107,20 @@ const getWorker = async ({
|
|
|
73
107
|
});
|
|
74
108
|
};
|
|
75
109
|
const main = async () => {
|
|
76
|
-
const { index, id, clear, workoff } = await parseArgs(
|
|
110
|
+
const { index, id, clear, workoff } = await parseArgs(import_node_process.default.argv);
|
|
77
111
|
const worker = await getWorker({ index, id, clear, workoff });
|
|
78
|
-
|
|
112
|
+
import_node_process.default.title = processName({ id, queues: worker.queues });
|
|
79
113
|
worker.run().then(() => {
|
|
80
|
-
worker.logger.info(`[${
|
|
81
|
-
|
|
114
|
+
worker.logger.info(`[${import_node_process.default.title}] Worker finished, shutting down.`);
|
|
115
|
+
import_node_process.default.exit(0);
|
|
82
116
|
});
|
|
83
117
|
setupSignals({ worker });
|
|
84
118
|
};
|
|
85
|
-
if (
|
|
119
|
+
if (import_node_process.default.env.NODE_ENV !== "test") {
|
|
86
120
|
main();
|
|
87
121
|
}
|
|
88
|
-
export
|
|
122
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
123
|
+
0 && (module.exports = {
|
|
89
124
|
getWorker,
|
|
90
125
|
processName
|
|
91
|
-
};
|
|
126
|
+
});
|