Skip to content

Commit

Permalink
Merge commit 'origin/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
gnufied committed Mar 28, 2009
2 parents c8fdeef + fd50495 commit 2d38299
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions lib/backgroundrb/bdrb_job_queue.rb
Expand Up @@ -5,6 +5,7 @@ class BdrbJobQueue < ActiveRecord::Base
# find next task from the table
def self.find_next(worker_name,worker_key = nil)
returned_job = nil
ActiveRecord::Base.verify_active_connections!
transaction do
unless worker_key
#use ruby time stamps for time calculations as db might have different times than what is calculated by ruby/rails
Expand All @@ -25,6 +26,7 @@ def self.find_next(worker_name,worker_key = nil)
# release a job and mark it to be unfinished and free.
# useful, if inside a worker, processing of this job failed and you want it to process later
def release_job
ActiveRecord::Base.verify_active_connections!
self.class.transaction do
self.taken = 0
self.started_at = nil
Expand All @@ -34,6 +36,7 @@ def release_job

# insert a new job for processing. jobs added will be automatically picked by the appropriate worker
def self.insert_job(options = { })
ActiveRecord::Base.verify_active_connections!
transaction do
options.merge!(:submitted_at => Time.now.utc,:finished => 0,:taken => 0)
t_job = new(options)
Expand All @@ -43,6 +46,7 @@ def self.insert_job(options = { })

# remove a job from table
def self.remove_job(options = { })
ActiveRecord::Base.verify_active_connections!
transaction do
t_job_id = find(:first, :conditions => options.merge(:finished => 0,:taken => 0),:lock => true)
delete(t_job_id)
Expand All @@ -51,6 +55,7 @@ def self.remove_job(options = { })

# Mark a job as finished
def finish!
ActiveRecord::Base.verify_active_connections!
self.class.transaction do
self.finished = 1
self.finished_at = Time.now.utc
Expand Down

0 comments on commit 2d38299

Please sign in to comment.