Queue actions errors can not be all fatal #12
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was trying something like the code in the end of this post
But, if I return a error from enqueued actions, it is a FATAL error and it shuts down the application and ends any concurrent tasks.
I do not think it make sense.
So I used seneca.root.delegate to change context.
It was necessary an adjustment on test.
I tried another approach adding a reference in the queue to the seneca instance provide by this keyword inside add function "role:role,hook:enqueue,type:memory" but not sure why it did not work.
The seneca instance used before was the one available in plugin function so it expected has fatal$:true, but the seneca instance from this keyword inside add function "role:role,hook:enqueue,type:memory" should not has fatal$: true, right?
seneca = (require 'seneca')
timeout: 40*1000
seneca.use 'seneca-queue',
role: 'cpu-intense-task-queue'
concurrency: 1
plugin = (options) ->
@add (init: 'cpu-intense-task'), (args,done) ->
@log.info 'CPU intense task is up'
done()
@add (role: 'cpu-intense-task', cmd: 'execute'), (args,done) ->
console.log "Starting #{args.task}"
console.log args
if args.fail
console.log "#{args.task} failed"
done (new Error "#{args.task} Failed ")
else
setTimeout ->
console.log "Finished #{args.task}"
done null, (task: args.task)
, 6000
'cpu-intense-task'
seneca.use plugin
seneca.act role: 'cpu-intense-task-queue', cmd: 'start'
console.log 'Seneca ready. Calling tasks every 3 seconds. Second is going to fail'
count = 0
timer = setInterval ->
count++
taskName = "Task #{count}"
seneca.act
role: 'cpu-intense-task-queue'
cmd: 'enqueue'
msg:
role: 'cpu-intense-task'
cmd: 'execute'
task: taskName
fail: count is 2
, (err,args) ->
if err
console.log 'Failed to add #{taskName} to queue', err.message
else
console.log "Added #{taskName} to queue"
clearInterval timer if count > 4
,3000