Skip to content
Browse files

check for connections less frequently

  • Loading branch information...
1 parent 7c53f8d commit 666c0848ea7ddd33e477726ac1d37e2186ae1329 @gnufied committed Jun 23, 2008
Showing with 12 additions and 8 deletions.
  1. +1 −1 lib/backgroundrb/rails_worker_proxy.rb
  2. +11 −7 server/lib/meta_worker.rb
View
2 lib/backgroundrb/rails_worker_proxy.rb
@@ -33,7 +33,7 @@ def choose_method worker_method,data
elsif worker_method =~ /^enq_(\w+)/i
method_name = $1
args = Marshal.dump([data[0]])
- options = data[1]
+ options = data[1] || {}
middle_man.enqueue_task(compact(:worker_name => worker_name.to_s,:worker_key => worker_key.to_s,:worker_method => method_name.to_s,:job_key => job_key.to_s, :args => args,:timeout => options[:timeout]))
else
middle_man.send_request(compact(:worker => worker_name,:worker_key => worker_key,:worker_method => worker_method,:job_key => job_key,:arg => data))
View
18 server/lib/meta_worker.rb
@@ -262,20 +262,15 @@ def check_for_enqueued_tasks
end
def check_for_timer_events
- begin
- ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord)
- super
- rescue
- logger.info($!.to_s)
- logger.info($!.backtrace.join("\n"))
- end
+ super
check_for_enqueued_tasks
return if @worker_method_triggers.nil? or @worker_method_triggers.empty?
@worker_method_triggers.delete_if { |key,value| value[:trigger].respond_to?(:end_time) && value[:trigger].end_time <= Time.now }
@worker_method_triggers.each do |key,value|
time_now = Time.now.to_i
if value[:runtime] < time_now
+ check_db_connection
begin
(t_data = value[:data]) ? send(key,t_data) : send(key)
rescue
@@ -288,6 +283,15 @@ def check_for_timer_events
end
end
+ def check_db_connection
+ begin
+ ActiveRecord::Base.verify_active_connections! if defined?(ActiveRecord)
+ rescue
+ logger.info($!.to_s)
+ logger.info($!.backtrace.join("\n"))
+ end
+ end
+
# method would allow user threads to run exclusively for a while
def run_user_threads
@thread_pool.exclusive_run

0 comments on commit 666c084

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