Sha256: 24dabe768148b1eb8b40b533c8d718adbb56bd048413116ba3ddf68b87d7a38f

Contents?: true

Size: 982 Bytes

Versions: 16

Compression:

Stored size: 982 Bytes

Contents

module Ddr::Batch
  class MonitorBatchObjectHandled

    class << self
      def call(*args)
        event = ActiveSupport::Notifications::Event.new(*args)
        batch_object = BatchObject.find(event.payload[:batch_object_id])
        batch = batch_object.batch
        batch_object_handled(batch_object, batch)
      end

      private

      def batch_object_handled(batch_object, batch)
        log_batch_object_messages(batch_object, batch.id)
        batch_object.update!(handled: true)
        unless batch.unhandled_objects?
          ActiveSupport::Notifications.instrument('finished.batch.batch.ddr', batch_id: batch.id)
        end
      end

      def log_batch_object_messages(batch_object, batch_id)
        logger = Ddr::Batch::Log.logger(batch_id)
        batch_object.batch_object_messages.each do |message|
          logger.add(message.level) { "Batch Object #{batch_object.id}: #{message.message}" }
        end
        logger.close
      end
    end

  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ddr-batch-1.7.1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.7.0 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.6.1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.6.0 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.6.0.rc1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.5.1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.5.0 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.5.0.rc1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.4.1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.4.0 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.4.0.rc1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.3.0 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.3.0.rc1 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.2.0 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.2.0.rc6 app/services/ddr/batch/monitor_batch_object_handled.rb
ddr-batch-1.2.0.rc5 app/services/ddr/batch/monitor_batch_object_handled.rb