Sha256: f90075c270449c74ed1395ac7c724ff4492e87316dd120524eea16f121795d3b

Contents?: true

Size: 1.21 KB

Versions: 3

Compression:

Stored size: 1.21 KB

Contents

module GoodJob
  class Job < ActiveRecord::Base
    include Lockable

    self.table_name = 'good_jobs'

    def self.enqueue(active_job, scheduled_at: nil, create_with_advisory_lock: false)
      good_job = nil
      ActiveSupport::Notifications.instrument("enqueue_job.good_job", { active_job: active_job, scheduled_at: scheduled_at, create_with_advisory_lock: create_with_advisory_lock }) do |instrument_payload|
        good_job = GoodJob::Job.new(
          queue_name: active_job.queue_name,
          priority: active_job.priority,
          serialized_params: active_job.serialize,
          scheduled_at: scheduled_at,
          create_with_advisory_lock: create_with_advisory_lock
        )

        instrument_payload[:good_job] = good_job

        good_job.save!
        active_job.provider_job_id = good_job.id
      end

      good_job
    end

    def perform
      ActiveSupport::Notifications.instrument("before_perform_job.good_job", { good_job: self })
      ActiveSupport::Notifications.instrument("perform_job.good_job", { good_job: self }) do
        params = serialized_params.merge(
          "provider_job_id" => id
        )
        ActiveJob::Base.execute(params)

        destroy!
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
good_job-0.5.0 lib/good_job/job.rb
good_job-0.4.0 lib/good_job/job.rb
good_job-0.3.0 lib/good_job/job.rb