Class: ActiveJob::QueueAdapters::SqewerAdapter::Performable

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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.

Parameters:

  • active_job_worker (ActiveJob::Job)

    the job you want to convert



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_nameObject



46
47
48
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 46

def class_name
  @job[:job_class]
end

#inspectObject



42
43
44
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 42

def inspect
  '<%s>' % [@job.inspect]
end

#runObject

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_hObject



38
39
40
# File 'lib/sqewer/extensions/active_job_adapter.rb', line 38

def to_h
  {job: @job}
end