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

Jonathan Wallace jonathan.wallace at gmail.com
Fri Jan 30 01:28:37 EST 2009


"Notifier" in my code is a reference to ARMailer.  You'll still need to use
that to send an email message from within rails or backgroundrb.

Of course, persisting the jobs to a database table means that you could use
something much lighter than backgroundrb (due to it loading a large portion
of rails).  For example, you could have a plain ruby script that accesses
the database and just uses TMail or an equivalent perl script.  And then you
could use cron to schedule the script.

 Jonathan

On Fri, Jan 30, 2009 at 12:56 AM, Ramon Tayag <ramon.tayag at gmail.com> wrote:

> Ahh, yes I understand more.  I might not need to use ARMailer?  I'll
> just save things into the QueuedEmails table, let backgroundrb read
> that and if it finds something, email it.
>
> Thanks!  Much clearer now.
> Ramon Tayag
>
>
>
> On Fri, Jan 30, 2009 at 12:39 PM, Jonathan Wallace
> <jonathan.wallace at gmail.com> wrote:
> > 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",
> >    t.timestamps
> > end
> >
> > #model
> > class QueuedEmail < ActiveRecord::Base
> > end
> >
> > #worker
> > 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) }
> >      emails.destroy!
> >   end
> >
> > #bdrb config file
> > :backgroundrb:
> >   :ip: 0.0.0.0
> >   :port: 1234
> >   :environment: production
> > :schedules:
> >   :email_processing_worker:
> >     :send_emails:
> >      :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,
> >
> >  Jonathan
> >
> > 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/20090130/4ee749cf/attachment.html>


More information about the Backgroundrb-devel mailing list