Class: CanvasSync::JobBatches::Sidekiq::ServerMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/canvas_sync/job_batches/sidekiq.rb

Instance Method Summary collapse

Instance Method Details

#call(_worker, msg, _queue) ⇒ Object



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/canvas_sync/job_batches/sidekiq.rb', line 58

def call(_worker, msg, _queue)
  if (bid = msg['bid'])
    prev_batch = Thread.current[CURRENT_BATCH_THREAD_KEY]
    begin
      Thread.current[CURRENT_BATCH_THREAD_KEY] = Batch.new(bid)
      yield
      Thread.current[CURRENT_BATCH_THREAD_KEY].save_context_changes
      Batch.process_successful_job(bid, msg['jid'])
    rescue
      Batch.process_failed_job(bid, msg['jid'])
      raise
    ensure
      Thread.current[CURRENT_BATCH_THREAD_KEY] = prev_batch
    end
  else
    yield
  end
end