Class: MandrillQueue::Worker

Inherits:
Object
  • Object
show all
Extended by:
Hooks
Includes:
Logging, MandrillApi, Sidekiq::Worker
Defined in:
lib/mandrill_queue/worker.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Hooks

on_failure_logging

Methods included from Logging

#log_results, #logger, #pretty, #result_formatter

Methods included from MandrillApi

#configuration, #mandrill

Class Method Details

.perform(*args) ⇒ Object



42
43
44
# File 'lib/mandrill_queue/worker.rb', line 42

def self.perform(*args)
	new.perform(*args)
end

Instance Method Details

#ip_poolObject



13
14
15
# File 'lib/mandrill_queue/worker.rb', line 13

def ip_pool
	"Default Pool"
end

#perform(data) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mandrill_queue/worker.rb', line 17

def perform(data)
	@_mailer = Mailer.new(data)
	logger.debug("Got mailer data: #{pretty(@_mailer.to_hash)}")

	message = @_mailer.message.load_attachments!.to_hash
	template = @_mailer.template
	send_at = @_mailer.send_at

	result = if template.nil?
		mandrill.messages.send(message, false, ip_pool, send_at)
	else
		content = @_mailer.content.to_key_value_array
		mandrill.messages.send_template(template, content, message, ip_pool, send_at)
	end
  rescue Mandrill::Error => e
    logger.error("A mandrill error occurred: #{e.class} - #{e.message}")
    raise
  else
    if result.nil?
      logger.error("No messages sent!")
    else
      log_results(result)
    end
end