Raghu Srinivasan
2008-Apr-09 23:46 UTC
[Backgroundrb-devel] Need help in passing parameters to a background job method
<backgroundrb-devel at rubyforge.org>I am trying to send email as a background process from within a Rails app. The goal is that when I go to http://mysite.com/foo/bar, the background job kicks in and sends an email out. The relevant code snippets are below. This errors out with a wrong number of arguments passed (2 for 1) message. I think I am making a mess of passing parameters to the email_admin method in the worker. How should I be passing multiple parameters to email_admin? Thanks =============================# Worker Code class PostalWorker < BackgrounDRb::MetaWorker set_worker_name :postal_worker def create # this method is called, when worker is loaded for the first time end def email_admin(p_subject,p_body) Emailer.deliver_send_info(p_subject,p_body,Time.now) end end =============================# Rails controller code class FooController < ApplicationController def bar worker = MiddleMan.worker(:postal_worker) result = worker.email_admin(''Some subject'',''And some body'') render :text => "Check your email " + Time.now.to_s end ===============================# Rails nodel code class Emailer < ActionMailer::Base def send_info(subject,message,sent_at = Time.now) @subject = subject @body = {:message => message} @recipients = ''raghu.srinivasan at gmail.com'' @from = '''' @sent_on = sent_at @headers = {} end end =====================================-------------- next part -------------- An HTML attachment was scrubbed... URL: http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20080409/4a680ad6/attachment.html
Ryan Leavengood
2008-Apr-10 00:45 UTC
[Backgroundrb-devel] Need help in passing parameters to a background job method
On Wed, Apr 9, 2008 at 7:46 PM, Raghu Srinivasan <raghu.srinivasan at gmail.com> wrote:> > This errors out with a wrong number of arguments passed (2 for 1) message. I > think I am making a mess of passing parameters to the email_admin method in > the worker. How should I be passing multiple parameters to email_admin?Worker methods are only supposed to have one argument, usually called args. If this needs to take multiple values, use a hash: def email_admin(args) Emailer.deliver_send_info(args[:p_subject],args[:p_body],Time.now) end Ryan