[Backgroundrb-devel] Something I just don't understand about the workers and job_key

Carl Pelletier carl at 2be.ca
Thu Jan 15 07:58:17 EST 2009

Hi everyone, I will try to be concise as possible to explain my  
problem. I building a admin section on my site to manage all my ruby  
scripts. I want to remove the script from cron and put them in  
backgroundrb so every admin user can start/stop those scripts when  
they want.

So the script start first from the scheduler(yml) to be sure they run  
each day. The way I understand bgrb, less worker is better. So I would  
like to reuse the worker started from the scheduler in my rails admin  
to start again the task sync_ezdeal.

I have a worker started from backgroundrb.yml file like this:
  :port: 11006
  :result_storage: memcache

:memcache: "localhost:11211,localhost:11211"

      :trigger_args: 0 30 3 * * * *
#This script run each night at 3:30.

My Worker:

class EzdealWorker < BackgrounDRb::MetaWorker
  set_worker_name :ezdeal_worker
  pool_size 1

def sync_ezdeal(args = nil)
	.... #do job
	cache[:filename] = xml_file # This is the filename of a generated xml  
file that the job sync_ezdeal build and save on disk. This filename  
must be unique each time the task sync_ezdeal is called. So i can look  
at the file from the admin site.

My call in the controller to start a new job is that:
=>current_time, :arg =>{:filename=>current_time,:local =>'/Users/carl/ 

The job is queued correctly but when I try to get the :filename that  
doesnt work.

This is my view:

@tasks = BdrbJobQueue.find(:all,:order =>'id DESC')
@tasks.each do |task|
    <td width="5%" align="center"><%=h task.id%></td>
    <td width="20%"><%=h task.worker_method %></td>
    <td width="20%"><%=h time_ago_in_words(task.submitted_at) %></td>
    <td width="20%"><%=h time_ago_in_words(task.started_at) unless  
    <td width="20%"><%=h time_ago_in_words(task.finished_at) if  
task.finished? %></td>
    <td width="20%"><%=h task.finished? %></td>
      <td width="20%" align="right">
        <!-- Action td -->
(MiddleMan.worker(task.worker_name).ask_result(:filename)) if
##### This is were i retreive the filename from the worker. This  
should came from the database?no? like task.args[:filename]

I don't known how to fetch the filename for each job (with the  
job_key??). Because the ask_result is alway overright when I start a  
new job. The way I understand it is the cache array is the same for  
all workers of the same type. so the cache[:filename] is overight each  
time the sync_ezdeal is called. I tried by creating a new worker each  
time, it's working, but that look overkill to me.

Is there a way to retreive the good key?

I saw in the database the field args that old the data push in the  
cache array. Is there a way to retreive it? Because currently the data  
look to have strange character in it. In the database it's a binary  
object.. Not sure what to do with that...

ex:args           |  

Thanks for any help!

I hope I am clear enough!

Carl Pelletier

More information about the Backgroundrb-devel mailing list