class Chore::Publisher

Base class for a Chore Publisher. Provides the interface that a Chore::Publisher implementation should adhere to.

Constants

DEFAULT_OPTIONS

Attributes

options[RW]

Public Class Methods

new(opts={}) click to toggle source

@param [Hash] opts

# File lib/chore/publisher.rb, line 9
def initialize(opts={})
  self.options = DEFAULT_OPTIONS.merge(opts)
end
publish(queue_name,job) click to toggle source

Publishes the provided job to the queue identified by the queue_name. Not designed to be used directly, this method ferries to the publish method on an instance of your configured Publisher.

@param [String] queue_name Name of queue to be consumed from @param [Hash] job Job instance definition, will be encoded to JSON

# File lib/chore/publisher.rb, line 18
def self.publish(queue_name,job)
  self.new.publish(queue_name,job)
end
reset_connection!() click to toggle source

Sets a flag that instructs the publisher to reset the connection the next time it's used. Should be overriden in publishers (but is not required)

# File lib/chore/publisher.rb, line 32
def self.reset_connection!
end

Public Instance Methods

publish(queue_name,job) click to toggle source

Publishes a message to queue

@param [String] queue_name Name of the SQS queue @param [Hash] job Job instance definition, will be encoded to JSON

# File lib/chore/publisher.rb, line 26
def publish(queue_name,job)
  raise NotImplementedError
end

Protected Instance Methods

encode_job(job) click to toggle source

Encodes the job class to format provided by endoder implementation

@param [Any] job

# File lib/chore/publisher.rb, line 40
def encode_job(job)
  options[:encoder].encode(job)
end