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

Ramon Tayag ramon.tayag at gmail.com
Fri Jan 30 00:56:43 EST 2009


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
>
>


More information about the Backgroundrb-devel mailing list