Class: MailSpy::Email
- Inherits:
-
Object
- Object
- MailSpy::Email
- Includes:
- Mongoid::Document, Mongoid::Timestamps
- Defined in:
- app/models/mail_spy/email.rb
Constant Summary collapse
- @@template_cache =
{}
Class Method Summary collapse
Instance Method Summary collapse
- #deliver ⇒ Object
- #html_erb ⇒ Object
-
#parsed_html_content ⇒ Object
Great for debugging emails.
- #parsed_text_content ⇒ Object
- #template_values ⇒ Object
- #text_erb ⇒ Object
Class Method Details
.deliver_batch(current_time, start_id, offset, total, step = 200, num_threads = 100) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/mail_spy/email.rb', line 78 def self.deliver_batch(current_time, start_id, offset, total, step=200, num_threads=100) wq = WorkQueue.new(num_threads, step*2) processed = 0 while true emails = self.where( :schedule_at.lte => current_time, :sent => false, :failed => false, :_id.gt => start_id ).limit(step).offset(offset) break if total >= processed || emails.blank? emails.each do |email| wq.enqueue_b do email.deliver end end processed += emails.count end wq.join processed end |
Instance Method Details
#deliver ⇒ Object
101 102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/mail_spy/email.rb', line 101 def deliver begin MailSpy::CoreMailer.template(self).deliver self.update_attribute(:sent, true) rescue Exception => e self.failed = true self. = e.try(:message) self.error_backtrace = e.try(:backtrace) self.save! end end |
#html_erb ⇒ Object
70 71 72 |
# File 'app/models/mail_spy/email.rb', line 70 def html_erb load_template("html.erb") end |
#parsed_html_content ⇒ Object
Great for debugging emails
62 63 64 |
# File 'app/models/mail_spy/email.rb', line 62 def parsed_html_content return MailSpy::CoreMailer.template(self).html_part.body.to_s end |
#parsed_text_content ⇒ Object
66 67 68 |
# File 'app/models/mail_spy/email.rb', line 66 def parsed_text_content return MailSpy::CoreMailer.template(self).text_part.body.to_s end |
#template_values ⇒ Object
57 58 59 |
# File 'app/models/mail_spy/email.rb', line 57 def template_values self.read_attribute(:template_values).try(:with_indifferent_access) end |
#text_erb ⇒ Object
74 75 76 |
# File 'app/models/mail_spy/email.rb', line 74 def text_erb load_template("text.erb") end |