Module: Delayed::Settings
- Defined in:
- lib/delayed/settings.rb
Constant Summary collapse
- SETTINGS =
[ :default_job_options, :disable_abandoned_job_cleanup, :disable_periodic_jobs, :disable_automatic_orphan_unlocking, :fetch_batch_size, # this is a transitional setting, so that you don't have a time where a # singleton switches to using the singleton column, but there are old # jobs that only used strand :infer_strand_from_singleton, :kill_workers_on_exit, :last_ditch_logfile, :max_attempts, :pool_procname_suffix, :queue, :select_random_from_batch, :silence_periodic_log, :sleep_delay, :sleep_delay_stagger, :slow_exit_timeout, :stranded_run_at_grace_period, :worker_health_check_type, :worker_health_check_config, :worker_procname_prefix ].freeze
- SETTINGS_WITH_ARGS =
%i[ job_detailed_log_format job_short_log_format num_strands ].freeze
- PARENT_PROCESS_DEFAULTS =
{ server_socket_timeout: 10.0, prefetched_jobs_timeout: 30.0, client_connect_timeout: 2.0, # We'll accept a partial, relative path and assume we want it inside # Rails.root with inst-jobs.sock appended if provided a directory. server_address: "tmp" }.with_indifferent_access.freeze
Class Attribute Summary collapse
-
.parent_process ⇒ Object
Returns the value of attribute parent_process.
Class Method Summary collapse
- .apply_worker_config!(config) ⇒ Object
- .default_worker_config_name ⇒ Object
-
.expand_rails_path(path) ⇒ Object
Expands rails-relative paths, without depending on rails being loaded.
- .parent_process_client_timeout=(val) ⇒ Object
- .queue=(queue_name) ⇒ Object
- .worker_config(config_filename = nil) ⇒ Object
- .worker_health_check_config=(new_config) ⇒ Object
Class Attribute Details
.parent_process ⇒ Object
Returns the value of attribute parent_process.
54 55 56 |
# File 'lib/delayed/settings.rb', line 54 def parent_process @parent_process end |
Class Method Details
.apply_worker_config!(config) ⇒ Object
89 90 91 92 93 94 95 96 97 |
# File 'lib/delayed/settings.rb', line 89 def apply_worker_config!(config) SETTINGS.each do |setting| send("#{setting}=", config[setting.to_s]) if config.key?(setting.to_s) end if config.key?("parent_process_client_timeout") parent_process.client_timeout = config["parent_process_client_timeout"] end self.parent_process = config["parent_process"] if config.key?("parent_process") end |
.default_worker_config_name ⇒ Object
99 100 101 |
# File 'lib/delayed/settings.rb', line 99 def default_worker_config_name ("config/delayed_jobs.yml") end |
.expand_rails_path(path) ⇒ Object
Expands rails-relative paths, without depending on rails being loaded.
104 105 106 107 108 109 110 111 |
# File 'lib/delayed/settings.rb', line 104 def (path) root = if defined?(Rails) && Rails.root Rails.root.join("Gemfile") else ENV.fetch("BUNDLE_GEMFILE", "#{Dir.pwd}/Gemfile") end File.("../#{path}", root) end |
.parent_process_client_timeout=(val) ⇒ Object
113 114 115 |
# File 'lib/delayed/settings.rb', line 113 def parent_process_client_timeout=(val) parent_process["server_socket_timeout"] = Integer(val) end |
.queue=(queue_name) ⇒ Object
65 66 67 68 69 |
# File 'lib/delayed/settings.rb', line 65 def queue=(queue_name) raise ArgumentError, "queue_name must not be blank" if queue_name.blank? @queue = queue_name end |
.worker_config(config_filename = nil) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/delayed/settings.rb', line 71 def worker_config(config_filename = nil) config_filename ||= default_worker_config_name config = YAML.load(ERB.new(File.read(config_filename)).result) env = Rails.env || "development" config = config[env] || config["default"] # Backwards compatibility from when the config was just an array of queues config = { workers: config } if config.is_a?(Array) unless config.is_a?(Hash) raise ArgumentError, "Invalid config file #{config_filename}" end config = config.with_indifferent_access config[:workers].map! do |worker_config| config.except(:workers).merge(worker_config.with_indifferent_access) end config end |
.worker_health_check_config=(new_config) ⇒ Object
123 124 125 |
# File 'lib/delayed/settings.rb', line 123 def worker_health_check_config=(new_config) @worker_health_check_config = (new_config || {}).with_indifferent_access end |