module Cloudtasker::Worker::ClassMethods
Module class methods
Module class methods
Public Instance Methods
Set the worker runtime options.
@param [Hash] opts The worker options.
@return [Hash] The options set.
# File lib/cloudtasker/worker.rb, line 64 def cloudtasker_options(opts = {}) opt_list = opts&.map { |k, v| [k.to_sym, v] } || [] # symbolize @cloudtasker_options_hash = Hash[opt_list] end
Return the worker runtime options.
@return [Hash] The worker runtime options.
# File lib/cloudtasker/worker.rb, line 74 def cloudtasker_options_hash @cloudtasker_options_hash || {} end
Run all jobs related to this worker class.
@return [Array<any>] The return values of the workers perform method.
# File lib/cloudtasker/testing.rb, line 128 def drain Backend::MemoryTask.drain(to_s) end
Return all jobs related to this worker class.
@return [Array<Cloudtasker::Backend::MemoryTask>] The list of tasks
# File lib/cloudtasker/testing.rb, line 119 def jobs Backend::MemoryTask.all(to_s) end
Return the numbeer of times this worker will be retried.
@return [Integer] The number of retries.
# File lib/cloudtasker/worker.rb, line 132 def max_retries cloudtasker_options_hash[:max_retries] || Cloudtasker.config.max_retries end
Enqueue worker in the backgroundf.
@param [Array<any>] *args List of worker arguments
@return [Cloudtasker::CloudTask] The Google Task response
# File lib/cloudtasker/worker.rb, line 85 def perform_async(*args) schedule(args: args) end
Enqueue worker and delay processing.
@param [Time, Integer] time_at The time at which the job should run. @param [Array<any>] *args List of worker arguments
@return [Cloudtasker::CloudTask] The Google Task response
# File lib/cloudtasker/worker.rb, line 109 def perform_at(time_at, *args) schedule(args: args, time_at: time_at) end
Enqueue worker and delay processing.
@param [Integer, nil] interval The delay in seconds. @param [Array<any>] *args List of worker arguments.
@return [Cloudtasker::CloudTask] The Google Task response
# File lib/cloudtasker/worker.rb, line 97 def perform_in(interval, *args) schedule(args: args, time_in: interval) end
Enqueue a worker with explicity options.
@param [Array<any>] args The job arguments. @param [Time, Integer] time_in The delay in seconds. @param [Time, Integer] time_at The time at which the job should run. @param [String, Symbol] queue The queue on which the worker should run.
@return [Cloudtasker::CloudTask] The Google Task response
# File lib/cloudtasker/worker.rb, line 123 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