@twin.org/background-task-models 0.0.3-next.1 → 0.0.3-next.10
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/README.md +1 -1
- package/dist/es/index.js +1 -2
- package/dist/es/index.js.map +1 -1
- package/dist/es/models/IBackgroundTaskComponent.js +2 -0
- package/dist/es/models/IBackgroundTaskComponent.js.map +1 -0
- package/dist/types/index.d.ts +1 -2
- package/dist/types/models/{IBackgroundTaskConnector.d.ts → IBackgroundTaskComponent.d.ts} +15 -5
- package/docs/changelog.md +128 -53
- package/docs/examples.md +179 -1
- package/docs/reference/index.md +1 -2
- package/docs/reference/interfaces/IBackgroundTask.md +22 -22
- package/docs/reference/interfaces/{IBackgroundTaskConnector.md → IBackgroundTaskComponent.md} +43 -15
- package/docs/reference/interfaces/IScheduledTaskInfo.md +1 -1
- package/docs/reference/interfaces/IScheduledTaskTime.md +8 -8
- package/docs/reference/interfaces/ITaskSchedulerComponent.md +3 -3
- package/docs/reference/variables/TaskStatus.md +5 -5
- package/package.json +4 -4
- package/dist/es/factories/backgroundTaskConnectorFactory.js +0 -9
- package/dist/es/factories/backgroundTaskConnectorFactory.js.map +0 -1
- package/dist/es/models/IBackgroundTaskConnector.js +0 -2
- package/dist/es/models/IBackgroundTaskConnector.js.map +0 -1
- package/dist/types/factories/backgroundTaskConnectorFactory.d.ts +0 -6
- package/docs/reference/variables/BackgroundTaskConnectorFactory.md +0 -5
package/README.md
CHANGED
package/dist/es/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
// Copyright 2024 IOTA Stiftung.
|
|
2
2
|
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
export * from "./factories/backgroundTaskConnectorFactory.js";
|
|
4
3
|
export * from "./models/IBackgroundTask.js";
|
|
5
|
-
export * from "./models/
|
|
4
|
+
export * from "./models/IBackgroundTaskComponent.js";
|
|
6
5
|
export * from "./models/IScheduledTaskInfo.js";
|
|
7
6
|
export * from "./models/IScheduledTaskTime.js";
|
|
8
7
|
export * from "./models/ITaskSchedulerComponent.js";
|
package/dist/es/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,sCAAsC,CAAC;AACrD,cAAc,gCAAgC,CAAC;AAC/C,cAAc,gCAAgC,CAAC;AAC/C,cAAc,qCAAqC,CAAC;AACpD,cAAc,wBAAwB,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nexport * from \"./models/IBackgroundTask.js\";\nexport * from \"./models/IBackgroundTaskComponent.js\";\nexport * from \"./models/IScheduledTaskInfo.js\";\nexport * from \"./models/IScheduledTaskTime.js\";\nexport * from \"./models/ITaskSchedulerComponent.js\";\nexport * from \"./models/taskStatus.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"IBackgroundTaskComponent.js","sourceRoot":"","sources":["../../../src/models/IBackgroundTaskComponent.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\nimport type { SortDirection } from \"@twin.org/entity\";\nimport type { IBackgroundTask } from \"./IBackgroundTask.js\";\nimport type { TaskStatus } from \"./taskStatus.js\";\n\n/**\n * Interface describing a background task component.\n */\nexport interface IBackgroundTaskComponent extends IComponent {\n\t/**\n\t * Register a handler for a task.\n\t * @param taskType The type of the task the handler can process.\n\t * @param module The module the handler is in.\n\t * @param method The method in the module to execute.\n\t * @param stateChangeCallback The callback to execute when the task state is updated.\n\t * @param options Additional options for the task.\n\t * @param options.maxWorkerCount The maximum number of workers in the pool.\n\t * @param options.idleShutdownTimeout Terminate the worker after it has been idle for the specified timeout in milliseconds, defaults to 0 shutdown immediately, -1 to keep forever.\n\t * @param options.initialiseMethod The initialisation method to call on the module when a worker is started.\n\t * @param options.shutdownMethod The shutdown method to call on the module when a worker is stopped.\n\t * @returns Nothing.\n\t */\n\tregisterHandler<T, U>(\n\t\ttaskType: string,\n\t\tmodule: string,\n\t\tmethod: string,\n\t\tstateChangeCallback?: (task: IBackgroundTask<T, U>) => Promise<void>,\n\t\toptions?: {\n\t\t\tmaxWorkerCount?: number;\n\t\t\tidleShutdownTimeout?: number;\n\t\t\tinitialiseMethod?: string;\n\t\t\tshutdownMethod?: string;\n\t\t}\n\t): Promise<void>;\n\n\t/**\n\t * Unregister a handler for a task.\n\t * @param taskType The type of the task handler to remove.\n\t * @returns Nothing.\n\t */\n\tunregisterHandler(taskType: string): Promise<void>;\n\n\t/**\n\t * Create a new task.\n\t * @param taskType The type of the task.\n\t * @param payload The payload for the task.\n\t * @param options Additional options for the task.\n\t * @param options.retryCount The number of times to retry the task if it fails, leave undefined to retry forever.\n\t * @param options.retryInterval The interval in milliseconds to wait between retries, defaults to 5000, leave undefined for default scheduling.\n\t * @param options.retainFor The amount of time in milliseconds to retain the result until removal, defaults to 0 for immediate removal, set to -1 to keep forever.\n\t * @returns The id of the created task.\n\t */\n\tcreate<T>(\n\t\ttaskType: string,\n\t\tpayload?: T,\n\t\toptions?: {\n\t\t\tretryCount?: number;\n\t\t\tretryInterval?: number;\n\t\t\tretainFor?: number;\n\t\t}\n\t): Promise<string>;\n\n\t/**\n\t * Get the task details.\n\t * @param taskId The id of the task to get the details for.\n\t * @returns The details of the task.\n\t */\n\tget<T, U>(taskId: string): Promise<IBackgroundTask<T, U> | undefined>;\n\n\t/**\n\t * Retry a failed task immediately instead of waiting for it's next scheduled retry time.\n\t * @param taskId The id of the task to retry.\n\t * @returns Nothing.\n\t */\n\tretry(taskId: string): Promise<void>;\n\n\t/**\n\t * Remove a task ignoring any retain until date.\n\t * @param taskId The id of the task to remove.\n\t * @returns Nothing.\n\t */\n\tremove(taskId: string): Promise<void>;\n\n\t/**\n\t * Cancel a task, will only be actioned if the task is currently pending.\n\t * @param taskId The id of the task to cancel.\n\t * @returns Nothing.\n\t */\n\tcancel(taskId: string): Promise<void>;\n\n\t/**\n\t * Get a list of tasks.\n\t * @param taskType The type of the task to get.\n\t * @param taskStatus The status of the task to get.\n\t * @param sortProperty The property to sort by, defaults to dateCreated.\n\t * @param sortDirection The order to sort by, defaults to ascending.\n\t * @param cursor The cursor to get the next page of tasks.\n\t * @param limit Limit the number of entities to return.\n\t * @returns The list of tasks.\n\t */\n\tquery(\n\t\ttaskType?: string,\n\t\ttaskStatus?: TaskStatus,\n\t\tsortProperty?: \"dateCreated\" | \"dateModified\" | \"dateCompleted\" | \"status\",\n\t\tsortDirection?: SortDirection,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentities: IBackgroundTask[];\n\t\tcursor?: string;\n\t}>;\n}\n"]}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
export * from "./factories/backgroundTaskConnectorFactory.js";
|
|
2
1
|
export * from "./models/IBackgroundTask.js";
|
|
3
|
-
export * from "./models/
|
|
2
|
+
export * from "./models/IBackgroundTaskComponent.js";
|
|
4
3
|
export * from "./models/IScheduledTaskInfo.js";
|
|
5
4
|
export * from "./models/IScheduledTaskTime.js";
|
|
6
5
|
export * from "./models/ITaskSchedulerComponent.js";
|
|
@@ -3,18 +3,28 @@ import type { SortDirection } from "@twin.org/entity";
|
|
|
3
3
|
import type { IBackgroundTask } from "./IBackgroundTask.js";
|
|
4
4
|
import type { TaskStatus } from "./taskStatus.js";
|
|
5
5
|
/**
|
|
6
|
-
* Interface describing a background task
|
|
6
|
+
* Interface describing a background task component.
|
|
7
7
|
*/
|
|
8
|
-
export interface
|
|
8
|
+
export interface IBackgroundTaskComponent extends IComponent {
|
|
9
9
|
/**
|
|
10
10
|
* Register a handler for a task.
|
|
11
11
|
* @param taskType The type of the task the handler can process.
|
|
12
12
|
* @param module The module the handler is in.
|
|
13
13
|
* @param method The method in the module to execute.
|
|
14
14
|
* @param stateChangeCallback The callback to execute when the task state is updated.
|
|
15
|
+
* @param options Additional options for the task.
|
|
16
|
+
* @param options.maxWorkerCount The maximum number of workers in the pool.
|
|
17
|
+
* @param options.idleShutdownTimeout Terminate the worker after it has been idle for the specified timeout in milliseconds, defaults to 0 shutdown immediately, -1 to keep forever.
|
|
18
|
+
* @param options.initialiseMethod The initialisation method to call on the module when a worker is started.
|
|
19
|
+
* @param options.shutdownMethod The shutdown method to call on the module when a worker is stopped.
|
|
15
20
|
* @returns Nothing.
|
|
16
21
|
*/
|
|
17
|
-
registerHandler<T, U>(taskType: string, module: string, method: string, stateChangeCallback?: (task: IBackgroundTask<T, U>) => Promise<void
|
|
22
|
+
registerHandler<T, U>(taskType: string, module: string, method: string, stateChangeCallback?: (task: IBackgroundTask<T, U>) => Promise<void>, options?: {
|
|
23
|
+
maxWorkerCount?: number;
|
|
24
|
+
idleShutdownTimeout?: number;
|
|
25
|
+
initialiseMethod?: string;
|
|
26
|
+
shutdownMethod?: string;
|
|
27
|
+
}): Promise<void>;
|
|
18
28
|
/**
|
|
19
29
|
* Unregister a handler for a task.
|
|
20
30
|
* @param taskType The type of the task handler to remove.
|
|
@@ -23,7 +33,7 @@ export interface IBackgroundTaskConnector extends IComponent {
|
|
|
23
33
|
unregisterHandler(taskType: string): Promise<void>;
|
|
24
34
|
/**
|
|
25
35
|
* Create a new task.
|
|
26
|
-
* @param
|
|
36
|
+
* @param taskType The type of the task.
|
|
27
37
|
* @param payload The payload for the task.
|
|
28
38
|
* @param options Additional options for the task.
|
|
29
39
|
* @param options.retryCount The number of times to retry the task if it fails, leave undefined to retry forever.
|
|
@@ -31,7 +41,7 @@ export interface IBackgroundTaskConnector extends IComponent {
|
|
|
31
41
|
* @param options.retainFor The amount of time in milliseconds to retain the result until removal, defaults to 0 for immediate removal, set to -1 to keep forever.
|
|
32
42
|
* @returns The id of the created task.
|
|
33
43
|
*/
|
|
34
|
-
create<T>(
|
|
44
|
+
create<T>(taskType: string, payload?: T, options?: {
|
|
35
45
|
retryCount?: number;
|
|
36
46
|
retryInterval?: number;
|
|
37
47
|
retainFor?: number;
|
package/docs/changelog.md
CHANGED
|
@@ -1,164 +1,239 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Changelog
|
|
2
2
|
|
|
3
|
-
## [0.0.3-next.
|
|
3
|
+
## [0.0.3-next.10](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.9...background-task-models-v0.0.3-next.10) (2026-06-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Miscellaneous Chores
|
|
7
|
+
|
|
8
|
+
* **background-task-models:** Synchronize repo versions
|
|
9
|
+
|
|
10
|
+
## [0.0.3-next.9](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.8...background-task-models-v0.0.3-next.9) (2026-06-08)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
### Features
|
|
14
|
+
|
|
15
|
+
* add context id features ([#29](https://github.com/iotaledger/twin-background-task/issues/29)) ([46ede49](https://github.com/iotaledger/twin-background-task/commit/46ede49a51a4955fe1530e645a66f0073db9a1fd))
|
|
16
|
+
* add multi-threading ([#32](https://github.com/iotaledger/twin-background-task/issues/32)) ([60fb5ef](https://github.com/iotaledger/twin-background-task/commit/60fb5ef55d3f7dc46a27c38d4497812d80b98e3b))
|
|
17
|
+
* add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
|
|
18
|
+
* add validate-locales ([968cbf9](https://github.com/iotaledger/twin-background-task/commit/968cbf966fffb5060305e8b221fecc0b6c8105b9))
|
|
19
|
+
* eslint migration to flat config ([6c9136c](https://github.com/iotaledger/twin-background-task/commit/6c9136c37bccdbbd109892d1503660aab7080d49))
|
|
20
|
+
* improve comment ([f2b4ac2](https://github.com/iotaledger/twin-background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
|
|
21
|
+
* only run tasks from your own thread ([c7d305b](https://github.com/iotaledger/twin-background-task/commit/c7d305b9807e65b8b1af6d0c2ca59e74190cab69))
|
|
22
|
+
* typescript 6 update ([e3f2727](https://github.com/iotaledger/twin-background-task/commit/e3f272783e0de7cf4d31f3e84a8e6f5ff633961b))
|
|
23
|
+
* update dependencies ([0867e02](https://github.com/iotaledger/twin-background-task/commit/0867e02fc3c034f8e8cf5918ac6cc4e6b5ca0c93))
|
|
24
|
+
* update dependencies ([8e65767](https://github.com/iotaledger/twin-background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
|
|
25
|
+
* update framework core ([a068098](https://github.com/iotaledger/twin-background-task/commit/a0680983d7923a1bfb980a67879019bb870ccc5d))
|
|
26
|
+
* update IComponent signatures ([e1a79bc](https://github.com/iotaledger/twin-background-task/commit/e1a79bc4dd813435c56e376f231a4b4ecd2276bf))
|
|
27
|
+
* use shared store mechanism ([#6](https://github.com/iotaledger/twin-background-task/issues/6)) ([27ed203](https://github.com/iotaledger/twin-background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
|
|
28
|
+
|
|
29
|
+
## [0.0.3-next.8](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.7...background-task-models-v0.0.3-next.8) (2026-06-08)
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
### Miscellaneous Chores
|
|
33
|
+
|
|
34
|
+
* **background-task-models:** Synchronize repo versions
|
|
35
|
+
|
|
36
|
+
## [0.0.3-next.7](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.6...background-task-models-v0.0.3-next.7) (2026-05-20)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### Features
|
|
40
|
+
|
|
41
|
+
* update dependencies ([0867e02](https://github.com/iotaledger/twin-background-task/commit/0867e02fc3c034f8e8cf5918ac6cc4e6b5ca0c93))
|
|
42
|
+
|
|
43
|
+
## [0.0.3-next.6](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.5...background-task-models-v0.0.3-next.6) (2026-05-11)
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
### Features
|
|
47
|
+
|
|
48
|
+
* typescript 6 update ([e3f2727](https://github.com/iotaledger/twin-background-task/commit/e3f272783e0de7cf4d31f3e84a8e6f5ff633961b))
|
|
49
|
+
|
|
50
|
+
## [0.0.3-next.5](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.4...background-task-models-v0.0.3-next.5) (2026-04-10)
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
### Miscellaneous Chores
|
|
54
|
+
|
|
55
|
+
* **background-task-models:** Synchronize repo versions
|
|
56
|
+
|
|
57
|
+
## [0.0.3-next.4](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.3...background-task-models-v0.0.3-next.4) (2026-02-23)
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Miscellaneous Chores
|
|
61
|
+
|
|
62
|
+
* **background-task-models:** Synchronize repo versions
|
|
63
|
+
|
|
64
|
+
## [0.0.3-next.3](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.2...background-task-models-v0.0.3-next.3) (2026-01-07)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
### Miscellaneous Chores
|
|
68
|
+
|
|
69
|
+
* **background-task-models:** Synchronize repo versions
|
|
70
|
+
|
|
71
|
+
## [0.0.3-next.2](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.1...background-task-models-v0.0.3-next.2) (2025-11-28)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
### Features
|
|
75
|
+
|
|
76
|
+
* add multi-threading ([#32](https://github.com/iotaledger/twin-background-task/issues/32)) ([60fb5ef](https://github.com/iotaledger/twin-background-task/commit/60fb5ef55d3f7dc46a27c38d4497812d80b98e3b))
|
|
77
|
+
|
|
78
|
+
## [0.0.3-next.1](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.3-next.0...background-task-models-v0.0.3-next.1) (2025-11-11)
|
|
4
79
|
|
|
5
80
|
|
|
6
81
|
### Features
|
|
7
82
|
|
|
8
|
-
* add context id features ([#29](https://github.com/
|
|
9
|
-
* add task scheduler ([754d973](https://github.com/
|
|
10
|
-
* add validate-locales ([968cbf9](https://github.com/
|
|
11
|
-
* eslint migration to flat config ([6c9136c](https://github.com/
|
|
12
|
-
* improve comment ([f2b4ac2](https://github.com/
|
|
13
|
-
* only run tasks from your own thread ([c7d305b](https://github.com/
|
|
14
|
-
* update dependencies ([8e65767](https://github.com/
|
|
15
|
-
* update framework core ([a068098](https://github.com/
|
|
16
|
-
* update IComponent signatures ([e1a79bc](https://github.com/
|
|
17
|
-
* use shared store mechanism ([#6](https://github.com/
|
|
83
|
+
* add context id features ([#29](https://github.com/iotaledger/twin-background-task/issues/29)) ([46ede49](https://github.com/iotaledger/twin-background-task/commit/46ede49a51a4955fe1530e645a66f0073db9a1fd))
|
|
84
|
+
* add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
|
|
85
|
+
* add validate-locales ([968cbf9](https://github.com/iotaledger/twin-background-task/commit/968cbf966fffb5060305e8b221fecc0b6c8105b9))
|
|
86
|
+
* eslint migration to flat config ([6c9136c](https://github.com/iotaledger/twin-background-task/commit/6c9136c37bccdbbd109892d1503660aab7080d49))
|
|
87
|
+
* improve comment ([f2b4ac2](https://github.com/iotaledger/twin-background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
|
|
88
|
+
* only run tasks from your own thread ([c7d305b](https://github.com/iotaledger/twin-background-task/commit/c7d305b9807e65b8b1af6d0c2ca59e74190cab69))
|
|
89
|
+
* update dependencies ([8e65767](https://github.com/iotaledger/twin-background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
|
|
90
|
+
* update framework core ([a068098](https://github.com/iotaledger/twin-background-task/commit/a0680983d7923a1bfb980a67879019bb870ccc5d))
|
|
91
|
+
* update IComponent signatures ([e1a79bc](https://github.com/iotaledger/twin-background-task/commit/e1a79bc4dd813435c56e376f231a4b4ecd2276bf))
|
|
92
|
+
* use shared store mechanism ([#6](https://github.com/iotaledger/twin-background-task/issues/6)) ([27ed203](https://github.com/iotaledger/twin-background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
|
|
18
93
|
|
|
19
|
-
## [0.0.2-next.9](https://github.com/
|
|
94
|
+
## [0.0.2-next.9](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.8...background-task-models-v0.0.2-next.9) (2025-10-09)
|
|
20
95
|
|
|
21
96
|
|
|
22
97
|
### Features
|
|
23
98
|
|
|
24
|
-
* add validate-locales ([968cbf9](https://github.com/
|
|
99
|
+
* add validate-locales ([968cbf9](https://github.com/iotaledger/twin-background-task/commit/968cbf966fffb5060305e8b221fecc0b6c8105b9))
|
|
25
100
|
|
|
26
|
-
## [0.0.2-next.8](https://github.com/
|
|
101
|
+
## [0.0.2-next.8](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.7...background-task-models-v0.0.2-next.8) (2025-09-29)
|
|
27
102
|
|
|
28
103
|
|
|
29
104
|
### Features
|
|
30
105
|
|
|
31
|
-
* update IComponent signatures ([e1a79bc](https://github.com/
|
|
106
|
+
* update IComponent signatures ([e1a79bc](https://github.com/iotaledger/twin-background-task/commit/e1a79bc4dd813435c56e376f231a4b4ecd2276bf))
|
|
32
107
|
|
|
33
|
-
## [0.0.2-next.7](https://github.com/
|
|
108
|
+
## [0.0.2-next.7](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.6...background-task-models-v0.0.2-next.7) (2025-08-29)
|
|
34
109
|
|
|
35
110
|
|
|
36
111
|
### Features
|
|
37
112
|
|
|
38
|
-
* eslint migration to flat config ([6c9136c](https://github.com/
|
|
113
|
+
* eslint migration to flat config ([6c9136c](https://github.com/iotaledger/twin-background-task/commit/6c9136c37bccdbbd109892d1503660aab7080d49))
|
|
39
114
|
|
|
40
|
-
## [0.0.2-next.6](https://github.com/
|
|
115
|
+
## [0.0.2-next.6](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.5...background-task-models-v0.0.2-next.6) (2025-08-22)
|
|
41
116
|
|
|
42
117
|
|
|
43
118
|
### Miscellaneous Chores
|
|
44
119
|
|
|
45
120
|
* **background-task-models:** Synchronize repo versions
|
|
46
121
|
|
|
47
|
-
## [0.0.2-next.5](https://github.com/
|
|
122
|
+
## [0.0.2-next.5](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.4...background-task-models-v0.0.2-next.5) (2025-08-20)
|
|
48
123
|
|
|
49
124
|
|
|
50
125
|
### Features
|
|
51
126
|
|
|
52
|
-
* update framework core ([a068098](https://github.com/
|
|
127
|
+
* update framework core ([a068098](https://github.com/iotaledger/twin-background-task/commit/a0680983d7923a1bfb980a67879019bb870ccc5d))
|
|
53
128
|
|
|
54
|
-
## [0.0.2-next.4](https://github.com/
|
|
129
|
+
## [0.0.2-next.4](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.3...background-task-models-v0.0.2-next.4) (2025-07-23)
|
|
55
130
|
|
|
56
131
|
|
|
57
132
|
### Miscellaneous Chores
|
|
58
133
|
|
|
59
134
|
* **background-task-models:** Synchronize repo versions
|
|
60
135
|
|
|
61
|
-
## [0.0.2-next.3](https://github.com/
|
|
136
|
+
## [0.0.2-next.3](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.2...background-task-models-v0.0.2-next.3) (2025-07-21)
|
|
62
137
|
|
|
63
138
|
|
|
64
139
|
### Miscellaneous Chores
|
|
65
140
|
|
|
66
141
|
* **background-task-models:** Synchronize repo versions
|
|
67
142
|
|
|
68
|
-
## [0.0.2-next.2](https://github.com/
|
|
143
|
+
## [0.0.2-next.2](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.1...background-task-models-v0.0.2-next.2) (2025-07-09)
|
|
69
144
|
|
|
70
145
|
|
|
71
146
|
### Features
|
|
72
147
|
|
|
73
|
-
* add task scheduler ([754d973](https://github.com/
|
|
74
|
-
* improve comment ([f2b4ac2](https://github.com/
|
|
75
|
-
* only run tasks from your own thread ([c7d305b](https://github.com/
|
|
76
|
-
* update dependencies ([8e65767](https://github.com/
|
|
77
|
-
* use shared store mechanism ([#6](https://github.com/
|
|
148
|
+
* add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
|
|
149
|
+
* improve comment ([f2b4ac2](https://github.com/iotaledger/twin-background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
|
|
150
|
+
* only run tasks from your own thread ([c7d305b](https://github.com/iotaledger/twin-background-task/commit/c7d305b9807e65b8b1af6d0c2ca59e74190cab69))
|
|
151
|
+
* update dependencies ([8e65767](https://github.com/iotaledger/twin-background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
|
|
152
|
+
* use shared store mechanism ([#6](https://github.com/iotaledger/twin-background-task/issues/6)) ([27ed203](https://github.com/iotaledger/twin-background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
|
|
78
153
|
|
|
79
|
-
## [0.0.2-next.1](https://github.com/
|
|
154
|
+
## [0.0.2-next.1](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.2-next.0...background-task-models-v0.0.2-next.1) (2025-07-09)
|
|
80
155
|
|
|
81
156
|
|
|
82
157
|
### Features
|
|
83
158
|
|
|
84
|
-
* add task scheduler ([754d973](https://github.com/
|
|
85
|
-
* improve comment ([f2b4ac2](https://github.com/
|
|
86
|
-
* only run tasks from your own thread ([c7d305b](https://github.com/
|
|
87
|
-
* update dependencies ([8e65767](https://github.com/
|
|
88
|
-
* use shared store mechanism ([#6](https://github.com/
|
|
159
|
+
* add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
|
|
160
|
+
* improve comment ([f2b4ac2](https://github.com/iotaledger/twin-background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
|
|
161
|
+
* only run tasks from your own thread ([c7d305b](https://github.com/iotaledger/twin-background-task/commit/c7d305b9807e65b8b1af6d0c2ca59e74190cab69))
|
|
162
|
+
* update dependencies ([8e65767](https://github.com/iotaledger/twin-background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
|
|
163
|
+
* use shared store mechanism ([#6](https://github.com/iotaledger/twin-background-task/issues/6)) ([27ed203](https://github.com/iotaledger/twin-background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
|
|
89
164
|
|
|
90
165
|
## 0.0.1 (2025-07-07)
|
|
91
166
|
|
|
92
167
|
|
|
93
168
|
### Features
|
|
94
169
|
|
|
95
|
-
* release to production ([7ce9896](https://github.com/
|
|
170
|
+
* release to production ([7ce9896](https://github.com/iotaledger/twin-background-task/commit/7ce989659e6819f05655c86b1bda2a265af5d281))
|
|
96
171
|
|
|
97
|
-
## [0.0.1-next.21](https://github.com/
|
|
172
|
+
## [0.0.1-next.21](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.20...background-task-models-v0.0.1-next.21) (2025-06-23)
|
|
98
173
|
|
|
99
174
|
|
|
100
175
|
### Miscellaneous Chores
|
|
101
176
|
|
|
102
177
|
* **background-task-models:** Synchronize repo versions
|
|
103
178
|
|
|
104
|
-
## [0.0.1-next.20](https://github.com/
|
|
179
|
+
## [0.0.1-next.20](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.19...background-task-models-v0.0.1-next.20) (2025-06-23)
|
|
105
180
|
|
|
106
181
|
|
|
107
182
|
### Features
|
|
108
183
|
|
|
109
|
-
* add task scheduler ([754d973](https://github.com/
|
|
110
|
-
* improve comment ([f2b4ac2](https://github.com/
|
|
111
|
-
* update dependencies ([8e65767](https://github.com/
|
|
112
|
-
* use shared store mechanism ([#6](https://github.com/
|
|
184
|
+
* add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
|
|
185
|
+
* improve comment ([f2b4ac2](https://github.com/iotaledger/twin-background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
|
|
186
|
+
* update dependencies ([8e65767](https://github.com/iotaledger/twin-background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
|
|
187
|
+
* use shared store mechanism ([#6](https://github.com/iotaledger/twin-background-task/issues/6)) ([27ed203](https://github.com/iotaledger/twin-background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
|
|
113
188
|
|
|
114
|
-
## [0.0.1-next.19](https://github.com/
|
|
189
|
+
## [0.0.1-next.19](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.18...background-task-models-v0.0.1-next.19) (2025-06-23)
|
|
115
190
|
|
|
116
191
|
|
|
117
192
|
### Features
|
|
118
193
|
|
|
119
|
-
* add task scheduler ([754d973](https://github.com/
|
|
194
|
+
* add task scheduler ([754d973](https://github.com/iotaledger/twin-background-task/commit/754d973e7c8483e5e54e887c157661867d5a0375))
|
|
120
195
|
|
|
121
|
-
## [0.0.1-next.18](https://github.com/
|
|
196
|
+
## [0.0.1-next.18](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.17...background-task-models-v0.0.1-next.18) (2025-06-19)
|
|
122
197
|
|
|
123
198
|
|
|
124
199
|
### Miscellaneous Chores
|
|
125
200
|
|
|
126
201
|
* **background-task-models:** Synchronize repo versions
|
|
127
202
|
|
|
128
|
-
## [0.0.1-next.17](https://github.com/
|
|
203
|
+
## [0.0.1-next.17](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.16...background-task-models-v0.0.1-next.17) (2025-06-12)
|
|
129
204
|
|
|
130
205
|
|
|
131
206
|
### Features
|
|
132
207
|
|
|
133
|
-
* update dependencies ([8e65767](https://github.com/
|
|
208
|
+
* update dependencies ([8e65767](https://github.com/iotaledger/twin-background-task/commit/8e657679f5e4305dbcb15ac7bcb3ab8a4613a60b))
|
|
134
209
|
|
|
135
|
-
## [0.0.1-next.16](https://github.com/
|
|
210
|
+
## [0.0.1-next.16](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.15...background-task-models-v0.0.1-next.16) (2025-06-05)
|
|
136
211
|
|
|
137
212
|
|
|
138
213
|
### Miscellaneous Chores
|
|
139
214
|
|
|
140
215
|
* **background-task-models:** Synchronize repo versions
|
|
141
216
|
|
|
142
|
-
## [0.0.1-next.15](https://github.com/
|
|
217
|
+
## [0.0.1-next.15](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.14...background-task-models-v0.0.1-next.15) (2025-04-17)
|
|
143
218
|
|
|
144
219
|
|
|
145
220
|
### Features
|
|
146
221
|
|
|
147
|
-
* use shared store mechanism ([#6](https://github.com/
|
|
222
|
+
* use shared store mechanism ([#6](https://github.com/iotaledger/twin-background-task/issues/6)) ([27ed203](https://github.com/iotaledger/twin-background-task/commit/27ed20367d5ace7257bfa7a82b59ad70e5b5d209))
|
|
148
223
|
|
|
149
|
-
## [0.0.1-next.14](https://github.com/
|
|
224
|
+
## [0.0.1-next.14](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.13...background-task-models-v0.0.1-next.14) (2025-04-11)
|
|
150
225
|
|
|
151
226
|
|
|
152
227
|
### Miscellaneous Chores
|
|
153
228
|
|
|
154
229
|
* **background-task-models:** Synchronize repo versions
|
|
155
230
|
|
|
156
|
-
## [0.0.1-next.13](https://github.com/
|
|
231
|
+
## [0.0.1-next.13](https://github.com/iotaledger/twin-background-task/compare/background-task-models-v0.0.1-next.12...background-task-models-v0.0.1-next.13) (2025-03-28)
|
|
157
232
|
|
|
158
233
|
|
|
159
234
|
### Features
|
|
160
235
|
|
|
161
|
-
* improve comment ([f2b4ac2](https://github.com/
|
|
236
|
+
* improve comment ([f2b4ac2](https://github.com/iotaledger/twin-background-task/commit/f2b4ac22fb8f735d2bf4ce28583cf7c54acdf272))
|
|
162
237
|
|
|
163
238
|
## v0.0.1-next.12
|
|
164
239
|
|
package/docs/examples.md
CHANGED
|
@@ -1 +1,179 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Background Task Models Examples
|
|
2
|
+
|
|
3
|
+
Use these snippets to model task payloads, status transitions and scheduler contracts in a strongly typed way.
|
|
4
|
+
|
|
5
|
+
## IBackgroundTask
|
|
6
|
+
|
|
7
|
+
```typescript
|
|
8
|
+
import type { IBackgroundTask } from '@twin.org/background-task-models';
|
|
9
|
+
import { TaskStatus } from '@twin.org/background-task-models';
|
|
10
|
+
|
|
11
|
+
type ImportPayload = {
|
|
12
|
+
source: string;
|
|
13
|
+
batchSize: number;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
type ImportResult = {
|
|
17
|
+
inserted: number;
|
|
18
|
+
skipped: number;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const queuedTask: IBackgroundTask<ImportPayload, ImportResult> = {
|
|
22
|
+
id: '7f4b2c18a4f44f1f9ff7348e260ca4c2',
|
|
23
|
+
type: 'catalogue-import',
|
|
24
|
+
threadId: '0',
|
|
25
|
+
dateCreated: '2026-03-09T10:30:00.000Z',
|
|
26
|
+
dateModified: '2026-03-09T10:30:00.000Z',
|
|
27
|
+
status: TaskStatus.Pending,
|
|
28
|
+
payload: {
|
|
29
|
+
source: 'tenant-a',
|
|
30
|
+
batchSize: 250
|
|
31
|
+
},
|
|
32
|
+
retriesRemaining: 3,
|
|
33
|
+
retryInterval: 5000
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
console.log(queuedTask.status); // pending
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```typescript
|
|
40
|
+
import type { IBackgroundTask } from '@twin.org/background-task-models';
|
|
41
|
+
import { TaskStatus } from '@twin.org/background-task-models';
|
|
42
|
+
|
|
43
|
+
type ImportResult = {
|
|
44
|
+
inserted: number;
|
|
45
|
+
skipped: number;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const completedTask: IBackgroundTask<unknown, ImportResult> = {
|
|
49
|
+
id: '7f4b2c18a4f44f1f9ff7348e260ca4c2',
|
|
50
|
+
type: 'catalogue-import',
|
|
51
|
+
threadId: '3',
|
|
52
|
+
dateCreated: '2026-03-09T10:30:00.000Z',
|
|
53
|
+
dateModified: '2026-03-09T10:31:22.000Z',
|
|
54
|
+
dateCompleted: '2026-03-09T10:31:22.000Z',
|
|
55
|
+
status: TaskStatus.Success,
|
|
56
|
+
result: {
|
|
57
|
+
inserted: 248,
|
|
58
|
+
skipped: 2
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
console.log(completedTask.result?.inserted); // 248
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## IBackgroundTaskComponent
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
import type { IBackgroundTask, IBackgroundTaskComponent } from '@twin.org/background-task-models';
|
|
69
|
+
import { TaskStatus } from '@twin.org/background-task-models';
|
|
70
|
+
|
|
71
|
+
type ResizePayload = {
|
|
72
|
+
imageId: string;
|
|
73
|
+
width: number;
|
|
74
|
+
height: number;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type ResizeResult = {
|
|
78
|
+
imageId: string;
|
|
79
|
+
location: string;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
export async function configureImageHandler(
|
|
83
|
+
taskComponent: IBackgroundTaskComponent
|
|
84
|
+
): Promise<void> {
|
|
85
|
+
await taskComponent.registerHandler<ResizePayload, ResizeResult>(
|
|
86
|
+
'image-resize',
|
|
87
|
+
'./workers/imageWorker',
|
|
88
|
+
'resize',
|
|
89
|
+
async (task: IBackgroundTask<ResizePayload, ResizeResult>) => {
|
|
90
|
+
if (task.status === TaskStatus.Success) {
|
|
91
|
+
console.log(task.result?.location); // s3://tenant-a/images/hero-1920x1080.webp
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
maxWorkerCount: 4,
|
|
96
|
+
idleShutdownTimeout: 60000,
|
|
97
|
+
initialiseMethod: 'initialise',
|
|
98
|
+
shutdownMethod: 'shutdown'
|
|
99
|
+
}
|
|
100
|
+
);
|
|
101
|
+
|
|
102
|
+
const taskId = await taskComponent.create<ResizePayload>(
|
|
103
|
+
'image-resize',
|
|
104
|
+
{
|
|
105
|
+
imageId: 'hero',
|
|
106
|
+
width: 1920,
|
|
107
|
+
height: 1080
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
retryCount: 2,
|
|
111
|
+
retryInterval: 3000,
|
|
112
|
+
retainFor: 120000
|
|
113
|
+
}
|
|
114
|
+
);
|
|
115
|
+
|
|
116
|
+
const task = await taskComponent.get<ResizePayload, ResizeResult>(taskId);
|
|
117
|
+
console.log(task?.status); // pending
|
|
118
|
+
}
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## ITaskSchedulerComponent
|
|
122
|
+
|
|
123
|
+
```typescript
|
|
124
|
+
import type { ITaskSchedulerComponent } from '@twin.org/background-task-models';
|
|
125
|
+
|
|
126
|
+
export async function registerDailySync(
|
|
127
|
+
scheduler: ITaskSchedulerComponent,
|
|
128
|
+
syncTaskId: string
|
|
129
|
+
): Promise<void> {
|
|
130
|
+
await scheduler.addTask(
|
|
131
|
+
syncTaskId,
|
|
132
|
+
[
|
|
133
|
+
{
|
|
134
|
+
nextTriggerTime: Date.now() + 15 * 60 * 1000,
|
|
135
|
+
intervalDays: 1
|
|
136
|
+
}
|
|
137
|
+
],
|
|
138
|
+
async () => {
|
|
139
|
+
console.log('sync running at', new Date().toISOString()); // sync running at 2026-03-09T10:45:00.000Z
|
|
140
|
+
}
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
const info = await scheduler.tasksInfo();
|
|
144
|
+
console.log(info.tasks[syncTaskId].length); // 1
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
## IScheduledTaskInfo and IScheduledTaskTime
|
|
149
|
+
|
|
150
|
+
```typescript
|
|
151
|
+
import type { IScheduledTaskInfo, IScheduledTaskTime } from '@twin.org/background-task-models';
|
|
152
|
+
|
|
153
|
+
const everyQuarterHour: IScheduledTaskTime = {
|
|
154
|
+
intervalMinutes: 15
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const schedule: IScheduledTaskInfo = {
|
|
158
|
+
tasks: {
|
|
159
|
+
'cleanup-cache': [everyQuarterHour]
|
|
160
|
+
}
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
console.log(schedule.tasks['cleanup-cache'][0].intervalMinutes); // 15
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
## TaskStatus
|
|
167
|
+
|
|
168
|
+
```typescript
|
|
169
|
+
import type { TaskStatus } from '@twin.org/background-task-models';
|
|
170
|
+
import { TaskStatus as TaskStatuses } from '@twin.org/background-task-models';
|
|
171
|
+
|
|
172
|
+
const terminalStatuses: TaskStatus[] = [
|
|
173
|
+
TaskStatuses.Success,
|
|
174
|
+
TaskStatuses.Failed,
|
|
175
|
+
TaskStatuses.Cancelled
|
|
176
|
+
];
|
|
177
|
+
|
|
178
|
+
console.log(terminalStatuses.join(', ')); // success, failed, cancelled
|
|
179
|
+
```
|
package/docs/reference/index.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
## Interfaces
|
|
4
4
|
|
|
5
5
|
- [IBackgroundTask](interfaces/IBackgroundTask.md)
|
|
6
|
-
- [
|
|
6
|
+
- [IBackgroundTaskComponent](interfaces/IBackgroundTaskComponent.md)
|
|
7
7
|
- [IScheduledTaskInfo](interfaces/IScheduledTaskInfo.md)
|
|
8
8
|
- [IScheduledTaskTime](interfaces/IScheduledTaskTime.md)
|
|
9
9
|
- [ITaskSchedulerComponent](interfaces/ITaskSchedulerComponent.md)
|
|
@@ -14,5 +14,4 @@
|
|
|
14
14
|
|
|
15
15
|
## Variables
|
|
16
16
|
|
|
17
|
-
- [BackgroundTaskConnectorFactory](variables/BackgroundTaskConnectorFactory.md)
|
|
18
17
|
- [TaskStatus](variables/TaskStatus.md)
|
|
@@ -14,7 +14,7 @@ Interface describing a background task.
|
|
|
14
14
|
|
|
15
15
|
## Properties
|
|
16
16
|
|
|
17
|
-
### id
|
|
17
|
+
### id {#id}
|
|
18
18
|
|
|
19
19
|
> **id**: `string`
|
|
20
20
|
|
|
@@ -22,7 +22,7 @@ The id.
|
|
|
22
22
|
|
|
23
23
|
***
|
|
24
24
|
|
|
25
|
-
### type
|
|
25
|
+
### type {#type}
|
|
26
26
|
|
|
27
27
|
> **type**: `string`
|
|
28
28
|
|
|
@@ -30,7 +30,7 @@ The type of the task.
|
|
|
30
30
|
|
|
31
31
|
***
|
|
32
32
|
|
|
33
|
-
### threadId
|
|
33
|
+
### threadId {#threadid}
|
|
34
34
|
|
|
35
35
|
> **threadId**: `string`
|
|
36
36
|
|
|
@@ -38,23 +38,23 @@ The thread id for the task.
|
|
|
38
38
|
|
|
39
39
|
***
|
|
40
40
|
|
|
41
|
-
### retryInterval?
|
|
41
|
+
### retryInterval? {#retryinterval}
|
|
42
42
|
|
|
43
|
-
> `optional` **retryInterval
|
|
43
|
+
> `optional` **retryInterval?**: `number`
|
|
44
44
|
|
|
45
45
|
The retry interval in milliseconds, undefined if default scheduling.
|
|
46
46
|
|
|
47
47
|
***
|
|
48
48
|
|
|
49
|
-
### retriesRemaining?
|
|
49
|
+
### retriesRemaining? {#retriesremaining}
|
|
50
50
|
|
|
51
|
-
> `optional` **retriesRemaining
|
|
51
|
+
> `optional` **retriesRemaining?**: `number`
|
|
52
52
|
|
|
53
53
|
The number of retries remaining, undefined if infinite retries.
|
|
54
54
|
|
|
55
55
|
***
|
|
56
56
|
|
|
57
|
-
### dateCreated
|
|
57
|
+
### dateCreated {#datecreated}
|
|
58
58
|
|
|
59
59
|
> **dateCreated**: `string`
|
|
60
60
|
|
|
@@ -62,7 +62,7 @@ The date the task was created.
|
|
|
62
62
|
|
|
63
63
|
***
|
|
64
64
|
|
|
65
|
-
### dateModified
|
|
65
|
+
### dateModified {#datemodified}
|
|
66
66
|
|
|
67
67
|
> **dateModified**: `string`
|
|
68
68
|
|
|
@@ -70,31 +70,31 @@ The date the task was last modified.
|
|
|
70
70
|
|
|
71
71
|
***
|
|
72
72
|
|
|
73
|
-
### dateCompleted?
|
|
73
|
+
### dateCompleted? {#datecompleted}
|
|
74
74
|
|
|
75
|
-
> `optional` **dateCompleted
|
|
75
|
+
> `optional` **dateCompleted?**: `string`
|
|
76
76
|
|
|
77
77
|
The date the task was complete.
|
|
78
78
|
|
|
79
79
|
***
|
|
80
80
|
|
|
81
|
-
### dateCancelled?
|
|
81
|
+
### dateCancelled? {#datecancelled}
|
|
82
82
|
|
|
83
|
-
> `optional` **dateCancelled
|
|
83
|
+
> `optional` **dateCancelled?**: `string`
|
|
84
84
|
|
|
85
85
|
The date the task was cancelled.
|
|
86
86
|
|
|
87
87
|
***
|
|
88
88
|
|
|
89
|
-
### dateRetainUntil?
|
|
89
|
+
### dateRetainUntil? {#dateretainuntil}
|
|
90
90
|
|
|
91
|
-
> `optional` **dateRetainUntil
|
|
91
|
+
> `optional` **dateRetainUntil?**: `string`
|
|
92
92
|
|
|
93
93
|
The date until when to retain.
|
|
94
94
|
|
|
95
95
|
***
|
|
96
96
|
|
|
97
|
-
### status
|
|
97
|
+
### status {#status}
|
|
98
98
|
|
|
99
99
|
> **status**: [`TaskStatus`](../type-aliases/TaskStatus.md)
|
|
100
100
|
|
|
@@ -102,24 +102,24 @@ The status of the task.
|
|
|
102
102
|
|
|
103
103
|
***
|
|
104
104
|
|
|
105
|
-
### payload?
|
|
105
|
+
### payload? {#payload}
|
|
106
106
|
|
|
107
|
-
> `optional` **payload
|
|
107
|
+
> `optional` **payload?**: `T`
|
|
108
108
|
|
|
109
109
|
The payload to execute the task with.
|
|
110
110
|
|
|
111
111
|
***
|
|
112
112
|
|
|
113
|
-
### result?
|
|
113
|
+
### result? {#result}
|
|
114
114
|
|
|
115
|
-
> `optional` **result
|
|
115
|
+
> `optional` **result?**: `U`
|
|
116
116
|
|
|
117
117
|
The result of the execution.
|
|
118
118
|
|
|
119
119
|
***
|
|
120
120
|
|
|
121
|
-
### error?
|
|
121
|
+
### error? {#error}
|
|
122
122
|
|
|
123
|
-
> `optional` **error
|
|
123
|
+
> `optional` **error?**: `IError`
|
|
124
124
|
|
|
125
125
|
The error at last execution.
|
package/docs/reference/interfaces/{IBackgroundTaskConnector.md → IBackgroundTaskComponent.md}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# Interface:
|
|
1
|
+
# Interface: IBackgroundTaskComponent
|
|
2
2
|
|
|
3
|
-
Interface describing a background task
|
|
3
|
+
Interface describing a background task component.
|
|
4
4
|
|
|
5
5
|
## Extends
|
|
6
6
|
|
|
@@ -8,9 +8,9 @@ Interface describing a background task connector.
|
|
|
8
8
|
|
|
9
9
|
## Methods
|
|
10
10
|
|
|
11
|
-
### registerHandler()
|
|
11
|
+
### registerHandler() {#registerhandler}
|
|
12
12
|
|
|
13
|
-
> **registerHandler**\<`T`, `U`\>(`taskType`, `module`, `method`, `stateChangeCallback?`): `Promise`\<`void`\>
|
|
13
|
+
> **registerHandler**\<`T`, `U`\>(`taskType`, `module`, `method`, `stateChangeCallback?`, `options?`): `Promise`\<`void`\>
|
|
14
14
|
|
|
15
15
|
Register a handler for a task.
|
|
16
16
|
|
|
@@ -50,6 +50,34 @@ The method in the module to execute.
|
|
|
50
50
|
|
|
51
51
|
The callback to execute when the task state is updated.
|
|
52
52
|
|
|
53
|
+
##### options?
|
|
54
|
+
|
|
55
|
+
Additional options for the task.
|
|
56
|
+
|
|
57
|
+
###### maxWorkerCount?
|
|
58
|
+
|
|
59
|
+
`number`
|
|
60
|
+
|
|
61
|
+
The maximum number of workers in the pool.
|
|
62
|
+
|
|
63
|
+
###### idleShutdownTimeout?
|
|
64
|
+
|
|
65
|
+
`number`
|
|
66
|
+
|
|
67
|
+
Terminate the worker after it has been idle for the specified timeout in milliseconds, defaults to 0 shutdown immediately, -1 to keep forever.
|
|
68
|
+
|
|
69
|
+
###### initialiseMethod?
|
|
70
|
+
|
|
71
|
+
`string`
|
|
72
|
+
|
|
73
|
+
The initialisation method to call on the module when a worker is started.
|
|
74
|
+
|
|
75
|
+
###### shutdownMethod?
|
|
76
|
+
|
|
77
|
+
`string`
|
|
78
|
+
|
|
79
|
+
The shutdown method to call on the module when a worker is stopped.
|
|
80
|
+
|
|
53
81
|
#### Returns
|
|
54
82
|
|
|
55
83
|
`Promise`\<`void`\>
|
|
@@ -58,7 +86,7 @@ Nothing.
|
|
|
58
86
|
|
|
59
87
|
***
|
|
60
88
|
|
|
61
|
-
### unregisterHandler()
|
|
89
|
+
### unregisterHandler() {#unregisterhandler}
|
|
62
90
|
|
|
63
91
|
> **unregisterHandler**(`taskType`): `Promise`\<`void`\>
|
|
64
92
|
|
|
@@ -80,9 +108,9 @@ Nothing.
|
|
|
80
108
|
|
|
81
109
|
***
|
|
82
110
|
|
|
83
|
-
### create()
|
|
111
|
+
### create() {#create}
|
|
84
112
|
|
|
85
|
-
> **create**\<`T`\>(`
|
|
113
|
+
> **create**\<`T`\>(`taskType`, `payload?`, `options?`): `Promise`\<`string`\>
|
|
86
114
|
|
|
87
115
|
Create a new task.
|
|
88
116
|
|
|
@@ -94,7 +122,7 @@ Create a new task.
|
|
|
94
122
|
|
|
95
123
|
#### Parameters
|
|
96
124
|
|
|
97
|
-
#####
|
|
125
|
+
##### taskType
|
|
98
126
|
|
|
99
127
|
`string`
|
|
100
128
|
|
|
@@ -136,7 +164,7 @@ The id of the created task.
|
|
|
136
164
|
|
|
137
165
|
***
|
|
138
166
|
|
|
139
|
-
### get()
|
|
167
|
+
### get() {#get}
|
|
140
168
|
|
|
141
169
|
> **get**\<`T`, `U`\>(`taskId`): `Promise`\<[`IBackgroundTask`](IBackgroundTask.md)\<`T`, `U`\> \| `undefined`\>
|
|
142
170
|
|
|
@@ -168,7 +196,7 @@ The details of the task.
|
|
|
168
196
|
|
|
169
197
|
***
|
|
170
198
|
|
|
171
|
-
### retry()
|
|
199
|
+
### retry() {#retry}
|
|
172
200
|
|
|
173
201
|
> **retry**(`taskId`): `Promise`\<`void`\>
|
|
174
202
|
|
|
@@ -190,7 +218,7 @@ Nothing.
|
|
|
190
218
|
|
|
191
219
|
***
|
|
192
220
|
|
|
193
|
-
### remove()
|
|
221
|
+
### remove() {#remove}
|
|
194
222
|
|
|
195
223
|
> **remove**(`taskId`): `Promise`\<`void`\>
|
|
196
224
|
|
|
@@ -212,7 +240,7 @@ Nothing.
|
|
|
212
240
|
|
|
213
241
|
***
|
|
214
242
|
|
|
215
|
-
### cancel()
|
|
243
|
+
### cancel() {#cancel}
|
|
216
244
|
|
|
217
245
|
> **cancel**(`taskId`): `Promise`\<`void`\>
|
|
218
246
|
|
|
@@ -234,7 +262,7 @@ Nothing.
|
|
|
234
262
|
|
|
235
263
|
***
|
|
236
264
|
|
|
237
|
-
### query()
|
|
265
|
+
### query() {#query}
|
|
238
266
|
|
|
239
267
|
> **query**(`taskType?`, `taskStatus?`, `sortProperty?`, `sortDirection?`, `cursor?`, `limit?`): `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)\<`any`, `any`\>[]; `cursor?`: `string`; \}\>
|
|
240
268
|
|
|
@@ -256,9 +284,9 @@ The status of the task to get.
|
|
|
256
284
|
|
|
257
285
|
##### sortProperty?
|
|
258
286
|
|
|
259
|
-
|
|
287
|
+
`"dateCreated"` \| `"dateModified"` \| `"dateCompleted"` \| `"status"`
|
|
260
288
|
|
|
261
|
-
|
|
289
|
+
The property to sort by, defaults to dateCreated.
|
|
262
290
|
|
|
263
291
|
##### sortDirection?
|
|
264
292
|
|
|
@@ -4,32 +4,32 @@ Interface describing a scheduled task time.
|
|
|
4
4
|
|
|
5
5
|
## Properties
|
|
6
6
|
|
|
7
|
-
### nextTriggerTime?
|
|
7
|
+
### nextTriggerTime? {#nexttriggertime}
|
|
8
8
|
|
|
9
|
-
> `optional` **nextTriggerTime
|
|
9
|
+
> `optional` **nextTriggerTime?**: `number`
|
|
10
10
|
|
|
11
11
|
The date/time to start the task, if not provided defaults to first interval from now.
|
|
12
12
|
|
|
13
13
|
***
|
|
14
14
|
|
|
15
|
-
### intervalDays?
|
|
15
|
+
### intervalDays? {#intervaldays}
|
|
16
16
|
|
|
17
|
-
> `optional` **intervalDays
|
|
17
|
+
> `optional` **intervalDays?**: `number`
|
|
18
18
|
|
|
19
19
|
The interval in days to repeat the task, if no intervals are set the task will not repeat.
|
|
20
20
|
|
|
21
21
|
***
|
|
22
22
|
|
|
23
|
-
### intervalHours?
|
|
23
|
+
### intervalHours? {#intervalhours}
|
|
24
24
|
|
|
25
|
-
> `optional` **intervalHours
|
|
25
|
+
> `optional` **intervalHours?**: `number`
|
|
26
26
|
|
|
27
27
|
The interval in hours to repeat the task, if no intervals are set the task will not repeat.
|
|
28
28
|
|
|
29
29
|
***
|
|
30
30
|
|
|
31
|
-
### intervalMinutes?
|
|
31
|
+
### intervalMinutes? {#intervalminutes}
|
|
32
32
|
|
|
33
|
-
> `optional` **intervalMinutes
|
|
33
|
+
> `optional` **intervalMinutes?**: `number`
|
|
34
34
|
|
|
35
35
|
The interval in minutes to repeat the task, if no intervals are set the task will not repeat.
|
|
@@ -8,7 +8,7 @@ Interface describing a task scheduler.
|
|
|
8
8
|
|
|
9
9
|
## Methods
|
|
10
10
|
|
|
11
|
-
### addTask()
|
|
11
|
+
### addTask() {#addtask}
|
|
12
12
|
|
|
13
13
|
> **addTask**(`taskId`, `times`, `taskCallback`): `Promise`\<`void`\>
|
|
14
14
|
|
|
@@ -42,7 +42,7 @@ Nothing.
|
|
|
42
42
|
|
|
43
43
|
***
|
|
44
44
|
|
|
45
|
-
### removeTask()
|
|
45
|
+
### removeTask() {#removetask}
|
|
46
46
|
|
|
47
47
|
> **removeTask**(`taskId`): `Promise`\<`void`\>
|
|
48
48
|
|
|
@@ -64,7 +64,7 @@ Nothing.
|
|
|
64
64
|
|
|
65
65
|
***
|
|
66
66
|
|
|
67
|
-
### tasksInfo()
|
|
67
|
+
### tasksInfo() {#tasksinfo}
|
|
68
68
|
|
|
69
69
|
> **tasksInfo**(): `Promise`\<[`IScheduledTaskInfo`](IScheduledTaskInfo.md)\>
|
|
70
70
|
|
|
@@ -6,31 +6,31 @@ Task statuses.
|
|
|
6
6
|
|
|
7
7
|
## Type Declaration
|
|
8
8
|
|
|
9
|
-
### Pending
|
|
9
|
+
### Pending {#pending}
|
|
10
10
|
|
|
11
11
|
> `readonly` **Pending**: `"pending"` = `"pending"`
|
|
12
12
|
|
|
13
13
|
Pending.
|
|
14
14
|
|
|
15
|
-
### Processing
|
|
15
|
+
### Processing {#processing}
|
|
16
16
|
|
|
17
17
|
> `readonly` **Processing**: `"processing"` = `"processing"`
|
|
18
18
|
|
|
19
19
|
Processing.
|
|
20
20
|
|
|
21
|
-
### Success
|
|
21
|
+
### Success {#success}
|
|
22
22
|
|
|
23
23
|
> `readonly` **Success**: `"success"` = `"success"`
|
|
24
24
|
|
|
25
25
|
Success.
|
|
26
26
|
|
|
27
|
-
### Failed
|
|
27
|
+
### Failed {#failed}
|
|
28
28
|
|
|
29
29
|
> `readonly` **Failed**: `"failed"` = `"failed"`
|
|
30
30
|
|
|
31
31
|
Failed.
|
|
32
32
|
|
|
33
|
-
### Cancelled
|
|
33
|
+
### Cancelled {#cancelled}
|
|
34
34
|
|
|
35
35
|
> `readonly` **Cancelled**: `"cancelled"` = `"cancelled"`
|
|
36
36
|
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@twin.org/background-task-models",
|
|
3
|
-
"version": "0.0.3-next.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.0.3-next.10",
|
|
4
|
+
"description": "Defines shared contracts and status models for background task workflows",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
|
-
"url": "git+https://github.com/
|
|
7
|
+
"url": "git+https://github.com/iotaledger/twin-background-task.git",
|
|
8
8
|
"directory": "packages/background-task-models"
|
|
9
9
|
},
|
|
10
10
|
"author": "martyn.janes@iota.org",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"schemas"
|
|
51
51
|
],
|
|
52
52
|
"bugs": {
|
|
53
|
-
"url": "git+https://github.com/
|
|
53
|
+
"url": "git+https://github.com/iotaledger/twin-background-task/issues"
|
|
54
54
|
},
|
|
55
55
|
"homepage": "https://twindev.org"
|
|
56
56
|
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
// Copyright 2024 IOTA Stiftung.
|
|
2
|
-
// SPDX-License-Identifier: Apache-2.0.
|
|
3
|
-
import { Factory } from "@twin.org/core";
|
|
4
|
-
/**
|
|
5
|
-
* Factory for creating background task connectors.
|
|
6
|
-
*/
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
8
|
-
export const BackgroundTaskConnectorFactory = Factory.createFactory("background-task");
|
|
9
|
-
//# sourceMappingURL=backgroundTaskConnectorFactory.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"backgroundTaskConnectorFactory.js","sourceRoot":"","sources":["../../../src/factories/backgroundTaskConnectorFactory.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,OAAO,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAGzC;;GAEG;AACH,gEAAgE;AAChE,MAAM,CAAC,MAAM,8BAA8B,GAC1C,OAAO,CAAC,aAAa,CAA2B,iBAAiB,CAAC,CAAC","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport { Factory } from \"@twin.org/core\";\nimport type { IBackgroundTaskConnector } from \"../models/IBackgroundTaskConnector.js\";\n\n/**\n * Factory for creating background task connectors.\n */\n// eslint-disable-next-line @typescript-eslint/naming-convention\nexport const BackgroundTaskConnectorFactory =\n\tFactory.createFactory<IBackgroundTaskConnector>(\"background-task\");\n"]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IBackgroundTaskConnector.js","sourceRoot":"","sources":["../../../src/models/IBackgroundTaskConnector.ts"],"names":[],"mappings":"","sourcesContent":["// Copyright 2024 IOTA Stiftung.\n// SPDX-License-Identifier: Apache-2.0.\nimport type { IComponent } from \"@twin.org/core\";\nimport type { SortDirection } from \"@twin.org/entity\";\nimport type { IBackgroundTask } from \"./IBackgroundTask.js\";\nimport type { TaskStatus } from \"./taskStatus.js\";\n\n/**\n * Interface describing a background task connector.\n */\nexport interface IBackgroundTaskConnector extends IComponent {\n\t/**\n\t * Register a handler for a task.\n\t * @param taskType The type of the task the handler can process.\n\t * @param module The module the handler is in.\n\t * @param method The method in the module to execute.\n\t * @param stateChangeCallback The callback to execute when the task state is updated.\n\t * @returns Nothing.\n\t */\n\tregisterHandler<T, U>(\n\t\ttaskType: string,\n\t\tmodule: string,\n\t\tmethod: string,\n\t\tstateChangeCallback?: (task: IBackgroundTask<T, U>) => Promise<void>\n\t): Promise<void>;\n\n\t/**\n\t * Unregister a handler for a task.\n\t * @param taskType The type of the task handler to remove.\n\t * @returns Nothing.\n\t */\n\tunregisterHandler(taskType: string): Promise<void>;\n\n\t/**\n\t * Create a new task.\n\t * @param type The type of the task.\n\t * @param payload The payload for the task.\n\t * @param options Additional options for the task.\n\t * @param options.retryCount The number of times to retry the task if it fails, leave undefined to retry forever.\n\t * @param options.retryInterval The interval in milliseconds to wait between retries, defaults to 5000, leave undefined for default scheduling.\n\t * @param options.retainFor The amount of time in milliseconds to retain the result until removal, defaults to 0 for immediate removal, set to -1 to keep forever.\n\t * @returns The id of the created task.\n\t */\n\tcreate<T>(\n\t\ttype: string,\n\t\tpayload?: T,\n\t\toptions?: {\n\t\t\tretryCount?: number;\n\t\t\tretryInterval?: number;\n\t\t\tretainFor?: number;\n\t\t}\n\t): Promise<string>;\n\n\t/**\n\t * Get the task details.\n\t * @param taskId The id of the task to get the details for.\n\t * @returns The details of the task.\n\t */\n\tget<T, U>(taskId: string): Promise<IBackgroundTask<T, U> | undefined>;\n\n\t/**\n\t * Retry a failed task immediately instead of waiting for it's next scheduled retry time.\n\t * @param taskId The id of the task to retry.\n\t * @returns Nothing.\n\t */\n\tretry(taskId: string): Promise<void>;\n\n\t/**\n\t * Remove a task ignoring any retain until date.\n\t * @param taskId The id of the task to remove.\n\t * @returns Nothing.\n\t */\n\tremove(taskId: string): Promise<void>;\n\n\t/**\n\t * Cancel a task, will only be actioned if the task is currently pending.\n\t * @param taskId The id of the task to cancel.\n\t * @returns Nothing.\n\t */\n\tcancel(taskId: string): Promise<void>;\n\n\t/**\n\t * Get a list of tasks.\n\t * @param taskType The type of the task to get.\n\t * @param taskStatus The status of the task to get.\n\t * @param sortProperty The property to sort by, defaults to dateCreated.\n\t * @param sortDirection The order to sort by, defaults to ascending.\n\t * @param cursor The cursor to get the next page of tasks.\n\t * @param limit Limit the number of entities to return.\n\t * @returns The list of tasks.\n\t */\n\tquery(\n\t\ttaskType?: string,\n\t\ttaskStatus?: TaskStatus,\n\t\tsortProperty?: \"dateCreated\" | \"dateModified\" | \"dateCompleted\" | \"status\",\n\t\tsortDirection?: SortDirection,\n\t\tcursor?: string,\n\t\tlimit?: number\n\t): Promise<{\n\t\tentities: IBackgroundTask[];\n\t\tcursor?: string;\n\t}>;\n}\n"]}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { Factory } from "@twin.org/core";
|
|
2
|
-
import type { IBackgroundTaskConnector } from "../models/IBackgroundTaskConnector.js";
|
|
3
|
-
/**
|
|
4
|
-
* Factory for creating background task connectors.
|
|
5
|
-
*/
|
|
6
|
-
export declare const BackgroundTaskConnectorFactory: Factory<IBackgroundTaskConnector>;
|