Module: Cloudtasker::Worker::ClassMethods
- Defined in:
- lib/cloudtasker/worker.rb,
lib/cloudtasker/testing.rb
Overview
Module class methods
Instance Method Summary collapse
-
#cache_key(val = nil) ⇒ String
Return a namespaced cache key.
-
#cloudtasker_options(opts = {}) ⇒ Hash
Set the worker runtime options.
-
#cloudtasker_options_hash ⇒ Hash
Return the worker runtime options.
-
#drain ⇒ Array<any>
Run all jobs related to this worker class.
-
#jobs ⇒ Array<Cloudtasker::Backend::MemoryTask>
Return all jobs related to this worker class.
-
#max_retries ⇒ Integer
Return the numbeer of times this worker will be retried.
-
#perform_async(*args) ⇒ Cloudtasker::CloudTask
Enqueue worker in the background.
-
#perform_at(time_at, *args) ⇒ Cloudtasker::CloudTask
Enqueue worker and delay processing.
-
#perform_in(interval, *args) ⇒ Cloudtasker::CloudTask
Enqueue worker and delay processing.
-
#perform_now(*args) ⇒ Any
Perform a worker inline, without sending it to the queue for processing.
-
#redis ⇒ Cloudtasker::RedisClient
Return the Cloudtasker redis client.
-
#schedule(args: nil, time_in: nil, time_at: nil, queue: nil) ⇒ Cloudtasker::CloudTask
Enqueue a worker with explicity options.
Instance Method Details
#cache_key(val = nil) ⇒ String
Return a namespaced cache key.
97 98 99 |
# File 'lib/cloudtasker/worker.rb', line 97 def cache_key(val = nil) [to_s.underscore, val].flatten.compact.map(&:to_s).join('/') end |
#cloudtasker_options(opts = {}) ⇒ Hash
Set the worker runtime options.
76 77 78 79 |
# File 'lib/cloudtasker/worker.rb', line 76 def (opts = {}) opt_list = opts&.map { |k, v| [k.to_sym, v] } || [] # symbolize @cloudtasker_options_hash = opt_list.to_h end |
#cloudtasker_options_hash ⇒ Hash
Return the worker runtime options.
86 87 88 |
# File 'lib/cloudtasker/worker.rb', line 86 def @cloudtasker_options_hash || {} end |
#drain ⇒ Array<any>
Run all jobs related to this worker class.
179 180 181 |
# File 'lib/cloudtasker/testing.rb', line 179 def drain Backend::MemoryTask.drain(to_s) end |
#jobs ⇒ Array<Cloudtasker::Backend::MemoryTask>
Return all jobs related to this worker class.
170 171 172 |
# File 'lib/cloudtasker/testing.rb', line 170 def jobs Backend::MemoryTask.all(to_s) end |
#max_retries ⇒ Integer
Return the numbeer of times this worker will be retried.
171 172 173 |
# File 'lib/cloudtasker/worker.rb', line 171 def max_retries [:max_retries] || Cloudtasker.config.max_retries end |
#perform_async(*args) ⇒ Cloudtasker::CloudTask
Enqueue worker in the background.
108 109 110 |
# File 'lib/cloudtasker/worker.rb', line 108 def perform_async(*args) schedule(args: args) end |
#perform_at(time_at, *args) ⇒ Cloudtasker::CloudTask
Enqueue worker and delay processing.
132 133 134 |
# File 'lib/cloudtasker/worker.rb', line 132 def perform_at(time_at, *args) schedule(args: args, time_at: time_at) end |
#perform_in(interval, *args) ⇒ Cloudtasker::CloudTask
Enqueue worker and delay processing.
120 121 122 |
# File 'lib/cloudtasker/worker.rb', line 120 def perform_in(interval, *args) schedule(args: args, time_in: interval) end |
#perform_now(*args) ⇒ Any
Perform a worker inline, without sending it to the queue for processing.
Middlewares (unique job, batch etc.) will still be invoked as if the job had been scheduled.
146 147 148 149 150 |
# File 'lib/cloudtasker/worker.rb', line 146 def perform_now(*args) # Serialize/deserialize arguments to mimic job enqueueing and produce a similar context job_args = JSON.parse(args.to_json) new(job_args: job_args).execute end |
#redis ⇒ Cloudtasker::RedisClient
Return the Cloudtasker redis client
65 66 67 |
# File 'lib/cloudtasker/worker.rb', line 65 def redis @redis ||= RedisClient.new end |
#schedule(args: nil, time_in: nil, time_at: nil, queue: nil) ⇒ Cloudtasker::CloudTask
Enqueue a worker with explicity options.
162 163 164 |
# File 'lib/cloudtasker/worker.rb', line 162 def schedule(args: nil, time_in: nil, time_at: nil, queue: nil) new(job_args: args, job_queue: queue).schedule(**{ interval: time_in, time_at: time_at }.compact) end |