Class: RenoteDac::Mailer::Client
- Inherits:
-
Object
- Object
- RenoteDac::Mailer::Client
- Defined in:
- lib/renote_dac/mailer.rb
Instance Method Summary collapse
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #process_batch(size = 100) ⇒ Object
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
52 53 54 55 56 57 58 59 |
# File 'lib/renote_dac/mailer.rb', line 52 def initialize @client = Postmark::ApiClient.new( RenoteDac.configuration.postmark_api_key, http_read_timeout: 20, http_open_timeout: 10, secure: true ) end |
Instance Method Details
#process_batch(size = 100) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/renote_dac/mailer.rb', line 61 def process_batch(size = 100) batch = Mailer.get_batch(size) return 0 if batch.empty? ids = [] = [] batch.each do |pending| template = pending[BATCH_TEMPLATE] params = pending[BATCH_PARAMS] = Mailer.(template) ids << pending[BATCH_ID] << { from: RenoteDac.configuration.from_address, to: pending[BATCH_EMAIL], template_id: [:template_id], template_model: params, tag: template } end if Rails.env.production? responses = @client.deliver_in_batches() handle_resp(ids, responses) else .each do || puts "Sending message... #{[:to]}" end # Dummy sending RenoteDac::Email.where(id: ids).update_all(error: 0) # Live sending # # if you must send messages for real in development to make sure the # templates look good, do it with care, because this uses the same # server as in production. Don't send 5,000 emails on accident or # Sidney will personally find you. # # responses = @client.deliver_in_batches(messages) # puts responses.inspect # handle_resp(ids, responses) end batch.size end |