Sha256: dfe1c5d5121aae0ed3ac1258b14b88b977b29139fad4b419043c24d883f102df

Contents?: true

Size: 1.62 KB

Versions: 17

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module GoodJob # :nodoc:
  class DiscreteExecution < BaseRecord
    include ErrorEvents

    self.table_name = 'good_job_executions'

    belongs_to :execution, class_name: 'GoodJob::Execution', foreign_key: 'active_job_id', primary_key: 'active_job_id', inverse_of: :discrete_executions, optional: true
    belongs_to :job, class_name: 'GoodJob::Job', foreign_key: 'active_job_id', primary_key: 'active_job_id', inverse_of: :discrete_executions, optional: true

    scope :finished, -> { where.not(finished_at: nil) }

    alias_attribute :performed_at, :created_at

    def self.error_event_migrated?
      return true if columns_hash["error_event"].present?

      migration_pending_warning!
      false
    end

    def number
      serialized_params.fetch('executions', 0) + 1
    end

    # Time between when this job was expected to run and when it started running
    def queue_latency
      created_at - scheduled_at
    end

    # Time between when this job started and finished
    def runtime_latency
      (finished_at || Time.current) - performed_at if performed_at
    end

    def last_status_at
      finished_at || created_at
    end

    def status
      if finished_at.present?
        if error.present?
          :retried
        elsif error.present? && job.finished_at.present?
          :discarded
        else
          :succeeded
        end
      else
        :running
      end
    end

    def display_serialized_params
      serialized_params.merge({
                                _good_job_execution: attributes.except('serialized_params'),
                              })
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
good_job-3.19.2 app/models/good_job/discrete_execution.rb
good_job-3.19.1 app/models/good_job/discrete_execution.rb
good_job-3.19.0 app/models/good_job/discrete_execution.rb
good_job-3.18.3 app/models/good_job/discrete_execution.rb
good_job-3.18.2 app/models/good_job/discrete_execution.rb
good_job-3.18.1 app/models/good_job/discrete_execution.rb
good_job-3.18.0 app/models/good_job/discrete_execution.rb
good_job-3.17.4 app/models/good_job/discrete_execution.rb
good_job-3.17.3 app/models/good_job/discrete_execution.rb
good_job-3.17.2 app/models/good_job/discrete_execution.rb
good_job-3.17.1 app/models/good_job/discrete_execution.rb
good_job-3.17.0 app/models/good_job/discrete_execution.rb
good_job-3.16.4 app/models/good_job/discrete_execution.rb
good_job-3.16.3 app/models/good_job/discrete_execution.rb
good_job-3.16.2 app/models/good_job/discrete_execution.rb
good_job-3.16.1 app/models/good_job/discrete_execution.rb
good_job-3.16.0 app/models/good_job/discrete_execution.rb