Module: Delayed::Settings
- Defined in:
- lib/delayed/settings.rb
Constant Summary collapse
- SETTINGS =
[ :queue, :max_attempts, :sleep_delay, :sleep_delay_stagger, :fetch_batch_size, :select_random_from_batch, :worker_procname_prefix, :pool_procname_suffix, :default_job_options, :silence_periodic_log, :disable_periodic_jobs, :disable_automatic_orphan_unlocking, :last_ditch_logfile, :parent_process_client_timeout, ]
- SETTINGS_WITH_ARGS =
[ :num_strands ]
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.
- .queue=(queue_name) ⇒ Object
- .worker_config(config_filename = nil) ⇒ Object
Class Method Details
.apply_worker_config!(config) ⇒ Object
70 71 72 73 74 |
# File 'lib/delayed/settings.rb', line 70 def self.apply_worker_config!(config) SETTINGS.each do |setting| self.send("#{setting}=", config[setting.to_s]) if config.key?(setting.to_s) end end |
.default_worker_config_name ⇒ Object
76 77 78 |
# File 'lib/delayed/settings.rb', line 76 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.
81 82 83 84 85 86 87 88 |
# File 'lib/delayed/settings.rb', line 81 def self.(path) root = if defined?(Rails) && Rails.root (Rails.root+"Gemfile").to_s else ENV.fetch('BUNDLE_GEMFILE') end File.("../#{path}", root) end |
.queue=(queue_name) ⇒ Object
35 36 37 38 |
# File 'lib/delayed/settings.rb', line 35 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
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/delayed/settings.rb', line 52 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 |