Class: Workerholic::JobStatistics

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ JobStatistics

Returns a new instance of JobStatistics.



10
11
12
13
14
15
# File 'lib/workerholic/job_statistics.rb', line 10

def initialize(options={})
  @enqueued_at = options[:enqueued_at]
  @errors = options[:errors] || []
  @started_at = options[:started_at]
  @completed_at = options[:completed_at]
end

Instance Attribute Details

#completed_atObject

Returns the value of attribute completed_at.



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

def completed_at
  @completed_at
end

#enqueued_atObject

Returns the value of attribute enqueued_at.



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

def enqueued_at
  @enqueued_at
end

#errorsObject

Returns the value of attribute errors.



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

def errors
  @errors
end

#failed_onObject

Returns the value of attribute failed_on.



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

def failed_on
  @failed_on
end

#started_atObject

Returns the value of attribute started_at.



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

def started_at
  @started_at
end

Instance Method Details

#elapsed_timeObject



28
29
30
31
32
# File 'lib/workerholic/job_statistics.rb', line 28

def elapsed_time
  if completed_at && started_at
    format_elapsed_time(completed_at - started_at)
  end
end

#format_elapsed_time(time) ⇒ Object



34
35
36
# File 'lib/workerholic/job_statistics.rb', line 34

def format_elapsed_time(time)
  '%.10f' % time
end

#to_hashObject



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

def to_hash
  {
    enqueued_at: enqueued_at,
    errors: errors,
    started_at: started_at,
    completed_at: completed_at,
    elapsed_time: elapsed_time,
    failed_on: failed_on
  }
end