Sha256: 1f140eb7ace9f3b9cd7f88c14f9e69889bde588c2891433053f2ff4fac05d5ac

Contents?: true

Size: 1.12 KB

Versions: 15

Compression:

Stored size: 1.12 KB

Contents

module Ddr::Batch
  class MonitorBatchStarted

    class << self
      def call(*args)
        event = ActiveSupport::Notifications::Event.new(*args)
        batch = Ddr::Batch::Batch.find(event.payload[:batch_id])
        batch_started(batch)
      end

      private

      def batch_started(batch)
        clear_logs(batch)
        log_batch_start(batch)
        update_batch(batch)
      end

      def clear_logs(batch)
        # delete any previously existing filesystem log file for this batch
        Ddr::Batch::Log.clear_log(batch.id)
        # remove any existing attached log file from the Batch ActiveRecord object
        batch.logfile.clear
      end

      def log_batch_start(batch)
        logger = Ddr::Batch::Log.logger(batch.id)
        logger.info "Batch id: #{batch.id}"
        logger.info "Batch name: #{batch.name}" if name
        logger.info "Batch size: #{batch.batch_objects.size}"
        logger.close
      end

      def update_batch(batch)
        batch.update!(start: DateTime.now,
                      status: Ddr::Batch::Batch::STATUS_RUNNING,
                      version: VERSION)
      end
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
ddr-batch-1.5.1 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.5.0 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.5.0.rc1 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.4.1 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.4.0 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.4.0.rc1 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.3.0 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.3.0.rc1 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0.rc6 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0.rc5 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0.rc4 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0.rc3 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0.rc2 app/services/ddr/batch/monitor_batch_started.rb
ddr-batch-1.2.0.rc1 app/services/ddr/batch/monitor_batch_started.rb