Sha256: 1859864276df05f125f38e0ad4b7608e0f2170983e2161c643281491b2a3d01d

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module RailsLiveDashboard
  module Recorders
    module Jobs
      class PerformRecorder
        def initialize(event)
          @event = event
          @job = Job.same(@event.payload[:job].job_id).first
        end

        def execute
          raise Exceptions::EntryNotFound.new(:job, @event.payload[:job].job_id) if @job.nil?

          build_content
          build_history

          @job.update(content:)
        end

        private

        def content
          @content ||= @job.content
        end

        def build_content
          content.status = :performed
          content.finished_at = Time.now
          content.duration = duration
        end

        def build_history
          content.history.push({
            status: :performed,
            date: Time.now
          })
        end

        def duration
          return 0 if content.started_at.nil?

          (content.finished_at - Time.parse(content.started_at)).in_milliseconds.round
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_live_dashboard-0.2.0 lib/rails_live_dashboard/recorders/jobs/perform_recorder.rb