Sha256: 29b3f2c8ff85cd7da14e515fff32bd9c84b325fd12455c41e00491881ac2363f

Contents?: true

Size: 708 Bytes

Versions: 8

Compression:

Stored size: 708 Bytes

Contents

# encoding: utf-8

require 'active_job'

module SayWhen
  module Processor
    class ActiveJobStrategy
      class << self
        def process(job)
          SayWhenJob.perform_later(job_to_arg(job))
        end

        def job_to_arg(job)
          case job
          when GlobalID::Identification
            job
          else
            { class: job.class.name, attributes: job.to_hash }
          end
        end
      end

      class SayWhenJob < ActiveJob::Base
        queue_as SayWhen.options[:queue]

        def perform(job)
          if job.is_a?(Hash)
            job = job[:class].constantize.new(job[:attributes])
          end
          job.execute
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
say_when-2.2.2 lib/say_when/processor/active_job_strategy.rb
say_when-2.2.1 lib/say_when/processor/active_job_strategy.rb
say_when-2.2.0 lib/say_when/processor/active_job_strategy.rb
say_when-2.1.1 lib/say_when/processor/active_job_strategy.rb
say_when-2.1.0 lib/say_when/processor/active_job_strategy.rb
say_when-2.0.2 lib/say_when/processor/active_job_strategy.rb
say_when-2.0.1 lib/say_when/processor/active_job_strategy.rb
say_when-2.0.0 lib/say_when/processor/active_job_strategy.rb