Class: Chore::UnitOfWork

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

Overview

Simple class to hold job processing information. Has six attributes:

  • :id The queue implementation specific identifier for this message.

  • :receipt_handle The queue implementation specific identifier for the receipt of this message.

  • :queue_name The name of the queue the job came from

  • :queue_timeout The time (in seconds) before the job will get re-enqueued if not processed

  • :message The actual data of the message.

  • :previous_attempts The number of times the work has been attempted previously.

  • :consumer The consumer instance used to fetch this message. Most queue implementations won't need access to this, but some (RabbitMQ) will. So we

make sure to pass it along with each message. This instance will be used by the Worker for things like complete and </tt>reject</tt>.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeUnitOfWork

:nodoc:



16
17
18
19
# File 'lib/chore/unit_of_work.rb', line 16

def initialize(*) #:nodoc:
  super
  @created_at = Time.now
end

Instance Attribute Details

#consumerObject

Returns the value of attribute consumer

Returns:

  • (Object)

    the current value of consumer



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def consumer
  @consumer
end

#created_atObject

The time at which this unit of work was created



14
15
16
# File 'lib/chore/unit_of_work.rb', line 14

def created_at
  @created_at
end

#decoded_messageObject

Returns the value of attribute decoded_message

Returns:

  • (Object)

    the current value of decoded_message



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def decoded_message
  @decoded_message
end

#idObject

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def id
  @id
end

#klassObject

Returns the value of attribute klass

Returns:

  • (Object)

    the current value of klass



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def klass
  @klass
end

#messageObject

Returns the value of attribute message

Returns:

  • (Object)

    the current value of message



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def message
  @message
end

#previous_attemptsObject

Returns the value of attribute previous_attempts

Returns:

  • (Object)

    the current value of previous_attempts



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def previous_attempts
  @previous_attempts
end

#queue_nameObject

Returns the value of attribute queue_name

Returns:

  • (Object)

    the current value of queue_name



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def queue_name
  @queue_name
end

#queue_timeoutObject

Returns the value of attribute queue_timeout

Returns:

  • (Object)

    the current value of queue_timeout



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def queue_timeout
  @queue_timeout
end

#receipt_handleObject

Returns the value of attribute receipt_handle

Returns:

  • (Object)

    the current value of receipt_handle



12
13
14
# File 'lib/chore/unit_of_work.rb', line 12

def receipt_handle
  @receipt_handle
end

Instance Method Details

#current_attemptObject

The current attempt number for the worker processing this message.



22
23
24
# File 'lib/chore/unit_of_work.rb', line 22

def current_attempt
  previous_attempts + 1
end