@twin.org/background-task-models 0.0.1-next.1 → 0.0.1-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.
@@ -1,5 +1,4 @@
1
1
  export * from "./factories/backgroundTaskConnectorFactory";
2
- export * from "./models/backgroundTaskHandler";
3
2
  export * from "./models/IBackgroundTask";
4
3
  export * from "./models/IBackgroundTaskConnector";
5
4
  export * from "./models/taskStatus";
@@ -1,6 +1,5 @@
1
1
  import type { IComponent } from "@twin.org/core";
2
2
  import type { SortDirection } from "@twin.org/entity";
3
- import type { BackgroundTaskHandler } from "./backgroundTaskHandler";
4
3
  import type { IBackgroundTask } from "./IBackgroundTask";
5
4
  import type { TaskStatus } from "./taskStatus";
6
5
  /**
@@ -10,10 +9,12 @@ export interface IBackgroundTaskConnector extends IComponent {
10
9
  /**
11
10
  * Register a handler for a task.
12
11
  * @param taskType The type of the task the handler can process.
13
- * @param handler The handler for the task.
12
+ * @param module The module the handler is in.
13
+ * @param method The method in the module to execute.
14
+ * @param stateChangeCallback The callback to execute when the task state is updated.
14
15
  * @returns Nothing.
15
16
  */
16
- registerHandler<T, U>(taskType: string, handler: BackgroundTaskHandler<T, U>): Promise<void>;
17
+ registerHandler<T, U>(taskType: string, module: string, method: string, stateChangeCallback?: (task: IBackgroundTask<T, U>) => Promise<void>): Promise<void>;
17
18
  /**
18
19
  * Unregister a handler for a task.
19
20
  * @param taskType The type of the task handler to remove.
package/docs/changelog.md CHANGED
@@ -1,5 +1,5 @@
1
1
  # @twin.org/background-task-models - Changelog
2
2
 
3
- ## v0.0.1-next.1
3
+ ## v0.0.1-next.10
4
4
 
5
5
  - Initial Release
@@ -7,7 +7,6 @@
7
7
 
8
8
  ## Type Aliases
9
9
 
10
- - [BackgroundTaskHandler](type-aliases/BackgroundTaskHandler.md)
11
10
  - [TaskStatus](type-aliases/TaskStatus.md)
12
11
 
13
12
  ## Variables
@@ -10,7 +10,7 @@ Interface describing a background task connector.
10
10
 
11
11
  ### registerHandler()
12
12
 
13
- > **registerHandler**\<`T`, `U`\>(`taskType`, `handler`): `Promise`\<`void`\>
13
+ > **registerHandler**\<`T`, `U`\>(`taskType`, `module`, `method`, `stateChangeCallback`?): `Promise`\<`void`\>
14
14
 
15
15
  Register a handler for a task.
16
16
 
@@ -22,13 +22,29 @@ Register a handler for a task.
22
22
 
23
23
  #### Parameters
24
24
 
25
- **taskType**: `string`
25
+ ##### taskType
26
+
27
+ `string`
26
28
 
27
29
  The type of the task the handler can process.
28
30
 
29
- **handler**: [`BackgroundTaskHandler`](../type-aliases/BackgroundTaskHandler.md)\<`T`, `U`\>
31
+ ##### module
32
+
33
+ `string`
34
+
35
+ The module the handler is in.
36
+
37
+ ##### method
38
+
39
+ `string`
40
+
41
+ The method in the module to execute.
42
+
43
+ ##### stateChangeCallback?
44
+
45
+ (`task`) => `Promise`\<`void`\>
30
46
 
31
- The handler for the task.
47
+ The callback to execute when the task state is updated.
32
48
 
33
49
  #### Returns
34
50
 
@@ -46,7 +62,9 @@ Unregister a handler for a task.
46
62
 
47
63
  #### Parameters
48
64
 
49
- **taskType**: `string`
65
+ ##### taskType
66
+
67
+ `string`
50
68
 
51
69
  The type of the task handler to remove.
52
70
 
@@ -70,27 +88,37 @@ Create a new task.
70
88
 
71
89
  #### Parameters
72
90
 
73
- **type**: `string`
91
+ ##### type
92
+
93
+ `string`
74
94
 
75
95
  The type of the task.
76
96
 
77
- **payload?**: `T`
97
+ ##### payload?
98
+
99
+ `T`
78
100
 
79
101
  The payload for the task.
80
102
 
81
- **options?**
103
+ ##### options?
82
104
 
83
105
  Additional options for the task.
84
106
 
85
- **options.retryCount?**: `number`
107
+ ###### retryCount
108
+
109
+ `number`
86
110
 
87
111
  The number of times to retry the task if it fails, leave undefined to retry forever.
88
112
 
89
- **options.retryInterval?**: `number`
113
+ ###### retryInterval
114
+
115
+ `number`
90
116
 
91
117
  The interval in milliseconds to wait between retries, defaults to 5000, leave undefined for default scheduling.
92
118
 
93
- **options.retainFor?**: `number`
119
+ ###### retainFor
120
+
121
+ `number`
94
122
 
95
123
  The amount of time in milliseconds to retain the result until removal, defaults to 0 for immediate removal, set to -1 to keep forever.
96
124
 
@@ -116,7 +144,9 @@ Get the task details.
116
144
 
117
145
  #### Parameters
118
146
 
119
- **taskId**: `string`
147
+ ##### taskId
148
+
149
+ `string`
120
150
 
121
151
  The id of the task to get the details for.
122
152
 
@@ -136,7 +166,9 @@ Retry a failed task immediately instead of waiting for it's next scheduled retry
136
166
 
137
167
  #### Parameters
138
168
 
139
- **taskId**: `string`
169
+ ##### taskId
170
+
171
+ `string`
140
172
 
141
173
  The id of the task to retry.
142
174
 
@@ -156,7 +188,9 @@ Remove a task ignoring any retain until date.
156
188
 
157
189
  #### Parameters
158
190
 
159
- **taskId**: `string`
191
+ ##### taskId
192
+
193
+ `string`
160
194
 
161
195
  The id of the task to remove.
162
196
 
@@ -176,7 +210,9 @@ Cancel a task, will only be actioned if the task is currently pending.
176
210
 
177
211
  #### Parameters
178
212
 
179
- **taskId**: `string`
213
+ ##### taskId
214
+
215
+ `string`
180
216
 
181
217
  The id of the task to cancel.
182
218
 
@@ -190,46 +226,50 @@ Nothing.
190
226
 
191
227
  ### query()
192
228
 
193
- > **query**(`taskType`?, `taskStatus`?, `sortProperty`?, `sortDirection`?, `cursor`?, `pageSize`?): `Promise`\<`object`\>
229
+ > **query**(`taskType`?, `taskStatus`?, `sortProperty`?, `sortDirection`?, `cursor`?, `pageSize`?): `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)[]; `cursor`: `string`; \}\>
194
230
 
195
231
  Get a list of tasks.
196
232
 
197
233
  #### Parameters
198
234
 
199
- **taskType?**: `string`
235
+ ##### taskType?
236
+
237
+ `string`
200
238
 
201
239
  The type of the task to get.
202
240
 
203
- **taskStatus?**: [`TaskStatus`](../type-aliases/TaskStatus.md)
241
+ ##### taskStatus?
242
+
243
+ [`TaskStatus`](../type-aliases/TaskStatus.md)
204
244
 
205
245
  The status of the task to get.
206
246
 
207
- **sortProperty?**: `"status"` \| `"dateCreated"` \| `"dateModified"` \| `"dateCompleted"`
247
+ ##### sortProperty?
208
248
 
209
249
  The property to sort by, defaults to dateCreated.
210
250
 
211
- **sortDirection?**: `SortDirection`
251
+ `"status"` | `"dateCreated"` | `"dateModified"` | `"dateCompleted"`
252
+
253
+ ##### sortDirection?
254
+
255
+ `SortDirection`
212
256
 
213
257
  The order to sort by, defaults to ascending.
214
258
 
215
- **cursor?**: `string`
259
+ ##### cursor?
260
+
261
+ `string`
216
262
 
217
263
  The cursor to get the next page of tasks.
218
264
 
219
- **pageSize?**: `number`
265
+ ##### pageSize?
266
+
267
+ `number`
220
268
 
221
269
  The maximum number of entities in a page.
222
270
 
223
271
  #### Returns
224
272
 
225
- `Promise`\<`object`\>
273
+ `Promise`\<\{ `entities`: [`IBackgroundTask`](IBackgroundTask.md)[]; `cursor`: `string`; \}\>
226
274
 
227
275
  The list of tasks.
228
-
229
- ##### entities
230
-
231
- > **entities**: [`IBackgroundTask`](IBackgroundTask.md)\<`any`, `any`\>[]
232
-
233
- ##### cursor?
234
-
235
- > `optional` **cursor**: `string`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@twin.org/background-task-models",
3
- "version": "0.0.1-next.1",
3
+ "version": "0.0.1-next.10",
4
4
  "description": "Models which define the structure of the background task contracts and connectors",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,11 +23,11 @@
23
23
  "types": "./dist/types/index.d.ts",
24
24
  "exports": {
25
25
  ".": {
26
+ "types": "./dist/types/index.d.ts",
26
27
  "require": "./dist/cjs/index.cjs",
27
- "import": "./dist/esm/index.mjs",
28
- "types": "./dist/types/index.d.ts"
28
+ "import": "./dist/esm/index.mjs"
29
29
  },
30
- "./locales": "./locales"
30
+ "./locales/*.json": "./locales/*.json"
31
31
  },
32
32
  "files": [
33
33
  "dist/cjs",
@@ -1,8 +0,0 @@
1
- import type { IError } from "@twin.org/core";
2
- /**
3
- * Interface describing a task handler.
4
- */
5
- export type BackgroundTaskHandler<T = any, U = any> = (payload: T) => Promise<{
6
- result?: U;
7
- error?: IError;
8
- }>;
@@ -1,27 +0,0 @@
1
- # Type Alias: BackgroundTaskHandler()\<T, U\>
2
-
3
- > **BackgroundTaskHandler**\<`T`, `U`\>: (`payload`) => `Promise`\<`object`\>
4
-
5
- Interface describing a task handler.
6
-
7
- ## Type Parameters
8
-
9
- • **T** = `any`
10
-
11
- • **U** = `any`
12
-
13
- ## Parameters
14
-
15
- • **payload**: `T`
16
-
17
- ## Returns
18
-
19
- `Promise`\<`object`\>
20
-
21
- ### result?
22
-
23
- > `optional` **result**: `U`
24
-
25
- ### error?
26
-
27
- > `optional` **error**: `IError`