[Backgroundrb-devel] Persistent queue and scheduled jobs

Chetan Sarva csarva at operative.com
Tue Sep 23 19:35:49 EDT 2008


While playing with scheduled jobs, I ran into a couple of issues and  
made a few notes.

1) Times MUST be UTC:

I've got the following:

     	BdrbJobQueue.insert_job(:worker_name => 'backup_worker',
     	                        :worker_method => 'do_work',
     	                        :args => @backup.id,
     	                        :scheduled_at => Time.now + 30)

resulting in:

   submitted_at: 2008-09-23 17:57:26
     started_at: 2008-09-23 17:57:30
    finished_at: NULL
    archived_at: NULL
   scheduled_at: 2008-09-23 17:57:56

changing it to Time.now.utc + 30 fixes it.

2. job_key is mandatory when using the persistent queue since there is  
a unique key check on this field. This was not immediately obvious,  
and no key is automatically generated. The above code inserts NULL for  

I can submit doc patches for the above if that helps.

3. When firing the job at the scheduled time, MetaWorker calls  
Marshal.load() on `args` though they were not previously marshalled by  
ActiveRecord. I made the following change in my WC in order to move  
passed this problem:

Index: vendor/plugins/backgroundrb/server/lib/meta_worker.rb
--- vendor/plugins/backgroundrb/server/lib/meta_worker.rb        
(revision 114)
+++ vendor/plugins/backgroundrb/server/lib/meta_worker.rb        
(working copy)
@@ -287,10 +287,9 @@
          Thread.current[:persistent_job_id] = task[:id]
          Thread.current[:job_key] = task[:job_key]
          called_method_arity = self.method(task.worker_method).arity
-        args = load_data(task.args)
            if called_method_arity != 0
-            self.send(task.worker_method,args)
+            self.send(task.worker_method,task.args)



More information about the Backgroundrb-devel mailing list