Sha256: ec1e1ca819a7d159345d1ab8e8ebc20bf6e141737dbe35447ef2b255e9368dfb
Contents?: true
Size: 1.38 KB
Versions: 22
Compression:
Stored size: 1.38 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 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]) batch.increment_job_queue(job_id) if (@bid = batch.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
22 entries across 22 versions & 1 rubygems