@neofinancial/chrono 0.3.0 → 0.4.1-next.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/build/index.d.ts +1 -1
- package/build/index.js.map +1 -1
- package/build/processors/create-processor.d.ts +11 -1
- package/build/processors/create-processor.js.map +1 -1
- package/build/processors/index.d.ts +1 -1
- package/build/processors/index.js.map +1 -1
- package/build/processors/simple-processor.js +2 -2
- package/build/processors/simple-processor.js.map +1 -1
- package/build/scheduler.d.ts +9 -0
- package/build/scheduler.js +21 -0
- package/build/scheduler.js.map +1 -0
- package/build/task.d.ts +33 -0
- package/build/task.js +10 -0
- package/build/task.js.map +1 -0
- package/package.json +1 -1
package/build/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { Chrono, type ScheduleTaskInput, type TaskMappingBase, type RegisterTaskHandlerInput, type RegisterTaskHandlerResponse, } from './chrono';
|
|
2
2
|
export { ChronoEvents } from './events';
|
|
3
|
-
export { ProcessorEvents } from './processors';
|
|
3
|
+
export { ProcessorEvents, type ProcessorEventsMap } from './processors';
|
|
4
4
|
export { TaskStatus, type ClaimTaskInput, type Datastore, type ScheduleInput, type Task, type DeleteInput, type DeleteOptions, type DeleteByIdempotencyKeyInput, } from './datastore';
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAMkB;AALhB,gGAAA,MAAM,OAAA;AAMR,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,mCAMkB;AALhB,gGAAA,MAAM,OAAA;AAMR,mCAAwC;AAA/B,sGAAA,YAAY,OAAA;AACrB,2CAAwE;AAA/D,6GAAA,eAAe,OAAA;AAExB,yCASqB;AARnB,uGAAA,UAAU,OAAA"}
|
|
@@ -2,13 +2,23 @@ import type { Datastore, Task } from 'datastore';
|
|
|
2
2
|
import type { TaskMappingBase } from '..';
|
|
3
3
|
import { type BackoffStrategyOptions } from '../backoff-strategy';
|
|
4
4
|
import type { Processor } from './processor';
|
|
5
|
+
/**
|
|
6
|
+
* Configuration for the processor.
|
|
7
|
+
*/
|
|
5
8
|
export type ProcessorConfiguration = {
|
|
9
|
+
/** The maximum number of concurrent tasks that the processor will use when processing. @default 1 */
|
|
6
10
|
maxConcurrency?: number;
|
|
11
|
+
/** The interval at which the processor will wait before next poll when the previous poll returned a task @default 50ms */
|
|
7
12
|
claimIntervalMs?: number;
|
|
8
|
-
|
|
13
|
+
/** The interval at which the processor will wait before next poll when no tasks are available for processing @default 5000ms */
|
|
9
14
|
idleIntervalMs?: number;
|
|
15
|
+
/** The maximum time a task can be claimed for processing before it will be considered stale and claimed again @default 10000ms */
|
|
16
|
+
claimStaleTimeoutMs?: number;
|
|
17
|
+
/** The maximum time a task handler can take to complete before it will be considered timed out @default 5000ms */
|
|
10
18
|
taskHandlerTimeoutMs?: number;
|
|
19
|
+
/** The maximum number of retries for a task handler, before task is marked as failed. @default 5 */
|
|
11
20
|
taskHandlerMaxRetries?: number;
|
|
21
|
+
/** The interval at which the processor will wait before next poll when an unexpected error occurs @default 20000ms */
|
|
12
22
|
processLoopRetryIntervalMs?: number;
|
|
13
23
|
};
|
|
14
24
|
export type CreateProcessorInput<TaskKind extends keyof TaskMapping, TaskMapping extends TaskMappingBase, DatastoreOptions> = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-processor.js","sourceRoot":"","sources":["../../src/processors/create-processor.ts"],"names":[],"mappings":";;
|
|
1
|
+
{"version":3,"file":"create-processor.js","sourceRoot":"","sources":["../../src/processors/create-processor.ts"],"names":[],"mappings":";;AAsCA,0CAcC;AAlDD,0DAA0F;AAE1F,yDAAqD;AAkCrD,SAAgB,eAAe,CAI7B,KAAoE;IACpE,MAAM,eAAe,GAAG,IAAA,yCAAsB,EAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;IAC7E,2BAA2B;IAC3B,OAAO,IAAI,kCAAe,CACxB,KAAK,CAAC,SAAS,EACf,KAAK,CAAC,IAAI,EACV,KAAK,CAAC,OAAO,EACb,eAAe,EACf,KAAK,CAAC,aAAa,CACpB,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/processors/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAExB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/processors/index.ts"],"names":[],"mappings":";;;AAAA,uDAAqD;AAA5C,mHAAA,eAAe,OAAA;AAExB,mCAAoE;AAA3D,yGAAA,eAAe,OAAA"}
|
|
@@ -8,10 +8,10 @@ const events_1 = require("./events");
|
|
|
8
8
|
const DEFAULT_CONFIG = {
|
|
9
9
|
maxConcurrency: 1,
|
|
10
10
|
claimIntervalMs: 50,
|
|
11
|
-
claimStaleTimeoutMs: 10_000,
|
|
12
11
|
idleIntervalMs: 5_000,
|
|
12
|
+
claimStaleTimeoutMs: 10_000,
|
|
13
13
|
taskHandlerTimeoutMs: 5_000,
|
|
14
|
-
taskHandlerMaxRetries:
|
|
14
|
+
taskHandlerMaxRetries: 5,
|
|
15
15
|
processLoopRetryIntervalMs: 20_000,
|
|
16
16
|
};
|
|
17
17
|
const InternalProcessorEvents = { PROCESSOR_LOOP_EXIT: 'processorLoopExit' };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"simple-processor.js","sourceRoot":"","sources":["../../src/processors/simple-processor.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,mDAAkD;AAKlD,0DAA4D;AAC5D,qCAAoE;AAGpE,MAAM,cAAc,GAA0B;IAC5C,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,EAAE;IACnB,
|
|
1
|
+
{"version":3,"file":"simple-processor.js","sourceRoot":"","sources":["../../src/processors/simple-processor.ts"],"names":[],"mappings":";;;AAAA,6CAA2C;AAC3C,mDAAkD;AAKlD,0DAA4D;AAC5D,qCAAoE;AAGpE,MAAM,cAAc,GAA0B;IAC5C,cAAc,EAAE,CAAC;IACjB,eAAe,EAAE,EAAE;IACnB,cAAc,EAAE,KAAK;IACrB,mBAAmB,EAAE,MAAM;IAC3B,oBAAoB,EAAE,KAAK;IAC3B,qBAAqB,EAAE,CAAC;IACxB,0BAA0B,EAAE,MAAM;CACnC,CAAC;AAYF,MAAM,uBAAuB,GAAG,EAAE,mBAAmB,EAAE,mBAAmB,EAAW,CAAC;AAOtF,MAAa,eAKX,SAAQ,0BAAuD;IASrD;IACA;IACA;IACA;IATF,MAAM,CAAwB;IAE9B,YAAY,GAA+C,EAAE,CAAC;IAC9D,aAAa,GAAG,KAAK,CAAC;IAE9B,YACU,SAAmD,EACnD,QAAkB,EAClB,OAAuE,EACvE,eAAgC,EACxC,MAAuC;QAEvC,KAAK,EAAE,CAAC;QANA,cAAS,GAAT,SAAS,CAA0C;QACnD,aAAQ,GAAR,QAAQ,CAAU;QAClB,YAAO,GAAP,OAAO,CAAgE;QACvE,oBAAe,GAAf,eAAe,CAAiB;QAKxC,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,cAAc;YACjB,GAAG,MAAM;SACV,CAAC;QAEF,IAAI,CAAC,uBAAuB,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;OAOG;IACK,uBAAuB;QAC7B,IAAI,IAAI,CAAC,MAAM,CAAC,oBAAoB,IAAI,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,CAAC;YACxE,MAAM,IAAI,KAAK,CACb,yBAAyB,IAAI,CAAC,MAAM,CAAC,oBAAoB,kDAAkD,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,CAChJ,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC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|
|
3
|
+
exports.Scheduler = void 0;
|
|
4
|
+
class Scheduler {
|
|
5
|
+
#tasks = [];
|
|
6
|
+
constructor() {
|
|
7
|
+
this.#tasks = [];
|
|
8
|
+
}
|
|
9
|
+
async schedule(task) {
|
|
10
|
+
this.#tasks.push(task);
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
async run() {
|
|
14
|
+
for (const task of this.#tasks) {
|
|
15
|
+
task.run();
|
|
16
|
+
}
|
|
17
|
+
return true;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Scheduler = Scheduler;
|
|
21
|
+
//# sourceMappingURL=scheduler.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"scheduler.js","sourceRoot":"","sources":["../src/scheduler.ts"],"names":[],"mappings":";;;AAIA,MAAa,SAAS;IACpB,MAAM,GAAc,EAAE,CAAC;IAEvB;QACE,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;IACnB,CAAC;IAEM,KAAK,CAAC,QAAQ,CAAC,IAAa;QACjC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEvB,OAAO,IAAI,CAAC;IACd,CAAC;IAEM,KAAK,CAAC,GAAG;QACd,KAAK,MAAM,IAAI,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC;YAC/B,IAAI,CAAC,GAAG,EAAE,CAAC;QACb,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AApBD,8BAoBC"}
|
package/build/task.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export declare const TaskStatus: {
|
|
2
|
+
readonly PENDING: "PENDING";
|
|
3
|
+
readonly CLAIMED: "CLAIMED";
|
|
4
|
+
readonly COMPLETED: "COMPLETED";
|
|
5
|
+
readonly FAILED: "FAILED";
|
|
6
|
+
};
|
|
7
|
+
export type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus];
|
|
8
|
+
export type Task<TaskKind, TaskData> = {
|
|
9
|
+
/** A unique identifier for the task */
|
|
10
|
+
id: string;
|
|
11
|
+
/** A human-readable name or type for the task */
|
|
12
|
+
kind: TaskKind;
|
|
13
|
+
/** The current status of the task */
|
|
14
|
+
status: TaskStatus;
|
|
15
|
+
/** The payload or data associated with the task */
|
|
16
|
+
data: TaskData;
|
|
17
|
+
/** The priority level of the task (lower numbers can indicate higher priority) */
|
|
18
|
+
priority?: number;
|
|
19
|
+
/** A key used for idempotency to prevent duplicate processing */
|
|
20
|
+
idempotencyKey?: string;
|
|
21
|
+
/** The original scheduled date when the task was first intended to run */
|
|
22
|
+
originalScheduleDate: Date;
|
|
23
|
+
/** The current scheduled execution date, which may change if rescheduled */
|
|
24
|
+
scheduledAt: Date;
|
|
25
|
+
/** The date the task is mark 'claimed */
|
|
26
|
+
claimedAt?: Date;
|
|
27
|
+
/** The date the task is mark 'completed' */
|
|
28
|
+
completedAt?: Date;
|
|
29
|
+
/** The date when the task was last executed (if any) */
|
|
30
|
+
lastExecutedAt?: Date;
|
|
31
|
+
/** A counter to track the number of times the task has been retried */
|
|
32
|
+
retryCount: number;
|
|
33
|
+
};
|
package/build/task.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TaskStatus = void 0;
|
|
4
|
+
exports.TaskStatus = {
|
|
5
|
+
PENDING: "PENDING",
|
|
6
|
+
CLAIMED: "CLAIMED",
|
|
7
|
+
COMPLETED: "COMPLETED",
|
|
8
|
+
FAILED: "FAILED",
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=task.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"task.js","sourceRoot":"","sources":["../src/task.ts"],"names":[],"mappings":";;;AAAa,QAAA,UAAU,GAAG;IACxB,OAAO,EAAE,SAAS;IAClB,OAAO,EAAE,SAAS;IAClB,SAAS,EAAE,WAAW;IACtB,MAAM,EAAE,QAAQ;CACR,CAAC"}
|