@twin.org/background-task-models 0.0.3-next.1 → 0.0.3-next.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # TWIN Background Task Models
2
2
 
3
- Models which define the structure of the background task contracts and connectors.
3
+ Models which define the structure of the background task contracts.
4
4
 
5
5
  ## Installation
6
6
 
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/IBackgroundTaskConnector.js";
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";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,uCAAuC;AACvC,cAAc,+CAA+C,CAAC;AAC9D,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 \"./factories/backgroundTaskConnectorFactory.js\";\nexport * from \"./models/IBackgroundTask.js\";\nexport * from \"./models/IBackgroundTaskConnector.js\";\nexport * from \"./models/IScheduledTaskInfo.js\";\nexport * from \"./models/IScheduledTaskTime.js\";\nexport * from \"./models/ITaskSchedulerComponent.js\";\nexport * from \"./models/taskStatus.js\";\n"]}
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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=IBackgroundTaskComponent.js.map
@@ -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"]}
@@ -1,6 +1,5 @@
1
- export * from "./factories/backgroundTaskConnectorFactory.js";
2
1
  export * from "./models/IBackgroundTask.js";
3
- export * from "./models/IBackgroundTaskConnector.js";
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 connector.
6
+ * Interface describing a background task component.
7
7
  */
8
- export interface IBackgroundTaskConnector extends IComponent {
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>): 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 type The type of the task.
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>(type: string, payload?: T, options?: {
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,5 +1,19 @@
1
1
  # @twin.org/background-task-models - Changelog
2
2
 
3
+ ## [0.0.3-next.3](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.3-next.2...background-task-models-v0.0.3-next.3) (2026-01-07)
4
+
5
+
6
+ ### Miscellaneous Chores
7
+
8
+ * **background-task-models:** Synchronize repo versions
9
+
10
+ ## [0.0.3-next.2](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.3-next.1...background-task-models-v0.0.3-next.2) (2025-11-28)
11
+
12
+
13
+ ### Features
14
+
15
+ * add multi-threading ([#32](https://github.com/twinfoundation/background-task/issues/32)) ([60fb5ef](https://github.com/twinfoundation/background-task/commit/60fb5ef55d3f7dc46a27c38d4497812d80b98e3b))
16
+
3
17
  ## [0.0.3-next.1](https://github.com/twinfoundation/background-task/compare/background-task-models-v0.0.3-next.0...background-task-models-v0.0.3-next.1) (2025-11-11)
4
18
 
5
19
 
@@ -3,7 +3,7 @@
3
3
  ## Interfaces
4
4
 
5
5
  - [IBackgroundTask](interfaces/IBackgroundTask.md)
6
- - [IBackgroundTaskConnector](interfaces/IBackgroundTaskConnector.md)
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)
@@ -1,6 +1,6 @@
1
- # Interface: IBackgroundTaskConnector
1
+ # Interface: IBackgroundTaskComponent
2
2
 
3
- Interface describing a background task connector.
3
+ Interface describing a background task component.
4
4
 
5
5
  ## Extends
6
6
 
@@ -10,7 +10,7 @@ Interface describing a background task connector.
10
10
 
11
11
  ### 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`\>
@@ -82,7 +110,7 @@ Nothing.
82
110
 
83
111
  ### create()
84
112
 
85
- > **create**\<`T`\>(`type`, `payload?`, `options?`): `Promise`\<`string`\>
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
- ##### type
125
+ ##### taskType
98
126
 
99
127
  `string`
100
128
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@twin.org/background-task-models",
3
- "version": "0.0.3-next.1",
4
- "description": "Models which define the structure of the background task contracts and connectors",
3
+ "version": "0.0.3-next.3",
4
+ "description": "Models which define the structure of the background task contracts",
5
5
  "repository": {
6
6
  "type": "git",
7
7
  "url": "git+https://github.com/twinfoundation/background-task.git",
@@ -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,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=IBackgroundTaskConnector.js.map
@@ -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>;
@@ -1,5 +0,0 @@
1
- # Variable: BackgroundTaskConnectorFactory
2
-
3
- > `const` **BackgroundTaskConnectorFactory**: `Factory`\<[`IBackgroundTaskConnector`](../interfaces/IBackgroundTaskConnector.md)\>
4
-
5
- Factory for creating background task connectors.