Sha256: f02dc26c7a606c51a8cda31dae52403ebbe953e8e2df0e902e5adec6fd4fa9a1
Contents?: true
Size: 1.53 KB
Versions: 12
Compression:
Stored size: 1.53 KB
Contents
module CanvasSync module JobBatches module BatchAwareJob extend ActiveSupport::Concern included do around_perform do |job, block| if (@bid) # This _must_ be @bid - not just bid prev_batch = Thread.current[CURRENT_BATCH_THREAD_KEY] begin Thread.current[CURRENT_BATCH_THREAD_KEY] = Batch.new(@bid) block.call Thread.current[CURRENT_BATCH_THREAD_KEY].save_context_changes Batch.process_successful_job(@bid, job_id) rescue Batch.process_failed_job(@bid, job_id) raise ensure Thread.current[CURRENT_BATCH_THREAD_KEY] = prev_batch end else block.call end end around_enqueue do |job, block| if (batch = Thread.current[CURRENT_BATCH_THREAD_KEY]) @bid = batch.bid batch.increment_job_queue(job_id) if @bid end block.call end end def bid @bid || Thread.current[CURRENT_BATCH_THREAD_KEY]&.bid end def batch Thread.current[CURRENT_BATCH_THREAD_KEY] end def batch_context batch&.context || {} end def valid_within_batch? batch.valid? end def serialize super.tap do |data| data['batch_id'] = @bid # This _must_ be @bid - not just bid end end def deserialize(data) super @bid = data['batch_id'] end end end end
Version data entries
12 entries across 12 versions & 1 rubygems