@live-change/task-service 0.9.104 → 0.9.106

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.
Files changed (2) hide show
  1. package/package.json +4 -4
  2. package/task.ts +44 -33
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@live-change/task-service",
3
- "version": "0.9.104",
3
+ "version": "0.9.106",
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.9.104",
26
- "@live-change/relations-plugin": "^0.9.104"
25
+ "@live-change/framework": "^0.9.106",
26
+ "@live-change/relations-plugin": "^0.9.106"
27
27
  },
28
- "gitHead": "6ee5d4a7d713cf488c79584381cb42adeb235c6d"
28
+ "gitHead": "1afc853b9044a57046dae972df68d89c8c1cd1a6"
29
29
  }
package/task.ts CHANGED
@@ -270,28 +270,35 @@ export default function task(definition:TaskDefinition, serviceDefinition) {
270
270
  //console.log("SUBTASK RUN", taskFunction.definition.name, props)
271
271
  const subtaskProgress = { current: 0, total: 1, factor: progressFactor }
272
272
  subtasksProgress.push(subtaskProgress)
273
- const result = await taskFunction(
274
- props,
275
- {
276
- ...context,
277
- taskObject: undefined,
278
- task: taskObject.id,
279
- causeType: 'task_Task',
280
- cause: taskObject.id,
281
- expire
282
- },
283
- (events) => app.emitEvents(serviceDefinition.name,
284
- Array.isArray(events) ? events : [events], {}),
285
- (current, total, action) => {
286
- subtaskProgress.current = current
287
- subtaskProgress.total = total
288
- updateProgress()
289
- }
290
- )
291
- //console.log("SUBTASK DONE", taskFunction.definition.name, props, '=>', result)
292
- subtaskProgress.current = subtaskProgress.total
293
- updateProgress()
294
- return result
273
+ try {
274
+ const result = await taskFunction(
275
+ props,
276
+ {
277
+ ...context,
278
+ taskObject: undefined,
279
+ causeType: 'task_Task',
280
+ cause: taskObject.id,
281
+ expire
282
+ },
283
+ (events) => app.emitEvents(serviceDefinition.name,
284
+ Array.isArray(events) ? events : [events], {}),
285
+ (current, total, action) => {
286
+ subtaskProgress.current = current
287
+ subtaskProgress.total = total
288
+ updateProgress()
289
+ }
290
+ )
291
+ //console.log("SUBTASK DONE", taskFunction.definition.name, props, '=>', result)
292
+ subtaskProgress.current = subtaskProgress.total
293
+ updateProgress()
294
+ return result
295
+ } catch(error) {
296
+ subtaskProgress.current = subtaskProgress.total // failed = finished
297
+ const outputError: any = new Error("Subtask error: " + error.toString())
298
+ outputError.stack = error.stack
299
+ outputError.taskNoRetry = true
300
+ throw outputError
301
+ }
295
302
  },
296
303
  async progress(current, total, action, opts) { // throttle this
297
304
  selfProgress = {
@@ -362,17 +369,21 @@ export default function task(definition:TaskDefinition, serviceDefinition) {
362
369
  })
363
370
 
364
371
  const promises = taskWatchers.map(watcher => new Promise((resolve, reject) => watcher.run(resolve, reject)))
365
- await Promise.all(promises)
366
- //console.log("TASK WATCHERS PROMISES FULLFILLED", taskWatchers)
367
- const results = taskWatchers.map(watcher => {
368
- //console.log("WATCHER OBSERVABLE", watcher.observable)
369
- watcher.observable.getValue().result
370
- })
371
- for(const watcher of taskWatchers) {
372
- //console.log("UNOBSERVING WATCHER", watcher)
373
- watcher.observable.unobserve(watcher.observer)
374
- }
375
- return results
372
+ try {
373
+ await Promise.all(promises)
374
+ //console.log("TASK WATCHERS PROMISES FULLFILLED", taskWatchers)
375
+ const results = taskWatchers.map(watcher => {
376
+ //console.log("WATCHER OBSERVABLE", watcher.observable)
377
+ watcher.observable.getValue().result
378
+ })
379
+ return results
380
+ } catch(subtask) {
381
+ const retry = subtask.retries?.at(-1)
382
+ const outputError: any = new Error("Subtask error: " + retry?.error)
383
+ outputError.stack = retry?.stack
384
+ outputError.taskNoRetry = true
385
+ throw outputError
386
+ }
376
387
  }
377
388
  }
378
389
  try {