Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix: Exception in periodic task stops this task queue
New task option: reEnqueuePeriodicTaskIfException
  • Loading branch information
n.a.onishchuk committed Jun 10, 2019
1 parent bebc326 commit 68568df
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 3 additions & 1 deletion classes/task.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ module.exports = class Task {
* @property {Number} frequency - How often to run this Task, in ms. 0 is non-recurring. (default: 0).
* @property {Array} middleware - The Middleware specific to this Task (default: []). Middleware is descibed by the string names of the middleware.
* @property {string} queue - The default queue to run this Task on (default: 'default').
* @property {boolean} reEnqueuePeriodicTaskIfException - Queuing a periodic task in the case of an exception. (default: false).
*
* @tutorial tasks
* @example
Expand Down Expand Up @@ -54,7 +55,8 @@ module.exports = class SayHello extends Task {
description: this.name,
frequency: 0,
queue: 'default',
middleware: []
middleware: [],
reEnqueuePeriodicTaskIfException: false
}
}

Expand Down
12 changes: 10 additions & 2 deletions initializers/tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ module.exports = class Tasks extends ActionHero.Initializer {
perform: async function () {
let combinedArgs = [].concat(Array.prototype.slice.call(arguments))
combinedArgs.push(this)
let response = await task.run.apply(task, combinedArgs)
await api.tasks.enqueueRecurrentTask(taskName)
let response = null;
try {
response = await task.run.apply(task, combinedArgs)
await api.tasks.enqueueRecurrentTask(taskName)
} catch (error) {
if(task.reEnqueuePeriodicTaskIfException){
await api.tasks.enqueueRecurrentTask(taskName)
}
throw error
}
return response
}
}
Expand Down

0 comments on commit 68568df

Please sign in to comment.