@neofinancial/chrono 0.4.1-next.0 → 0.5.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.
Files changed (44) hide show
  1. package/README.md +10 -0
  2. package/build/index.d.mts +217 -0
  3. package/build/index.d.ts +217 -4
  4. package/build/index.js +352 -11
  5. package/build/index.js.map +1 -1
  6. package/build/index.mjs +325 -0
  7. package/build/index.mjs.map +1 -0
  8. package/package.json +17 -4
  9. package/build/backoff-strategy.d.ts +0 -64
  10. package/build/backoff-strategy.js +0 -86
  11. package/build/backoff-strategy.js.map +0 -1
  12. package/build/chrono.d.ts +0 -37
  13. package/build/chrono.js +0 -71
  14. package/build/chrono.js.map +0 -1
  15. package/build/datastore.d.ts +0 -63
  16. package/build/datastore.js +0 -10
  17. package/build/datastore.js.map +0 -1
  18. package/build/events.d.ts +0 -16
  19. package/build/events.js +0 -10
  20. package/build/events.js.map +0 -1
  21. package/build/processors/create-processor.d.ts +0 -31
  22. package/build/processors/create-processor.js +0 -11
  23. package/build/processors/create-processor.js.map +0 -1
  24. package/build/processors/events.d.ts +0 -50
  25. package/build/processors/events.js +0 -19
  26. package/build/processors/events.js.map +0 -1
  27. package/build/processors/index.d.ts +0 -3
  28. package/build/processors/index.js +0 -8
  29. package/build/processors/index.js.map +0 -1
  30. package/build/processors/processor.d.ts +0 -7
  31. package/build/processors/processor.js +0 -3
  32. package/build/processors/processor.js.map +0 -1
  33. package/build/processors/simple-processor.d.ts +0 -63
  34. package/build/processors/simple-processor.js +0 -161
  35. package/build/processors/simple-processor.js.map +0 -1
  36. package/build/scheduler.d.ts +0 -9
  37. package/build/scheduler.js +0 -21
  38. package/build/scheduler.js.map +0 -1
  39. package/build/task.d.ts +0 -33
  40. package/build/task.js +0 -10
  41. package/build/task.js.map +0 -1
  42. package/build/utils/promise-utils.d.ts +0 -1
  43. package/build/utils/promise-utils.js +0 -20
  44. package/build/utils/promise-utils.js.map +0 -1
package/README.md CHANGED
@@ -23,6 +23,16 @@ pnpm add @neofinancial/chrono
23
23
  yarn add @neofinancial/chrono
24
24
  ```
25
25
 
26
+ This package supports both **CommonJS** and **ES Modules**:
27
+
28
+ ```typescript
29
+ // ESM
30
+ import { Chrono } from "@neofinancial/chrono";
31
+
32
+ // CommonJS
33
+ const { Chrono } = require("@neofinancial/chrono");
34
+ ```
35
+
26
36
  ## Basic Usage
27
37
 
28
38
  ```typescript
@@ -0,0 +1,217 @@
1
+ import { EventEmitter } from "node:stream";
2
+
3
+ //#region src/backoff-strategy.d.ts
4
+
5
+ interface FixedBackoffStrategyConfig {
6
+ /** The constant delay in milliseconds. */
7
+ readonly delayMs: number;
8
+ }
9
+ interface LinearBackoffStrategyConfig {
10
+ /** The base delay for all retires that will be incremented off of */
11
+ readonly baseDelayMs?: number;
12
+ /** The amount to increase the delay by for each subsequent retry in milliseconds. */
13
+ readonly incrementMs: number;
14
+ }
15
+ interface ExponentialBackoffStrategyConfig {
16
+ /** The base delay for the first retry (retryAttempt = 0) in milliseconds. */
17
+ readonly baseDelayMs: number;
18
+ /** The maximum delay in milliseconds. Defaults to Infinity. */
19
+ readonly maxDelayMs?: number;
20
+ /** Type of jitter to apply. Defaults to 'none'. */
21
+ readonly jitter?: 'none' | 'full' | 'equal';
22
+ }
23
+ type BackoffStrategyOptions = {
24
+ type: 'none';
25
+ } | ({
26
+ type: 'fixed';
27
+ } & FixedBackoffStrategyConfig) | ({
28
+ type: 'linear';
29
+ } & LinearBackoffStrategyConfig) | ({
30
+ type: 'exponential';
31
+ } & ExponentialBackoffStrategyConfig);
32
+ //#endregion
33
+ //#region src/datastore.d.ts
34
+ declare const TaskStatus: {
35
+ readonly PENDING: "PENDING";
36
+ readonly CLAIMED: "CLAIMED";
37
+ readonly COMPLETED: "COMPLETED";
38
+ readonly FAILED: "FAILED";
39
+ };
40
+ type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus];
41
+ type Task<TaskKind, TaskData> = {
42
+ /** A unique identifier for the task */
43
+ id: string;
44
+ /** A human-readable name or type for the task */
45
+ kind: TaskKind;
46
+ /** The current status of the task */
47
+ status: TaskStatus;
48
+ /** The payload or data associated with the task */
49
+ data: TaskData;
50
+ /** The priority level of the task (lower numbers can indicate higher priority) */
51
+ priority?: number;
52
+ /** A key used for idempotency to prevent duplicate processing */
53
+ idempotencyKey?: string;
54
+ /** The original scheduled date when the task was first intended to run */
55
+ originalScheduleDate: Date;
56
+ /** The current scheduled execution date, which may change if rescheduled */
57
+ scheduledAt: Date;
58
+ /** The date the task is mark 'claimed */
59
+ claimedAt?: Date;
60
+ /** The date the task is mark 'completed' */
61
+ completedAt?: Date;
62
+ /** The date when the task was last executed (if any) */
63
+ lastExecutedAt?: Date;
64
+ /** A counter to track the number of times the task has been retried */
65
+ retryCount: number;
66
+ };
67
+ type ScheduleInput<TaskKind, TaskData, DatastoreOptions> = {
68
+ when: Date;
69
+ kind: TaskKind;
70
+ data: TaskData;
71
+ priority?: number;
72
+ idempotencyKey?: string;
73
+ datastoreOptions?: DatastoreOptions;
74
+ };
75
+ type ClaimTaskInput<TaskKind> = {
76
+ kind: TaskKind;
77
+ claimStaleTimeoutMs: number;
78
+ };
79
+ type DeleteByIdempotencyKeyInput<TaskKind> = {
80
+ kind: TaskKind;
81
+ idempotencyKey: string;
82
+ };
83
+ type DeleteOptions = {
84
+ force?: boolean;
85
+ };
86
+ type DeleteInput<TaskKind> = DeleteByIdempotencyKeyInput<TaskKind> | string;
87
+ interface Datastore<TaskMapping extends TaskMappingBase, DatastoreOptions> {
88
+ schedule<TaskKind extends keyof TaskMapping>(input: ScheduleInput<TaskKind, TaskMapping[TaskKind], DatastoreOptions>): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
89
+ delete<TaskKind extends keyof TaskMapping>(taskId: string, options?: DeleteOptions): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
90
+ delete<TaskKind extends keyof TaskMapping>(key: DeleteByIdempotencyKeyInput<TaskKind>, options?: DeleteOptions): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
91
+ claim<TaskKind extends Extract<keyof TaskMapping, string>>(input: ClaimTaskInput<TaskKind>): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
92
+ retry<TaskKind extends keyof TaskMapping>(taskId: string, retryAt: Date): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
93
+ complete<TaskKind extends keyof TaskMapping>(taskId: string): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
94
+ fail<TaskKind extends keyof TaskMapping>(taskId: string): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
95
+ }
96
+ //#endregion
97
+ //#region src/events.d.ts
98
+ declare const ChronoEvents: {
99
+ /** Chrono instance has started processors and begun polling tasks */
100
+ readonly STARTED: "started";
101
+ /** Chrono instance has failed to gracefully stop so shutdown has been aborted */
102
+ readonly STOP_ABORTED: "stopAborted";
103
+ };
104
+ type ChronoEvents = (typeof ChronoEvents)[keyof typeof ChronoEvents];
105
+ type ChronoEventsMap = {
106
+ [ChronoEvents.STARTED]: [{
107
+ startedAt: Date;
108
+ }];
109
+ [ChronoEvents.STOP_ABORTED]: [{
110
+ timestamp: Date;
111
+ error: unknown;
112
+ }];
113
+ };
114
+ //#endregion
115
+ //#region src/processors/events.d.ts
116
+ declare const ProcessorEvents: {
117
+ /** A task has been claimed by the running processor for handling */
118
+ readonly TASK_CLAIMED: "taskClaimed";
119
+ /** A task has completed processing and successfully marked as completed */
120
+ readonly TASK_COMPLETED: "taskCompleted";
121
+ /** A task has failed during processing and being scheduled for retry */
122
+ readonly TASK_RETRY_SCHEDULED: "taskRetryScheduled";
123
+ /** A task has been marked as FAILED due to process failures exceeding max retries */
124
+ readonly TASK_FAILED: "taskFailed";
125
+ /** A task has been successfully processed but underlying data store failed to mark task as completed. Duplicate processing expected */
126
+ readonly TASK_COMPLETION_FAILURE: "taskCompletionFailure";
127
+ /** An unknown and uncaught exception occurred in processor. Processing paused for processLoopRetryIntervalMs before continuing */
128
+ readonly UNKNOWN_PROCESSING_ERROR: "unknownProcessingError";
129
+ };
130
+ type ProcessorEvents = (typeof ProcessorEvents)[keyof typeof ProcessorEvents];
131
+ type ProcessorEventsMap<TaskKind extends keyof TaskMapping, TaskMapping extends TaskMappingBase> = {
132
+ [ProcessorEvents.TASK_CLAIMED]: [{
133
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
134
+ claimedAt: Date;
135
+ }];
136
+ [ProcessorEvents.TASK_COMPLETED]: [{
137
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
138
+ completedAt: Date;
139
+ }];
140
+ [ProcessorEvents.TASK_RETRY_SCHEDULED]: [{
141
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
142
+ error: unknown;
143
+ retryScheduledAt: Date;
144
+ errorAt: Date;
145
+ }];
146
+ [ProcessorEvents.TASK_FAILED]: [{
147
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
148
+ error: unknown;
149
+ failedAt: Date;
150
+ }];
151
+ [ProcessorEvents.TASK_COMPLETION_FAILURE]: [{
152
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
153
+ error: unknown;
154
+ failedAt: Date;
155
+ }];
156
+ [ProcessorEvents.UNKNOWN_PROCESSING_ERROR]: [{
157
+ error: unknown;
158
+ timestamp: Date;
159
+ }];
160
+ };
161
+ //#endregion
162
+ //#region src/processors/create-processor.d.ts
163
+ /**
164
+ * Configuration for the processor.
165
+ */
166
+ type ProcessorConfiguration = {
167
+ /** The maximum number of concurrent tasks that the processor will use when processing. @default 1 */
168
+ maxConcurrency?: number;
169
+ /** The interval at which the processor will wait before next poll when the previous poll returned a task @default 50ms */
170
+ claimIntervalMs?: number;
171
+ /** The interval at which the processor will wait before next poll when no tasks are available for processing @default 5000ms */
172
+ idleIntervalMs?: number;
173
+ /** The maximum time a task can be claimed for processing before it will be considered stale and claimed again @default 10000ms */
174
+ claimStaleTimeoutMs?: number;
175
+ /** The maximum time a task handler can take to complete before it will be considered timed out @default 5000ms */
176
+ taskHandlerTimeoutMs?: number;
177
+ /** The maximum number of retries for a task handler, before task is marked as failed. @default 5 */
178
+ taskHandlerMaxRetries?: number;
179
+ /** The interval at which the processor will wait before next poll when an unexpected error occurs @default 20000ms */
180
+ processLoopRetryIntervalMs?: number;
181
+ };
182
+ //#endregion
183
+ //#region src/chrono.d.ts
184
+ type TaskMappingBase = Record<string, unknown>;
185
+ type ScheduleTaskInput<TaskKind, TaskData, DatastoreOptions> = ScheduleInput<TaskKind, TaskData, DatastoreOptions>;
186
+ type RegisterTaskHandlerInput<TaskKind, TaskData> = {
187
+ kind: TaskKind;
188
+ handler: (task: Task<TaskKind, TaskData>) => Promise<void>;
189
+ backoffStrategyOptions?: BackoffStrategyOptions;
190
+ processorConfiguration?: ProcessorConfiguration;
191
+ };
192
+ type RegisterTaskHandlerResponse<TaskKind extends keyof TaskMapping, TaskMapping extends TaskMappingBase> = EventEmitter<ProcessorEventsMap<TaskKind, TaskMapping>>;
193
+ /**
194
+ * This is a type that represents the mapping of task kinds to their respective data types.
195
+ *
196
+ * Eg. shape of the TaskMapping type:
197
+ *
198
+ * type TaskMapping = {
199
+ * "async-messaging": { someField: number };
200
+ * "send-email": { url: string };
201
+ * };
202
+ *
203
+ */
204
+ declare class Chrono<TaskMapping extends TaskMappingBase, DatastoreOptions> extends EventEmitter<ChronoEventsMap> {
205
+ private readonly datastore;
206
+ private readonly processors;
207
+ readonly exitTimeoutMs = 60000;
208
+ constructor(datastore: Datastore<TaskMapping, DatastoreOptions>);
209
+ start(): Promise<void>;
210
+ stop(): Promise<void>;
211
+ scheduleTask<TaskKind extends keyof TaskMapping>(input: ScheduleTaskInput<TaskKind, TaskMapping[TaskKind], DatastoreOptions>): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
212
+ deleteTask<TaskKind extends keyof TaskMapping>(taskId: string): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
213
+ registerTaskHandler<TaskKind extends Extract<keyof TaskMapping, string>>(input: RegisterTaskHandlerInput<TaskKind, TaskMapping[TaskKind]>): RegisterTaskHandlerResponse<TaskKind, TaskMapping>;
214
+ }
215
+ //#endregion
216
+ export { Chrono, ChronoEvents, type ClaimTaskInput, type Datastore, type DeleteByIdempotencyKeyInput, type DeleteInput, type DeleteOptions, ProcessorEvents, type ProcessorEventsMap, type RegisterTaskHandlerInput, type RegisterTaskHandlerResponse, type ScheduleInput, type ScheduleTaskInput, type Task, type TaskMappingBase, TaskStatus };
217
+ //# sourceMappingURL=index.d.mts.map
package/build/index.d.ts CHANGED
@@ -1,4 +1,217 @@
1
- export { Chrono, type ScheduleTaskInput, type TaskMappingBase, type RegisterTaskHandlerInput, type RegisterTaskHandlerResponse, } from './chrono';
2
- export { ChronoEvents } from './events';
3
- export { ProcessorEvents, type ProcessorEventsMap } from './processors';
4
- export { TaskStatus, type ClaimTaskInput, type Datastore, type ScheduleInput, type Task, type DeleteInput, type DeleteOptions, type DeleteByIdempotencyKeyInput, } from './datastore';
1
+ import { EventEmitter } from "node:stream";
2
+
3
+ //#region src/backoff-strategy.d.ts
4
+
5
+ interface FixedBackoffStrategyConfig {
6
+ /** The constant delay in milliseconds. */
7
+ readonly delayMs: number;
8
+ }
9
+ interface LinearBackoffStrategyConfig {
10
+ /** The base delay for all retires that will be incremented off of */
11
+ readonly baseDelayMs?: number;
12
+ /** The amount to increase the delay by for each subsequent retry in milliseconds. */
13
+ readonly incrementMs: number;
14
+ }
15
+ interface ExponentialBackoffStrategyConfig {
16
+ /** The base delay for the first retry (retryAttempt = 0) in milliseconds. */
17
+ readonly baseDelayMs: number;
18
+ /** The maximum delay in milliseconds. Defaults to Infinity. */
19
+ readonly maxDelayMs?: number;
20
+ /** Type of jitter to apply. Defaults to 'none'. */
21
+ readonly jitter?: 'none' | 'full' | 'equal';
22
+ }
23
+ type BackoffStrategyOptions = {
24
+ type: 'none';
25
+ } | ({
26
+ type: 'fixed';
27
+ } & FixedBackoffStrategyConfig) | ({
28
+ type: 'linear';
29
+ } & LinearBackoffStrategyConfig) | ({
30
+ type: 'exponential';
31
+ } & ExponentialBackoffStrategyConfig);
32
+ //#endregion
33
+ //#region src/datastore.d.ts
34
+ declare const TaskStatus: {
35
+ readonly PENDING: "PENDING";
36
+ readonly CLAIMED: "CLAIMED";
37
+ readonly COMPLETED: "COMPLETED";
38
+ readonly FAILED: "FAILED";
39
+ };
40
+ type TaskStatus = (typeof TaskStatus)[keyof typeof TaskStatus];
41
+ type Task<TaskKind, TaskData> = {
42
+ /** A unique identifier for the task */
43
+ id: string;
44
+ /** A human-readable name or type for the task */
45
+ kind: TaskKind;
46
+ /** The current status of the task */
47
+ status: TaskStatus;
48
+ /** The payload or data associated with the task */
49
+ data: TaskData;
50
+ /** The priority level of the task (lower numbers can indicate higher priority) */
51
+ priority?: number;
52
+ /** A key used for idempotency to prevent duplicate processing */
53
+ idempotencyKey?: string;
54
+ /** The original scheduled date when the task was first intended to run */
55
+ originalScheduleDate: Date;
56
+ /** The current scheduled execution date, which may change if rescheduled */
57
+ scheduledAt: Date;
58
+ /** The date the task is mark 'claimed */
59
+ claimedAt?: Date;
60
+ /** The date the task is mark 'completed' */
61
+ completedAt?: Date;
62
+ /** The date when the task was last executed (if any) */
63
+ lastExecutedAt?: Date;
64
+ /** A counter to track the number of times the task has been retried */
65
+ retryCount: number;
66
+ };
67
+ type ScheduleInput<TaskKind, TaskData, DatastoreOptions> = {
68
+ when: Date;
69
+ kind: TaskKind;
70
+ data: TaskData;
71
+ priority?: number;
72
+ idempotencyKey?: string;
73
+ datastoreOptions?: DatastoreOptions;
74
+ };
75
+ type ClaimTaskInput<TaskKind> = {
76
+ kind: TaskKind;
77
+ claimStaleTimeoutMs: number;
78
+ };
79
+ type DeleteByIdempotencyKeyInput<TaskKind> = {
80
+ kind: TaskKind;
81
+ idempotencyKey: string;
82
+ };
83
+ type DeleteOptions = {
84
+ force?: boolean;
85
+ };
86
+ type DeleteInput<TaskKind> = DeleteByIdempotencyKeyInput<TaskKind> | string;
87
+ interface Datastore<TaskMapping extends TaskMappingBase, DatastoreOptions> {
88
+ schedule<TaskKind extends keyof TaskMapping>(input: ScheduleInput<TaskKind, TaskMapping[TaskKind], DatastoreOptions>): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
89
+ delete<TaskKind extends keyof TaskMapping>(taskId: string, options?: DeleteOptions): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
90
+ delete<TaskKind extends keyof TaskMapping>(key: DeleteByIdempotencyKeyInput<TaskKind>, options?: DeleteOptions): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
91
+ claim<TaskKind extends Extract<keyof TaskMapping, string>>(input: ClaimTaskInput<TaskKind>): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
92
+ retry<TaskKind extends keyof TaskMapping>(taskId: string, retryAt: Date): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
93
+ complete<TaskKind extends keyof TaskMapping>(taskId: string): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
94
+ fail<TaskKind extends keyof TaskMapping>(taskId: string): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
95
+ }
96
+ //#endregion
97
+ //#region src/events.d.ts
98
+ declare const ChronoEvents: {
99
+ /** Chrono instance has started processors and begun polling tasks */
100
+ readonly STARTED: "started";
101
+ /** Chrono instance has failed to gracefully stop so shutdown has been aborted */
102
+ readonly STOP_ABORTED: "stopAborted";
103
+ };
104
+ type ChronoEvents = (typeof ChronoEvents)[keyof typeof ChronoEvents];
105
+ type ChronoEventsMap = {
106
+ [ChronoEvents.STARTED]: [{
107
+ startedAt: Date;
108
+ }];
109
+ [ChronoEvents.STOP_ABORTED]: [{
110
+ timestamp: Date;
111
+ error: unknown;
112
+ }];
113
+ };
114
+ //#endregion
115
+ //#region src/processors/events.d.ts
116
+ declare const ProcessorEvents: {
117
+ /** A task has been claimed by the running processor for handling */
118
+ readonly TASK_CLAIMED: "taskClaimed";
119
+ /** A task has completed processing and successfully marked as completed */
120
+ readonly TASK_COMPLETED: "taskCompleted";
121
+ /** A task has failed during processing and being scheduled for retry */
122
+ readonly TASK_RETRY_SCHEDULED: "taskRetryScheduled";
123
+ /** A task has been marked as FAILED due to process failures exceeding max retries */
124
+ readonly TASK_FAILED: "taskFailed";
125
+ /** A task has been successfully processed but underlying data store failed to mark task as completed. Duplicate processing expected */
126
+ readonly TASK_COMPLETION_FAILURE: "taskCompletionFailure";
127
+ /** An unknown and uncaught exception occurred in processor. Processing paused for processLoopRetryIntervalMs before continuing */
128
+ readonly UNKNOWN_PROCESSING_ERROR: "unknownProcessingError";
129
+ };
130
+ type ProcessorEvents = (typeof ProcessorEvents)[keyof typeof ProcessorEvents];
131
+ type ProcessorEventsMap<TaskKind extends keyof TaskMapping, TaskMapping extends TaskMappingBase> = {
132
+ [ProcessorEvents.TASK_CLAIMED]: [{
133
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
134
+ claimedAt: Date;
135
+ }];
136
+ [ProcessorEvents.TASK_COMPLETED]: [{
137
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
138
+ completedAt: Date;
139
+ }];
140
+ [ProcessorEvents.TASK_RETRY_SCHEDULED]: [{
141
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
142
+ error: unknown;
143
+ retryScheduledAt: Date;
144
+ errorAt: Date;
145
+ }];
146
+ [ProcessorEvents.TASK_FAILED]: [{
147
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
148
+ error: unknown;
149
+ failedAt: Date;
150
+ }];
151
+ [ProcessorEvents.TASK_COMPLETION_FAILURE]: [{
152
+ task: Task<TaskKind, TaskMapping[TaskKind]>;
153
+ error: unknown;
154
+ failedAt: Date;
155
+ }];
156
+ [ProcessorEvents.UNKNOWN_PROCESSING_ERROR]: [{
157
+ error: unknown;
158
+ timestamp: Date;
159
+ }];
160
+ };
161
+ //#endregion
162
+ //#region src/processors/create-processor.d.ts
163
+ /**
164
+ * Configuration for the processor.
165
+ */
166
+ type ProcessorConfiguration = {
167
+ /** The maximum number of concurrent tasks that the processor will use when processing. @default 1 */
168
+ maxConcurrency?: number;
169
+ /** The interval at which the processor will wait before next poll when the previous poll returned a task @default 50ms */
170
+ claimIntervalMs?: number;
171
+ /** The interval at which the processor will wait before next poll when no tasks are available for processing @default 5000ms */
172
+ idleIntervalMs?: number;
173
+ /** The maximum time a task can be claimed for processing before it will be considered stale and claimed again @default 10000ms */
174
+ claimStaleTimeoutMs?: number;
175
+ /** The maximum time a task handler can take to complete before it will be considered timed out @default 5000ms */
176
+ taskHandlerTimeoutMs?: number;
177
+ /** The maximum number of retries for a task handler, before task is marked as failed. @default 5 */
178
+ taskHandlerMaxRetries?: number;
179
+ /** The interval at which the processor will wait before next poll when an unexpected error occurs @default 20000ms */
180
+ processLoopRetryIntervalMs?: number;
181
+ };
182
+ //#endregion
183
+ //#region src/chrono.d.ts
184
+ type TaskMappingBase = Record<string, unknown>;
185
+ type ScheduleTaskInput<TaskKind, TaskData, DatastoreOptions> = ScheduleInput<TaskKind, TaskData, DatastoreOptions>;
186
+ type RegisterTaskHandlerInput<TaskKind, TaskData> = {
187
+ kind: TaskKind;
188
+ handler: (task: Task<TaskKind, TaskData>) => Promise<void>;
189
+ backoffStrategyOptions?: BackoffStrategyOptions;
190
+ processorConfiguration?: ProcessorConfiguration;
191
+ };
192
+ type RegisterTaskHandlerResponse<TaskKind extends keyof TaskMapping, TaskMapping extends TaskMappingBase> = EventEmitter<ProcessorEventsMap<TaskKind, TaskMapping>>;
193
+ /**
194
+ * This is a type that represents the mapping of task kinds to their respective data types.
195
+ *
196
+ * Eg. shape of the TaskMapping type:
197
+ *
198
+ * type TaskMapping = {
199
+ * "async-messaging": { someField: number };
200
+ * "send-email": { url: string };
201
+ * };
202
+ *
203
+ */
204
+ declare class Chrono<TaskMapping extends TaskMappingBase, DatastoreOptions> extends EventEmitter<ChronoEventsMap> {
205
+ private readonly datastore;
206
+ private readonly processors;
207
+ readonly exitTimeoutMs = 60000;
208
+ constructor(datastore: Datastore<TaskMapping, DatastoreOptions>);
209
+ start(): Promise<void>;
210
+ stop(): Promise<void>;
211
+ scheduleTask<TaskKind extends keyof TaskMapping>(input: ScheduleTaskInput<TaskKind, TaskMapping[TaskKind], DatastoreOptions>): Promise<Task<TaskKind, TaskMapping[TaskKind]>>;
212
+ deleteTask<TaskKind extends keyof TaskMapping>(taskId: string): Promise<Task<TaskKind, TaskMapping[TaskKind]> | undefined>;
213
+ registerTaskHandler<TaskKind extends Extract<keyof TaskMapping, string>>(input: RegisterTaskHandlerInput<TaskKind, TaskMapping[TaskKind]>): RegisterTaskHandlerResponse<TaskKind, TaskMapping>;
214
+ }
215
+ //#endregion
216
+ export { Chrono, ChronoEvents, type ClaimTaskInput, type Datastore, type DeleteByIdempotencyKeyInput, type DeleteInput, type DeleteOptions, ProcessorEvents, type ProcessorEventsMap, type RegisterTaskHandlerInput, type RegisterTaskHandlerResponse, type ScheduleInput, type ScheduleTaskInput, type Task, type TaskMappingBase, TaskStatus };
217
+ //# sourceMappingURL=index.d.ts.map