class Cloudtasker::Config
Holds cloudtasker configuration. See Cloudtasker#configure
Constants
- AUTHORIZATION_HEADER
Authorization header
- CONTENT_TYPE_HEADER
Content Type
- DEFAULT_DISPATCH_DEADLINE
Job timeout configuration for Cloud Tasks
- DEFAULT_JOB_QUEUE
Default queue values
- DEFAULT_LOCATION_ID
Default values
- DEFAULT_MAX_RETRY_ATTEMPTS
The number of times jobs will be attempted before declaring them dead.
With the default retry configuration (maxDoublings = 16 and minBackoff = 0.100s) it means that jobs will be declared dead after 20h of consecutive failing.
Note that this configuration parameter is internal to
Cloudtasker
and does not affect the Cloud Task queue configuration. The number of retries configured on the Cloud Task queue should be higher than the number below to also cover failures due to the instance being unreachable.- DEFAULT_ON_ERROR
Default
on_error
Proc- DEFAULT_PROCESSOR_PATH
- DEFAULT_QUEUE_CONCURRENCY
- DEFAULT_QUEUE_RETRIES
- ENCODING_HEADER
Content-Transfer-Encoding header in Cloud Task responses
- MAX_DISPATCH_DEADLINE
- MAX_TASK_SIZE
Max Cloud Task size in bytes
- MIN_DISPATCH_DEADLINE
- PROCESSOR_HOST_MISSING
- PROJECT_ID_MISSING_ERROR
- QUEUE_PREFIX_MISSING_ERROR
- RETRY_HEADER
Retry header in Cloud Task responses
TODO: use 'X-CloudTasks-TaskExecutionCount' instead of 'X-CloudTasks-TaskRetryCount'
'X-CloudTasks-TaskExecutionCount' is currently bugged and remains at 0 even on retries.
See bug: issuetracker.google.com/issues/154532072
Definitions:
X-CloudTasks-TaskRetryCount: total number of retries (including 504 "instance unreachable") X-CloudTasks-TaskExecutionCount: number of non-503 retries (= actual number of job failures)
- SECRET_MISSING_ERROR
- TASK_ID_HEADER
Cloud Task ID header
Attributes
Public Instance Methods
Return the chain of client middlewares.
@return [Cloudtasker::Middleware::Chain] The chain of middlewares.
# File lib/cloudtasker/config.rb, line 266 def client_middleware @client_middleware ||= Middleware::Chain.new yield @client_middleware if block_given? @client_middleware end
Return the Dispatch deadline duration. Cloud Tasks will timeout the job after this duration is elapsed.
@return [Integer] The value in seconds.
# File lib/cloudtasker/config.rb, line 225 def dispatch_deadline @dispatch_deadline || DEFAULT_DISPATCH_DEADLINE end
Return the current environment.
@return [String] The environment name.
# File lib/cloudtasker/config.rb, line 129 def environment ENV['CLOUDTASKER_ENV'] || ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development' end
Return the GCP location ID. Default to 'us-east1'
@return [String] The location ID where tasks will be processed.
# File lib/cloudtasker/config.rb, line 215 def gcp_location_id @gcp_location_id || DEFAULT_LOCATION_ID end
Return the GCP project ID.
@return [String] The ID of the project for which tasks will be processed.
# File lib/cloudtasker/config.rb, line 206 def gcp_project_id @gcp_project_id || raise(StandardError, PROJECT_ID_MISSING_ERROR) end
Return the prefix used for queues.
@return [String] The prefix of the processing queues.
# File lib/cloudtasker/config.rb, line 197 def gcp_queue_prefix @gcp_queue_prefix || raise(StandardError, QUEUE_PREFIX_MISSING_ERROR) end
Return the Cloudtasker
logger.
@return [Logger, any] The cloudtasker logger.
# File lib/cloudtasker/config.rb, line 138 def logger @logger ||= defined?(Rails) ? Rails.logger : ::Logger.new(STDOUT) end
The number of times jobs will be retried. This number of retries does not include failures due to the application being unreachable.
@return [Integer] The number of retries
# File lib/cloudtasker/config.rb, line 109 def max_retries @max_retries ||= DEFAULT_MAX_RETRY_ATTEMPTS end
The operating mode.
- :production => process tasks via GCP Cloud Task. - :development => process tasks locally via Redis.
@return [<Type>] <description>
# File lib/cloudtasker/config.rb, line 120 def mode @mode ||= environment == 'development' ? :development : :production end
Return a Proc invoked whenever a worker DeadWorkerError
is raised. See Cloudtasker::WorkerHandler.with_worker_handling
@return [Proc] A Proc handler
# File lib/cloudtasker/config.rb, line 257 def on_dead @on_dead || DEFAULT_ON_ERROR end
Return a Proc invoked whenever a worker runtime error is raised. See Cloudtasker::WorkerHandler.with_worker_handling
@return [Proc] A Proc handler
# File lib/cloudtasker/config.rb, line 247 def on_error @on_error || DEFAULT_ON_ERROR end
The hostname of the application processing the workers. The hostname must be reachable from Cloud Task.
@return [String] The processor host.
# File lib/cloudtasker/config.rb, line 177 def processor_host @processor_host || raise(StandardError, PROCESSOR_HOST_MISSING) end
Set the processor host. In the context of Rails the host will also be added to the list of authorized Rails hosts.
@param [String] val The processor host to set.
# File lib/cloudtasker/config.rb, line 158 def processor_host=(val) @processor_host = val # Check if Rails supports host filtering return unless val && defined?(Rails) && Rails.application.config.respond_to?(:hosts) && Rails.application.config.hosts&.any? # Add processor host to the list of authorized hosts Rails.application.config.hosts << val.gsub(%r{https?://}, '') end
The path on the host when worker payloads will be sent. Default to `/cloudtasker/run`
@return [String] The processor path
# File lib/cloudtasker/config.rb, line 188 def processor_path @processor_path || DEFAULT_PROCESSOR_PATH end
Return the full URL of the processor. Worker
payloads will be sent to this URL.
@return [String] The processor URL.
# File lib/cloudtasker/config.rb, line 148 def processor_url File.join(processor_host, processor_path) end
Return the threshold above which job arguments must be stored in Redis instead of being sent to the backend as part of the job payload.
Return nil if redis payload storage is disabled.
@return [Integer, nil] The threshold above which payloads will be stored in Redis.
# File lib/cloudtasker/config.rb, line 96 def redis_payload_storage_threshold return nil unless store_payloads_in_redis store_payloads_in_redis.respond_to?(:to_i) ? store_payloads_in_redis.to_i : 0 end
Return the secret to use to sign the verification tokens attached to tasks.
@return [String] The cloudtasker secret
# File lib/cloudtasker/config.rb, line 235 def secret @secret ||= ( defined?(Rails) && Rails.application.credentials&.dig(:secret_key_base) ) || raise(StandardError, SECRET_MISSING_ERROR) end
Return the chain of server middlewares.
@return [Cloudtasker::Middleware::Chain] The chain of middlewares.
# File lib/cloudtasker/config.rb, line 277 def server_middleware @server_middleware ||= Middleware::Chain.new yield @server_middleware if block_given? @server_middleware end