public
Description: Deliver email to local db and have it send by sequel_sendmail later. Attempt at a clone of ar_mailer for merb + sequel.
Clone URL: git://github.com/bricooke/sequel_mailer.git
Search Repo:
Now the --once is verified to be working
bricooke (author)
Sat Mar 15 19:38:01 -0700 2008
commit  86137a94f79e2772e53c092a4b1e29e1903719f4
tree    86a18f0055430aefd3bcdf7a3509325ba512b3b2
parent  d039d176883b1ef37c2ee94d2b3ab208587fe1b4
...
401
402
403
404
 
405
406
407
408
...
410
411
412
 
 
413
414
415
416
417
418
 
419
420
421
422
423
...
470
471
472
473
 
474
475
 
 
 
476
477
 
478
479
480
...
491
492
493
494
 
495
496
497
...
401
402
403
 
404
405
406
407
408
...
410
411
412
413
414
415
416
417
418
419
 
420
421
422
423
424
425
...
472
473
474
 
475
476
 
477
478
479
480
 
481
482
483
484
...
495
496
497
 
498
499
500
501
0
@@ -401,7 +401,7 @@
0
     return if @max_age == 0
0
     timeout = Time.now - @max_age
0
     conditions = ['last_send_attempt > 0 and created_on < ?', timeout]
0
- mail = @email_class.destroy_all conditions
0
+ mail = @email_class.find(conditions).delete rescue []
0
 
0
     log "expired #{mail.length} emails from the queue"
0
   end
0
0
@@ -410,12 +410,14 @@
0
   # Delivers +emails+ to Merb::Mailer's SMTP server and destroys them.
0
 
0
   def deliver(emails)
0
+ raise "You must setup Merb::Mailer.config" if Merb::Mailer.config.nil?
0
+
0
     user = Merb::Mailer.config[:user] || Merb::Mailer.config[:user_name]
0
     Net::SMTP.start Merb::Mailer.config[:host],
0
                     Merb::Mailer.config[:port],
0
                     Merb::Mailer.config[:domain],
0
                     user,
0
- Merb::Mailer.config[:password],
0
+ Merb::Mailer.config[:pass],
0
                     Merb::Mailer.config[:auth],
0
                     Merb::Mailer.config[:tls] do |smtp|
0
       @failed_auth_count = 0
0
0
0
@@ -470,11 +472,13 @@
0
   # last 300 seconds.
0
 
0
   def find_emails
0
- options = { :conditions => ['last_send_attempt < ?', Time.now.to_i - 300] }
0
+
0
     options[:limit] = batch_size unless batch_size.nil?
0
- mail = @email_class.find :all, options
0
+ query = @email_class.filter("last_send_attempt < #{Time.now.to_i - 300}")
0
+ query.limit(batch_size) unless batch_size.nil?
0
+ mail = query.all
0
 
0
- log "found #{mail.length} emails to send"
0
+ log "found #{mail.size} emails to send"
0
     mail
0
   end
0
 
0
@@ -491,7 +495,7 @@
0
 
0
   def log(message)
0
     $stderr.puts message if @verbose
0
- ActionMailer::Base.logger.info "ar_sendmail: #{message}"
0
+ Merb.logger.info "ar_sendmail: #{message}"
0
   end
0
 
0
   ##

Comments

    No one has commented yet.