Class: AlchemyCrm::Delivery
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- AlchemyCrm::Delivery
- Defined in:
- app/models/alchemy_crm/delivery.rb
Instance Attribute Summary collapse
-
#chunk_delay ⇒ Object
Returns the value of attribute chunk_delay.
Class Method Summary collapse
Instance Method Summary collapse
- #delivered? ⇒ Boolean
-
#send_chunks(options = {}) ⇒ Object
Sending mails in chunks.
-
#send_mail_chunk(recipients_chunk, options) ⇒ Object
Send the mail chunk via delayed_job and waiting some time before next is enqueued.
Instance Attribute Details
#chunk_delay ⇒ Object
Returns the value of attribute chunk_delay.
5 6 7 |
# File 'app/models/alchemy_crm/delivery.rb', line 5 def chunk_delay @chunk_delay end |
Class Method Details
.settings(name) ⇒ Object
40 41 42 |
# File 'app/models/alchemy_crm/delivery.rb', line 40 def self.settings(name) AlchemyCrm::Config.get(name) end |
Instance Method Details
#delivered? ⇒ Boolean
15 16 17 |
# File 'app/models/alchemy_crm/delivery.rb', line 15 def delivered? !self.delivered_at.nil? end |
#send_chunks(options = {}) ⇒ Object
Sending mails in chunks.
20 21 22 23 24 25 26 27 28 |
# File 'app/models/alchemy_crm/delivery.rb', line 20 def send_chunks(={}) raise "No Mailing Given" if mailing.blank? @chunk_delay = 0 recipients.each_slice(self.class.settings(:send_mails_in_chunks_of)) do |recipients_chunk| send_mail_chunk(recipients_chunk, ) @chunk_delay += 1 end update_attribute(:delivered_at, Time.now) end |
#send_mail_chunk(recipients_chunk, options) ⇒ Object
Send the mail chunk via delayed_job and waiting some time before next is enqueued
32 33 34 35 36 37 |
# File 'app/models/alchemy_crm/delivery.rb', line 32 def send_mail_chunk(recipients_chunk, ) recipients_chunk.each do |recipient| mail = MailingsMailer.build(mailing, recipient, ).deliver recipient.update_attribute(:message_id, mail.) end end |