Class: Workerholic::JobProcessor

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(serialized_job) ⇒ JobProcessor

Returns a new instance of JobProcessor.



5
6
7
8
# File 'lib/workerholic/job_processor.rb', line 5

def initialize(serialized_job)
  @serialized_job = serialized_job
  @logger = LogManager.new
end

Instance Attribute Details

#serialized_jobObject (readonly)

Returns the value of attribute serialized_job.



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

def serialized_job
  @serialized_job
end

Instance Method Details

#processObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/workerholic/job_processor.rb', line 10

def process
  job = JobSerializer.deserialize(serialized_job)

  job.statistics.started_at = Time.now.to_f
  job_result = job.perform
  job.statistics.completed_at = Time.now.to_f

  StatsStorage.save_job('completed_jobs', job)
  StatsStorage.update_historical_stats('completed_jobs', job.klass.to_s)

  # @logger.info("Completed: your job from class #{job.klass} was completed on #{job.statistics.completed_at}.")

  # forces AR to release idle connections back to the pool
  ActiveRecord::Base.clear_active_connections! if defined?(Rails)

  job_result
rescue Exception => e
  job.statistics.errors.push([e.class, e.message])
  retry_job(job, e)
end