[Backgroundrb-devel] Need help in passing parameters to a background job method
Raghu Srinivasan
raghu.srinivasan at gmail.com
Wed Apr 9 19:46:57 EDT 2008
<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
More information about the Backgroundrb-devel
mailing list