Module: Delayed::Settings
- Defined in:
- lib/delayed/settings.rb
Constant Summary collapse
- SETTINGS =
[ :default_job_options, :disable_periodic_jobs, :disable_automatic_orphan_unlocking, :fetch_batch_size, :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, :worker_health_check_type, :worker_health_check_config, :worker_procname_prefix, ]
- SETTINGS_WITH_ARGS =
[ :num_strands ]
- 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
- @@parent_process =
PARENT_PROCESS_DEFAULTS.dup
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=(new_config) ⇒ Object
- .parent_process_client_timeout=(val) ⇒ Object
- .queue=(queue_name) ⇒ Object
- .worker_config(config_filename = nil) ⇒ Object
- .worker_health_check_config=(new_config) ⇒ Object
Class Method Details
.apply_worker_config!(config) ⇒ Object
95 96 97 98 99 100 101 |
# File 'lib/delayed/settings.rb', line 95 def self.apply_worker_config!(config) SETTINGS.each do |setting| self.send("#{setting}=", config[setting.to_s]) if config.key?(setting.to_s) end parent_process.client_timeout = config['parent_process_client_timeout'] if config.key?('parent_process_client_timeout') self.parent_process = config['parent_process'] if config.key?('parent_process') end |
.default_worker_config_name ⇒ Object
103 104 105 |
# File 'lib/delayed/settings.rb', line 103 def self.default_worker_config_name ("config/delayed_jobs.yml") end |
.expand_rails_path(path) ⇒ Object
Expands rails-relative paths, without depending on rails being loaded.
108 109 110 111 112 113 114 115 |
# File 'lib/delayed/settings.rb', line 108 def self.(path) root = if defined?(Rails) && Rails.root (Rails.root+"Gemfile").to_s else ENV.fetch('BUNDLE_GEMFILE', Dir.pwd+"/Gemfile") end File.("../#{path}", root) end |
.parent_process=(new_config) ⇒ Object
121 122 123 124 |
# File 'lib/delayed/settings.rb', line 121 def self.parent_process=(new_config) raise 'Parent process configurations must be a hash!' unless Hash === new_config @@parent_process = PARENT_PROCESS_DEFAULTS.merge(new_config) end |
.parent_process_client_timeout=(val) ⇒ Object
117 118 119 |
# File 'lib/delayed/settings.rb', line 117 def self.parent_process_client_timeout=(val) parent_process['server_socket_timeout'] = Integer(val) end |
.queue=(queue_name) ⇒ Object
53 54 55 56 |
# File 'lib/delayed/settings.rb', line 53 def self.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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/delayed/settings.rb', line 77 def self.worker_config(config_filename = nil) config_filename ||= default_worker_config_name config = YAML.load(ERB.new(File.read(config_filename)).result) env = defined?(RAILS_ENV) ? RAILS_ENV : 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 && 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
126 127 128 |
# File 'lib/delayed/settings.rb', line 126 def self.worker_health_check_config=(new_config) @@worker_health_check_config = (new_config || {}).with_indifferent_access end |