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:
---
:backgroundrb:
 :port: 11006
 :ip: 0.0.0.0
 :result_storage: memcache

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


:schedules:
 :ezdeal_worker:
   :sync_ezdeal:
     :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.
end

My call in the controller to start a new job is that:
MiddleMan.worker(:ezdeal_worker).enq_sync_ezdeal(:job_key =>current_time, :arg =>{:filename=>current_time,:local =>'/Users/carl/ gm_core/log/ezdeal/ezdeal.xml'})

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|
%>
 <tr>
   <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 task.started_at.blank?%></td> <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 -->
<%=link_to 'log_file ',ezdeal_log_file_admin_task_path (MiddleMan.worker(task.worker_name).ask_result(:filename)) if
task.finished?%>
##### This is were i retreive the filename from the worker. This should came from the database?no? like task.args[:filename]
     </td>
   </tr>
 <%end%>

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 | \004\010{\007:\015filename"\02414012009_155548:\012local"./Users/carl/ gm_core/log/ezdeal/ezdeal.xml

Thanks for any help!

I hope I am clear enough!

Carl Pelletier
_______________________________________________
Backgroundrb-devel mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/backgroundrb-devel

Reply via email to