Sha256: 34282003c766e2d34a6ff1d2bed4e6a6ef94f5b38e554fc946b2a1a3a5e0929f

Contents?: true

Size: 686 Bytes

Versions: 1

Compression:

Stored size: 686 Bytes

Contents

module GoodJob
  class Adapter
    def initialize(options = {})
      @options = options
      @scheduler = InlineScheduler.new if inline?
    end

    def inline?
      @options.fetch(:inline, false)
    end

    def enqueue(job)
      enqueue_at(job, nil)
    end

    def enqueue_at(job, timestamp)
      params = {
        queue_name: job.queue_name,
        priority: job.priority,
        serialized_params: job.serialize,
      }
      params[:scheduled_at] = Time.at(timestamp) if timestamp

      good_job = GoodJob::Job.create(params)
      @scheduler.enqueue(good_job) if inline?
    end

    def shutdown(wait: true)
      @scheduler&.shutdown(wait: wait)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
good_job-0.1.0 lib/good_job/adapter.rb