@twin.org/background-task-models 0.0.1-next.1 → 0.0.1-next.11
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/dist/types/index.d.ts +0 -1
- package/dist/types/models/IBackgroundTaskConnector.d.ts +4 -3
- package/docs/changelog.md +1 -1
- package/docs/reference/index.md +0 -1
- package/docs/reference/interfaces/IBackgroundTaskConnector.md +71 -31
- package/package.json +4 -4
- package/dist/types/models/backgroundTaskHandler.d.ts +0 -8
- package/docs/reference/type-aliases/BackgroundTaskHandler.md +0 -27
package/dist/types/index.d.ts
CHANGED
|
@@ -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
|
|
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,
|
|
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
package/docs/reference/index.md
CHANGED
|
@@ -10,7 +10,7 @@ Interface describing a background task connector.
|
|
|
10
10
|
|
|
11
11
|
### registerHandler()
|
|
12
12
|
|
|
13
|
-
> **registerHandler**\<`T`, `U`\>(`taskType`, `
|
|
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
|
-
|
|
25
|
+
##### taskType
|
|
26
|
+
|
|
27
|
+
`string`
|
|
26
28
|
|
|
27
29
|
The type of the task the handler can process.
|
|
28
30
|
|
|
29
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
91
|
+
##### type
|
|
92
|
+
|
|
93
|
+
`string`
|
|
74
94
|
|
|
75
95
|
The type of the task.
|
|
76
96
|
|
|
77
|
-
|
|
97
|
+
##### payload?
|
|
98
|
+
|
|
99
|
+
`T`
|
|
78
100
|
|
|
79
101
|
The payload for the task.
|
|
80
102
|
|
|
81
|
-
|
|
103
|
+
##### options?
|
|
82
104
|
|
|
83
105
|
Additional options for the task.
|
|
84
106
|
|
|
85
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
235
|
+
##### taskType?
|
|
236
|
+
|
|
237
|
+
`string`
|
|
200
238
|
|
|
201
239
|
The type of the task to get.
|
|
202
240
|
|
|
203
|
-
|
|
241
|
+
##### taskStatus?
|
|
242
|
+
|
|
243
|
+
[`TaskStatus`](../type-aliases/TaskStatus.md)
|
|
204
244
|
|
|
205
245
|
The status of the task to get.
|
|
206
246
|
|
|
207
|
-
|
|
247
|
+
##### sortProperty?
|
|
208
248
|
|
|
209
249
|
The property to sort by, defaults to dateCreated.
|
|
210
250
|
|
|
211
|
-
|
|
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
|
-
|
|
259
|
+
##### cursor?
|
|
260
|
+
|
|
261
|
+
`string`
|
|
216
262
|
|
|
217
263
|
The cursor to get the next page of tasks.
|
|
218
264
|
|
|
219
|
-
|
|
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
|
|
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.
|
|
3
|
+
"version": "0.0.1-next.11",
|
|
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,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`
|