Class: Tina4::QueueMessage

Inherits:
Object
  • Object
show all
Defined in:
lib/tina4/queue.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#attemptsObject (readonly)

Returns the value of attribute attempts.



7
8
9
# File 'lib/tina4/queue.rb', line 7

def attempts
  @attempts
end

#created_atObject (readonly)

Returns the value of attribute created_at.



7
8
9
# File 'lib/tina4/queue.rb', line 7

def created_at
  @created_at
end

#idObject (readonly)

Returns the value of attribute id.



7
8
9
# File 'lib/tina4/queue.rb', line 7

def id
  @id
end

#payloadObject (readonly)

Returns the value of attribute payload.



7
8
9
# File 'lib/tina4/queue.rb', line 7

def payload
  @payload
end

#statusObject

Returns the value of attribute status.



8
9
10
# File 'lib/tina4/queue.rb', line 8

def status
  @status
end

#topicObject (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_hashObject



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