Sha256: 90ee165e161e6083351d6a7f86e112ab301ccd954b57a3424dd87c14a4f70811

Contents?: true

Size: 726 Bytes

Versions: 4

Compression:

Stored size: 726 Bytes

Contents

# frozen_string_literal: true

require "active_record"

module AcidicJob
  class Staged < ActiveRecord::Base
    self.table_name = "staged_acidic_jobs"

    validates :adapter, presence: true
    validates :job_name, presence: true
    validates :job_args, presence: true

    serialize :job_args

    after_create_commit :enqueue_job

    def enqueue_job
      case adapter
      when "activejob"
        job = ActiveJob::Base.deserialize(job_args)
        job.enqueue
      when "sidekiq"
        Sidekiq::Client.push("class" => job_name, "args" => job_args)
      else
        raise UnknownJobAdapter.new(adapter: adapter)
      end

      # TODO: ensure successful enqueuing before deletion
      delete
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
acidic_job-0.6.0 lib/acidic_job/staged.rb
acidic_job-0.5.5 lib/acidic_job/staged.rb
acidic_job-0.5.4 lib/acidic_job/staged.rb
acidic_job-0.5.3 lib/acidic_job/staged.rb