Sha256: 5246eadbd545d94bd3520bec2431b06a9f655604e682f14d9fa0790d328ab555
Contents?: true
Size: 1.41 KB
Versions: 18
Compression:
Stored size: 1.41 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[:batch] begin Thread.current[:batch] = Batch.new(@bid) block.call Thread.current[:batch].save_context_changes Batch.process_successful_job(@bid, job_id) rescue Batch.process_failed_job(@bid, job_id) raise ensure Thread.current[:batch] = prev_batch end else block.call end end around_enqueue do |job, block| if (batch = Thread.current[:batch]) @bid = batch.bid batch.increment_job_queue(job_id) if @bid end block.call end end def bid @bid || Thread.current[:batch]&.bid end def batch Thread.current[:batch] 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
18 entries across 18 versions & 1 rubygems