Class: Woodhouse::JobExecution

Inherits:
Object
  • Object
show all
Defined in:
lib/woodhouse/job_execution.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config, job) ⇒ JobExecution

Returns a new instance of JobExecution.



12
13
14
15
# File 'lib/woodhouse/job_execution.rb', line 12

def initialize(config, job)
  @config = config
  @job = job
end

Class Attribute Details

.fatal_error_procObject

Returns the value of attribute fatal_error_proc.



4
5
6
# File 'lib/woodhouse/job_execution.rb', line 4

def fatal_error_proc
  @fatal_error_proc
end

Instance Method Details

#executeObject

Looks up the correct worker class for a job and executes it, running it through the runner middleware stack first. Returns true if the job finishes without an exception, false otherwise.

If you need to keep track of exceptions raised by jobs, add middleware to handle them, like Woodhouse::Middleware::AirbrakeExceptions.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/woodhouse/job_execution.rb', line 23

def execute
  worker = @config.registry[@job.worker_class_name]
  unless worker
    raise Woodhouse::WorkerNotFoundError, "couldn't find job class #{@job.worker_class_name}"
  end
  work_object = worker.new
  begin
    @config.runner_middleware.call(@job, work_object) {|job, work_object|
      work_object.send(job.job_method, job)
    }
    return true
  rescue Woodhouse::FatalError
    raise
  rescue => err
    if fatal_error?(err)
      raise err
    else
      # Ignore the exception
      return false
    end
  end
end