Class: Workerholic::JobWrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/workerholic/job_wrapper.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ JobWrapper

Returns a new instance of JobWrapper.



6
7
8
9
10
11
12
13
14
# File 'lib/workerholic/job_wrapper.rb', line 6

def initialize(options={})
  @klass = options[:klass]
  @wrapper = options[:wrapper]
  @arguments = options[:arguments]
  @queue = options[:queue]
  @execute_at = options[:execute_at]
  @retry_count = options[:retry_count] || 0
  @statistics = JobStatistics.new(options[:statistics] || {})
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



4
5
6
# File 'lib/workerholic/job_wrapper.rb', line 4

def arguments
  @arguments
end

#execute_atObject

Returns the value of attribute execute_at.



3
4
5
# File 'lib/workerholic/job_wrapper.rb', line 3

def execute_at
  @execute_at
end

#klassObject (readonly)

Returns the value of attribute klass.



4
5
6
# File 'lib/workerholic/job_wrapper.rb', line 4

def klass
  @klass
end

#queueObject (readonly)

Returns the value of attribute queue.



4
5
6
# File 'lib/workerholic/job_wrapper.rb', line 4

def queue
  @queue
end

#retry_countObject

Returns the value of attribute retry_count.



3
4
5
# File 'lib/workerholic/job_wrapper.rb', line 3

def retry_count
  @retry_count
end

#statisticsObject (readonly)

Returns the value of attribute statistics.



4
5
6
# File 'lib/workerholic/job_wrapper.rb', line 4

def statistics
  @statistics
end

#wrapperObject (readonly)

Returns the value of attribute wrapper.



4
5
6
# File 'lib/workerholic/job_wrapper.rb', line 4

def wrapper
  @wrapper
end

Instance Method Details

#==(other) ⇒ Object



39
40
41
# File 'lib/workerholic/job_wrapper.rb', line 39

def ==(other)
  to_hash == other.to_hash
end

#performObject



28
29
30
31
32
33
34
35
36
37
# File 'lib/workerholic/job_wrapper.rb', line 28

def perform
  if wrapper && wrapper.name == 'ActiveJob::QueueAdapters::WorkerholicAdapter::JobWrapper'
    wrapper.new.perform(
      'job_class' => klass,
      'arguments' => arguments
    )
  else
    klass.new.perform(*arguments)
  end
end

#to_hashObject



16
17
18
19
20
21
22
23
24
25
26
# File 'lib/workerholic/job_wrapper.rb', line 16

def to_hash
  {
    klass: klass,
    wrapper: wrapper,
    arguments: arguments,
    queue: queue,
    retry_count: retry_count,
    execute_at: execute_at,
    statistics: statistics.to_hash
  }
end