Class: Tina4::QueueMessage
- Inherits:
-
Object
- Object
- Tina4::QueueMessage
- Defined in:
- lib/tina4/queue.rb
Instance Attribute Summary collapse
-
#attempts ⇒ Object
readonly
Returns the value of attribute attempts.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#status ⇒ Object
Returns the value of attribute status.
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
- #increment_attempts! ⇒ Object
-
#initialize(topic:, payload:, id: nil) ⇒ QueueMessage
constructor
A new instance of QueueMessage.
- #to_hash ⇒ Object
- #to_json(*_args) ⇒ Object
Constructor Details
#initialize(topic:, payload:, id: nil) ⇒ QueueMessage
Returns a new instance of QueueMessage.
10 11 12 13 14 15 16 17 |
# File 'lib/tina4/queue.rb', line 10 def initialize(topic:, payload:, id: nil) @id = id || SecureRandom.uuid @topic = topic @payload = payload @created_at = Time.now @attempts = 0 @status = :pending end |
Instance Attribute Details
#attempts ⇒ Object (readonly)
Returns the value of attribute attempts.
7 8 9 |
# File 'lib/tina4/queue.rb', line 7 def attempts @attempts end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/tina4/queue.rb', line 7 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
7 8 9 |
# File 'lib/tina4/queue.rb', line 7 def id @id end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
7 8 9 |
# File 'lib/tina4/queue.rb', line 7 def payload @payload end |
#status ⇒ Object
Returns the value of attribute status.
8 9 10 |
# File 'lib/tina4/queue.rb', line 8 def status @status end |
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
7 8 9 |
# File 'lib/tina4/queue.rb', line 7 def topic @topic end |
Instance Method Details
#increment_attempts! ⇒ Object
34 35 36 |
# File 'lib/tina4/queue.rb', line 34 def increment_attempts! @attempts += 1 end |
#to_hash ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tina4/queue.rb', line 19 def to_hash { id: @id, topic: @topic, payload: @payload, created_at: @created_at.iso8601, attempts: @attempts, status: @status } end |
#to_json(*_args) ⇒ Object
30 31 32 |
# File 'lib/tina4/queue.rb', line 30 def to_json(*_args) JSON.generate(to_hash) end |