           @emitConsumeTask message, queueName, ironTask
 
   taskExecuted: (err, result) ->
-    @getQueue(result.queue).del result.id, {}, (err, body) =>
+    @getQueue(result.queue).del result.id, { reservation_id: result.options.reservation_id }, (err, body) =>
       if err
         logger.warn "IVY_WARNING Cannot delete task #{result.id} from IronMQ", err
         @manager.emit 'mqError', err

tokencrypto = require '../tokencrypto'

CONSUME_INTERVAL  = parseInt(process.env.IRONMQ_CONSUME_INTERVAL, 10) or 1000
IRONMQ_LIMIT = parseInt(process.env.IRONMQ_LIMIT, 10) or 65536

class IronMQQueue

  emitConsumeTask: (message, queue, ironTask) ->
    try
      taskArgs = JSON.parse message
      taskArgs.options.reservation_id = ironTask.reservation_id
    catch e
      logger.error 'ironTask is', ironTask
      logger.error "IVY_IRONMQ_ERROR Retrieve tasks that cannot be parsed as JSON, deleting from queue: #{ironTask}", e
      logger.warn "IRONTASK", ironTask
      if ironTask.id
        @getQueue().del ironTask.id, { reservation_id: taskArgs.options.reservation_id}, (err, body) =>
          if err
            logger.warn "IVY_WARNING Cannot delete task from IronMQ 1", err
            @manager.emit 'mqError', err

    @manager.emit 'scheduledTaskRetrieved',
      id:             ironTask.id
      name:           taskArgs.name
      args:           taskArgs.args
      options:        taskArgs.options
      queue:          queue

  consumeTasks: (queues) ->
    toRetrieve = @options.messageSize or 1
