Class: Cloudtasker::WorkerWrapper
- Inherits:
-
Object
- Object
- Cloudtasker::WorkerWrapper
- Includes:
- Worker
- Defined in:
- lib/cloudtasker/worker_wrapper.rb
Overview
A worker class used to schedule jobs without actually instantiating the worker class. This is useful for middlewares needing to enqueue jobs in a Rails initializer. Rails 6 complains about instantiating workers in an iniitializer because of autoloading in zeitwerk mode.
Downside of this wrapper: any cloudtasker_options specified on on the worker_class will be ignored.
Instance Attribute Summary collapse
-
#worker_name ⇒ Object
Returns the value of attribute worker_name.
Instance Method Summary collapse
-
#initialize(worker_name:, **opts) ⇒ WorkerWrapper
constructor
Build a new instance of the class.
-
#job_class_name ⇒ String
Override parent.
-
#new_instance ⇒ Cloudtasker::WorkerWrapper
Return a new instance of the worker with the same args and metadata but with a different id.
Methods included from Worker
#==, #arguments_missing?, clear_all, #dispatch_deadline, drain_all, #execute, from_hash, from_json, included, #job_dead?, #job_duration, #job_max_retries, #job_must_die?, #job_queue, #logger, #reenqueue, #run_callback, #schedule, #schedule_time, #to_h, #to_json
Constructor Details
#initialize(worker_name:, **opts) ⇒ WorkerWrapper
Build a new instance of the class.
28 29 30 31 |
# File 'lib/cloudtasker/worker_wrapper.rb', line 28 def initialize(worker_name:, **opts) @worker_name = worker_name super(**opts) end |
Instance Attribute Details
#worker_name ⇒ Object
Returns the value of attribute worker_name.
20 21 22 |
# File 'lib/cloudtasker/worker_wrapper.rb', line 20 def worker_name @worker_name end |
Instance Method Details
#job_class_name ⇒ String
Override parent. Return the underlying worker class name.
38 39 40 |
# File 'lib/cloudtasker/worker_wrapper.rb', line 38 def job_class_name worker_name end |
#new_instance ⇒ Cloudtasker::WorkerWrapper
Return a new instance of the worker with the same args and metadata but with a different id.
48 49 50 |
# File 'lib/cloudtasker/worker_wrapper.rb', line 48 def new_instance self.class.new(worker_name: worker_name, job_queue: job_queue, job_args: job_args, job_meta: ) end |