lib/rocket_job/plugins/job/worker.rb in rocketjob-2.0.0 vs lib/rocket_job/plugins/job/worker.rb in rocketjob-2.1.1
- old
+ new
@@ -67,11 +67,14 @@
end
end
# Requeues all jobs that were running on worker that died
def self.requeue_dead_worker(worker_name)
- running.each { |job| job.requeue!(worker_name) if job.may_requeue?(worker_name) }
+ # TODO Need to requeue paused, failed since user may have transitioned job before it finished
+ running.each do |job|
+ job.requeue!(worker_name) if job.may_requeue?(worker_name)
+ end
end
# Turn off embedded callbacks. Slow and not used for Jobs
embedded_callbacks_off
end
@@ -95,11 +98,11 @@
raise(MongoMapper::DocumentNotValid, self)
end
worker = RocketJob::Worker.new(name: 'inline')
worker.started
start if may_start?
- # Raise exceptions
+ # Re-Raise exceptions
rocket_job_work(worker, true) if running?
result
end
def perform(*)
@@ -111,14 +114,14 @@
# The job is automatically saved only if an exception is raised in the supplied block.
#
# worker_name: [String]
# Name of the worker on which the exception has occurred
#
- # raise_exceptions: [true|false]
+ # re_raise_exceptions: [true|false]
# Re-raise the exception after updating the job
- # Default: !RocketJob::Config.inline_mode
- def rocket_job_fail_on_exception!(worker_name, raise_exceptions = !RocketJob::Config.inline_mode)
+ # Default: false
+ def rocket_job_fail_on_exception!(worker_name, re_raise_exceptions = false)
yield
rescue Exception => exc
if failed? || !may_fail?
self.exception = JobException.from_exception(exc)
exception.worker_name = worker_name
@@ -128,23 +131,23 @@
fail(worker_name, exc)
else
fail!(worker_name, exc)
end
end
- raise exc if raise_exceptions
+ raise exc if re_raise_exceptions
end
# Works on this job
#
# Returns [true|false] whether this job should be excluded from the next lookup
#
# If an exception is thrown the job is marked as failed and the exception
# is set in the job itself.
#
# Thread-safe, can be called by multiple threads at the same time
- def rocket_job_work(worker, raise_exceptions = !RocketJob::Config.inline_mode)
+ def rocket_job_work(worker, re_raise_exceptions = false)
raise(ArgumentError, 'Job must be started before calling #rocket_job_work') unless running?
- rocket_job_fail_on_exception!(worker.name, raise_exceptions) do
+ rocket_job_fail_on_exception!(worker.name, re_raise_exceptions) do
run_callbacks :perform do
# Allow callbacks to fail, complete or abort the job
if running?
ret = perform(*arguments)
if collect_output?