class MailRoom::Delivery::Que

Que Delivery method @author Tony Pitale

Constants

Options

Attributes

options[R]

Public Class Methods

new(options) click to toggle source

Build a new delivery, hold the mailbox configuration @param [MailRoom::Delivery::Que::Options]

# File lib/mail_room/delivery/que.rb, line 29
def initialize(options)
  @options = options
end

Public Instance Methods

deliver(message) click to toggle source

deliver the message by pushing it onto the configured Sidekiq queue @param message [String] the email message as a string, RFC822 format

# File lib/mail_room/delivery/que.rb, line 35
def deliver(message)
  queue_job(message)
end

Private Instance Methods

connection() click to toggle source
# File lib/mail_room/delivery/que.rb, line 40
def connection
  PG.connect(connection_options)
end
connection_options() click to toggle source
# File lib/mail_room/delivery/que.rb, line 44
def connection_options
  {
    host: options.host,
    port: options.port,
    dbname: options.database,
    user: options.username,
    password: options.password
  }
end
queue_job(*args) click to toggle source
# File lib/mail_room/delivery/que.rb, line 54
def queue_job(*args)
  sql = "INSERT INTO que_jobs (priority, job_class, queue, args) VALUES ($1, $2, $3, $4)"

  connection.exec(sql, [options.priority, options.job_class, options.queue, JSON.dump(args)])
end