Permalink
Browse files

use base encoding for utf thingies

  • Loading branch information...
1 parent 8e7af36 commit 741e775c4d8727041f98824671e1084a7a9addcd @gnufied committed Apr 10, 2009
Showing with 14 additions and 5 deletions.
  1. +14 −5 lib/backgroundrb/bdrb_job_queue.rb
@@ -5,7 +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!
+ 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
@@ -23,10 +23,19 @@ def self.find_next(worker_name,worker_key = nil)
returned_job
end
+ #these accessors get around any possible character encoding issues with the database
+ def args=(args)
+ write_attribute(:args, Base64.b64encode(args))
+ end
+
+ def args
+ Base64.decode64(read_attribute(:args))
+ end
+
# 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!
+ ActiveRecord::Base.verify_active_connections!
self.class.transaction do
self.taken = 0
self.started_at = nil
@@ -36,7 +45,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!
+ ActiveRecord::Base.verify_active_connections!
transaction do
options.merge!(:submitted_at => Time.now.utc,:finished => 0,:taken => 0)
t_job = new(options)
@@ -46,7 +55,7 @@ def self.insert_job(options = { })
# remove a job from table
def self.remove_job(options = { })
- ActiveRecord::Base.verify_active_connections!
+ 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)
@@ -55,7 +64,7 @@ def self.remove_job(options = { })
# Mark a job as finished
def finish!
- ActiveRecord::Base.verify_active_connections!
+ ActiveRecord::Base.verify_active_connections!
self.class.transaction do
self.finished = 1
self.finished_at = Time.now.utc

0 comments on commit 741e775

Please sign in to comment.