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.
26 27 28 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 26 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.
18 19 20 21 22 23 24 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 18 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
38 39 40 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 38 def class_name @job[:job_class] end |
#inspect ⇒ Object
34 35 36 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 34 def inspect '<%s>' % [@job.inspect] end |
#run ⇒ Object
Runs the contained ActiveJob.
43 44 45 46 47 48 49 50 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 43 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
30 31 32 |
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 30 def to_h {job: @job} end |