Class: ActiveJob::QueueAdapters::SqewerAdapter::Performable
- Inherits:
-
Object
- Object
- ActiveJob::QueueAdapters::SqewerAdapter::Performable
- Defined in:
- lib/sqewer/extensions/active_job_adapter.rb
Overview
Works as a Job for sqewer, and wraps an ActiveJob Worker which responds to perform()
Class Method Summary collapse
-
.from_active_job(active_job_worker) ⇒ Object
Creates a new Performable using the passed ActiveJob object.
Instance Method Summary collapse
- #class_name ⇒ Object
-
#initialize(job:) ⇒ Performable
constructor
A new instance of Performable.
- #inspect ⇒ Object
-
#run ⇒ Object
Runs the contained ActiveJob.
- #to_h ⇒ Object
Constructor Details
#initialize(job:) ⇒ Performable
Returns a new instance of Performable.
34 35 36 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 34 def initialize(job:) @job = job end |
Class Method Details
.from_active_job(active_job_worker) ⇒ Object
Creates a new Performable using the passed ActiveJob object. The resulting Performable can be sent to any Sqewer queue.
26 27 28 29 30 31 32 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 26 def self.from_active_job(active_job_worker) # Try to grab the job class immediately, so that an error is raised in the unserializer # if the class is not available klass = active_job_worker.class.to_s Kernel.const_get(klass) new(job: active_job_worker.serialize) end |
Instance Method Details
#class_name ⇒ Object
46 47 48 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 46 def class_name @job[:job_class] end |
#inspect ⇒ Object
42 43 44 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 42 def inspect '<%s>' % [@job.inspect] end |
#run ⇒ Object
Runs the contained ActiveJob.
51 52 53 54 55 56 57 58 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 51 def run job = ActiveSupport::HashWithIndifferentAccess.new(@job) if active_record_defined_and_connected? with_active_record_connection_from_pool { Base.execute(job) } else Base.execute(job) end end |
#to_h ⇒ Object
38 39 40 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 38 def to_h {job: @job} end |