Module: RocketJob::Concerns::Worker
- Included in:
- Job
- Defined in:
- lib/rocket_job/concerns/worker.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #rocket_job_csv_parser ⇒ Object
-
#work(worker) ⇒ Object
Works on this job.
Class Method Details
.included(base) ⇒ Object
7 8 9 10 11 12 13 14 15 |
# File 'lib/rocket_job/concerns/worker.rb', line 7 def self.included(base) base.extend ClassMethods base.class_eval do # While working on a slice, the current slice is available via this reader attr_reader :rocket_job_slice @rocket_job_defaults = nil end end |
Instance Method Details
#rocket_job_csv_parser ⇒ Object
76 77 78 79 |
# File 'lib/rocket_job/concerns/worker.rb', line 76 def rocket_job_csv_parser # TODO Change into an instance variable once CSV handling has been re-worked RocketJob::Utility::CSVRow.new end |
#work(worker) ⇒ Object
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
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/rocket_job/concerns/worker.rb', line 89 def work(worker) raise 'Job must be started before calling #work' unless running? begin # before_perform call_method(perform_method, arguments, event: :before, log_level: log_level) # perform call_method(perform_method, arguments, log_level: log_level) if self.collect_output? self.output = (result.is_a?(Hash) || result.is_a?(BSON::OrderedHash)) ? result : { result: result } end # after_perform call_method(perform_method, arguments, event: :after, log_level: log_level) complete! rescue Exception => exc set_exception(worker.name, exc) raise exc if RocketJob::Config.inline_mode end false end |