Sha256: e7d4c9de70a97b4c56676d79eda1afa61e957eeaad1315a76d20912ba65bed50

Contents?: true

Size: 1008 Bytes

Versions: 1

Compression:

Stored size: 1008 Bytes

Contents

module RailsLiveDashboard
  module Recorders
    module Jobs
      class DiscardRecorder
        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 = :discarded
          content.finished_at = Time.now
          content.duration = duration
        end

        def build_history
          content.history.push({
            status: :discarded,
            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/discard_recorder.rb