@live-change/task-service 0.8.145 → 0.8.147
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/package.json +4 -4
- package/task.ts +75 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@live-change/task-service",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.147",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
},
|
|
23
23
|
"type": "module",
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@live-change/framework": "^0.8.
|
|
26
|
-
"@live-change/relations-plugin": "^0.8.
|
|
25
|
+
"@live-change/framework": "^0.8.147",
|
|
26
|
+
"@live-change/relations-plugin": "^0.8.147"
|
|
27
27
|
},
|
|
28
|
-
"gitHead": "
|
|
28
|
+
"gitHead": "2bfde1b464cba759052a10453b004be386922177"
|
|
29
29
|
}
|
package/task.ts
CHANGED
|
@@ -115,6 +115,16 @@ interface TaskDefinition {
|
|
|
115
115
|
*/
|
|
116
116
|
maxRetries?: number,
|
|
117
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Task properties/parameters schema
|
|
120
|
+
*/
|
|
121
|
+
properties?: Object,
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Task returns schema
|
|
125
|
+
*/
|
|
126
|
+
returns?: Object,
|
|
127
|
+
|
|
118
128
|
/**
|
|
119
129
|
* Task execution function
|
|
120
130
|
* @param props - task properties/parameters
|
|
@@ -140,6 +150,31 @@ interface TaskDefinition {
|
|
|
140
150
|
* @returns {Promise<any>} - fallback result
|
|
141
151
|
*/
|
|
142
152
|
fallback?: (props, context: TaskExecuteContext, error) => any
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* create trigger for task, trigger will return object with task property
|
|
156
|
+
* @param trigger - true, or trigger name
|
|
157
|
+
*/
|
|
158
|
+
trigger?: string | true
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* create action for task, action will return object with task property,
|
|
162
|
+
* @param action - true, or action name
|
|
163
|
+
*/
|
|
164
|
+
action?: string | true
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* check if action is accessible for certain user
|
|
168
|
+
* @param props
|
|
169
|
+
* @param context
|
|
170
|
+
*/
|
|
171
|
+
actionAccess?: (props, context) => boolean
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* action access control settings
|
|
175
|
+
*/
|
|
176
|
+
actionAccessControl?: Object
|
|
177
|
+
|
|
143
178
|
}
|
|
144
179
|
|
|
145
180
|
type TaskFunction = (props, context: TaskExecuteContext, emit, reportProgress) => Promise<any>
|
|
@@ -364,6 +399,46 @@ export default function task(definition:TaskDefinition, serviceDefinition) {
|
|
|
364
399
|
}, 500)
|
|
365
400
|
})
|
|
366
401
|
|
|
402
|
+
const Task = serviceDefinition.foreignModel('task', 'Task')
|
|
403
|
+
|
|
404
|
+
if(definition.trigger) {
|
|
405
|
+
serviceDefinition.trigger({
|
|
406
|
+
name: definition.trigger === true ? definition.name : definition.trigger,
|
|
407
|
+
properties: definition.properties,
|
|
408
|
+
returnsTask: true,
|
|
409
|
+
returns: {
|
|
410
|
+
type: Task
|
|
411
|
+
},
|
|
412
|
+
async execute(props, context, emit) {
|
|
413
|
+
const startResult =
|
|
414
|
+
await startTask(taskFunction, props, 'trigger', context.id)
|
|
415
|
+
return {
|
|
416
|
+
task: startResult.task
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
})
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
if(definition.action) {
|
|
423
|
+
serviceDefinition.action({
|
|
424
|
+
name: definition.action === true ? definition.name : definition.action,
|
|
425
|
+
properties: definition.properties,
|
|
426
|
+
returnsTask: true,
|
|
427
|
+
access: definition.actionAccess,
|
|
428
|
+
accessControl: definition.actionAccessControl,
|
|
429
|
+
returns: {
|
|
430
|
+
type: Task
|
|
431
|
+
},
|
|
432
|
+
async execute(props, context, emit) {
|
|
433
|
+
const startResult =
|
|
434
|
+
await startTask(taskFunction, { ...props, client: context.client }, 'command', context.id)
|
|
435
|
+
return {
|
|
436
|
+
task: startResult.task
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
})
|
|
440
|
+
}
|
|
441
|
+
|
|
367
442
|
taskFunction.definition = definition
|
|
368
443
|
taskFunction.start = async (props, causeType, cause) => {
|
|
369
444
|
return await startTask(taskFunction, props, causeType, cause)
|