Skip to content
Browse files

Merge branch 'per_worker_config' into glyde_stable

  • Loading branch information...
2 parents 83b4f14 + e7e694b commit e619c14f06e281790ae2cf8895f5a39eb893b40b Seth Morabito committed Oct 23, 2008
Showing with 32 additions and 3 deletions.
  1. +32 −3 server/lib/meta_worker.rb
View
35 server/lib/meta_worker.rb
@@ -128,11 +128,21 @@ def worker_init
create_arity = method(:create).arity
(create_arity == 0) ? create : create(worker_options[:data])
end
- return if BDRB_CONFIG[:backgroundrb][:persistent_disabled]
- delay = BDRB_CONFIG[:backgroundrb][:persistent_delay] || 5
- add_periodic_timer(delay.to_i) { check_for_enqueued_tasks }
+ if run_persistent_jobs?
+ add_periodic_timer(delay.to_i) { check_for_enqueued_tasks }
+ end
end
+ # Returns the persistent job queue check delay for this worker
+ def persistent_delay
+ get_config_value(:persistent_delay, 5)
+ end
+
+ # Returns true if persistent jobs should be run for this worker.
+ def run_persistent_jobs?
+ !get_conig_value(:persistent_disabled, false)
+ end
+
# return job key from thread global variable
def job_key; Thread.current[:job_key]; end
@@ -332,6 +342,25 @@ def check_db_connection
end
private
+
+ # Returns the local configuration hash for this worker. Returns an
+ # empty hash if no local config exists.
+ def worker_config
+ if BDRB_CONFIG[:workers] && BDRB_CONFIG[:workers][worker_name.to_sym]
+ BDRB_CONFIG[:workers][worker_name.to_sym]
+ else
+ {}
+ end
+ end
+
+ # Returns the appropriate configuration value, based on both the
+ # global config and the per-worker configuration for this worker.
+ def get_config_value(key_sym, default)
+ worker_config[key_sym] ||
+ BDRB_CONFIG[:backgroundrb][key_sym] ||
+ default
+ end
+
def load_rails_env
db_config_file = YAML.load(ERB.new(IO.read("#{RAILS_HOME}/config/database.yml")).result)
run_env = ENV["RAILS_ENV"]

0 comments on commit e619c14

Please sign in to comment.
Something went wrong with that request. Please try again.