Module: Delayed::Backend::Base::ClassMethods
- Defined in:
- lib/delayed/backend/base.rb
Instance Method Summary collapse
-
#after_fork ⇒ Object
Hook method that is called after a new worker is forked.
-
#before_fork ⇒ Object
Hook method that is called before a new worker is forked.
-
#enqueue(*args) ⇒ Object
Add a job to the queue.
-
#recover_from(_error) ⇒ Object
Allow the backend to attempt recovery from reserve errors.
- #reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object
- #work_off(num = 100) ⇒ Object
Instance Method Details
#after_fork ⇒ Object
Hook method that is called after a new worker is forked
57 58 |
# File 'lib/delayed/backend/base.rb', line 57 def after_fork end |
#before_fork ⇒ Object
Hook method that is called before a new worker is forked
53 54 |
# File 'lib/delayed/backend/base.rb', line 53 def before_fork end |
#enqueue(*args) ⇒ Object
Add a job to the queue
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/delayed/backend/base.rb', line 10 def enqueue(*args) # rubocop:disable CyclomaticComplexity = args. [:payload_object] ||= args.shift [:priority] ||= Delayed::Worker.default_priority if [:queue].nil? if [:payload_object].respond_to?(:queue_name) [:queue] = [:payload_object].queue_name end [:queue] ||= Delayed::Worker.default_queue_name end if args.size > 0 warn '[DEPRECATION] Passing multiple arguments to `#enqueue` is deprecated. Pass a hash with :priority and :run_at.' [:priority] = args.first || [:priority] [:run_at] = args[1] end unless [:payload_object].respond_to?(:perform) raise ArgumentError, 'Cannot enqueue items which do not respond to perform' end new().tap do |job| Delayed::Worker.lifecycle.run_callbacks(:enqueue, job) do job.hook(:enqueue) Delayed::Worker.delay_jobs ? job.save : job.invoke_job end end end |
#recover_from(_error) ⇒ Object
Allow the backend to attempt recovery from reserve errors
49 50 |
# File 'lib/delayed/backend/base.rb', line 49 def recover_from(_error) end |
#reserve(worker, max_run_time = Worker.max_run_time) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/delayed/backend/base.rb', line 40 def reserve(worker, max_run_time = Worker.max_run_time) # We get up to 5 jobs from the db. In case we cannot get exclusive access to a job we try the next. # this leads to a more even distribution of jobs across the worker processes find_available(worker.name, worker.read_ahead, max_run_time).detect do |job| job.lock_exclusively!(max_run_time, worker.name) end end |