[Backgroundrb-devel] Doing max of N tasks per given time

Jonathan Wallace jonathan.wallace at gmail.com
Thu Jan 29 23:39:23 EST 2009

Hi Ramon,

I think he means persisting emails to a database table that acts as a queue
for your emails.  Make the logic in the worker only process 250 elements in
your database table.

For example,
#db table
create_table "queued_emails", :force => true do |t|
   t.string "subject",
   t.string "body",
   t.string "to",

class QueuedEmail < ActiveRecord::Base

class EmailProcessingWorker < BackgrounDRb::MetaWorker
  set_worker_name :email_processing_worker
  def create(args = nil); end
  def send_emails
     emails = QueuedEmail.find(:all, :order => "created_on", :limit => 250)
     emails.each {|e| Notifier.send_email(e) }

#bdrb config file
  :port: 1234
  :environment: production
     :trigger_args: 0 * */1 * * *

You'd need to write the Notifier class which inherits from AR::Mailer and
use at your own risk, etc.  This code is just a toss off and most definitely
contains deficiencies but gets the idea across.

Hope this helps,


On Thu, Jan 29, 2009 at 9:25 PM, Ramon Tayag <ramon.tayag at gmail.com> wrote:

> Hi Dale!  I suppose by table you mean something like ar_mailer?
> Thanks,
> Ramon Tayag
> On Fri, Jan 30, 2009 at 10:13 AM, Dale Cook <petesalty at gmail.com> wrote:
> > Ramon,
> >
> > What I would do is push all the records that need to be mailed to a table
> > (or flag them in a table they already reside in). Then you can have BDRB
> set
> > up to run once an hour - it picks up the most recent (or the oldest, or
> some
> > other combination, your choice) and mails them, 250 each hour until there
> > are none left. You can add in records whenever you want, confident that
> they
> > will go out eventually.
> > Trying to do it another way, i.e. sending out 250, then setting up a
> > schedule to send out the rest, could be done but it's a lot harder and
> > probably doesn't get you much more, especially for the 251st and onward
> > email recipients, plus you then have to deal with the issue of that
> happens
> > if you need to send another batch of 250+ within an hour of the first
> being
> > sent - what to do then?
> >
> > You can read more about BDRB cron scheduling at
> > http://backgroundrb.rubyforge.org/scheduling/ (this isn't one of my
> > strengths unfortunately).
> >
> > Hope this helped some.
> > Dale
> _______________________________________________
> Backgroundrb-devel mailing list
> Backgroundrb-devel at rubyforge.org
> http://rubyforge.org/mailman/listinfo/backgroundrb-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/backgroundrb-devel/attachments/20090129/9528f7bb/attachment.html>

More information about the Backgroundrb-devel mailing list