Class: Chore::Publisher

Inherits:
Object
  • Object
show all
Defined in:
lib/chore/publisher.rb

Overview

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

Constant Summary collapse

DEFAULT_OPTIONS =
{ :encoder => Encoder::JsonEncoder }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Publisher

Returns a new instance of Publisher.

Parameters:

  • opts (Hash) (defaults to: {})


9
10
11
# File 'lib/chore/publisher.rb', line 9

def initialize(opts={})
  self.options = DEFAULT_OPTIONS.merge(opts)
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



6
7
8
# File 'lib/chore/publisher.rb', line 6

def options
  @options
end

Class Method Details

.publish(queue_name, job) ⇒ Object

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.

Parameters:

  • queue_name (String)

    Name of queue to be consumed from

  • job (Hash)

    Job instance definition, will be encoded to JSON



18
19
20
# File 'lib/chore/publisher.rb', line 18

def self.publish(queue_name,job)
  self.new.publish(queue_name,job)
end

.reset_connection!Object

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)



32
33
# File 'lib/chore/publisher.rb', line 32

def self.reset_connection!
end

Instance Method Details

#publish(queue_name, job) ⇒ Object

Publishes a message to queue

Parameters:

  • queue_name (String)

    Name of the SQS queue

  • job (Hash)

    Job instance definition, will be encoded to JSON

Raises:

  • (NotImplementedError)


26
27
28
# File 'lib/chore/publisher.rb', line 26

def publish(queue_name,job)
  raise NotImplementedError
end