Class: RailwayIpc::ConsumedMessage

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
lib/railway_ipc/models/consumed_message.rb

Constant Summary collapse

STATUS_SUCCESS =
'success'
STATUS_PROCESSING =
'processing'
STATUS_IGNORED =
'ignored'
STATUS_UNKNOWN_MESSAGE_TYPE =
'unknown_message_type'
STATUS_FAILED_TO_PROCESS =
'failed_to_process'
VALID_STATUSES =
[
  STATUS_SUCCESS,
  STATUS_PROCESSING,
  STATUS_IGNORED,
  STATUS_UNKNOWN_MESSAGE_TYPE,
  STATUS_FAILED_TO_PROCESS
].freeze

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#decoded_messageObject (readonly)

Returns the value of attribute decoded_message.



19
20
21
# File 'lib/railway_ipc/models/consumed_message.rb', line 19

def decoded_message
  @decoded_message
end

Class Method Details

.create_processing(consumer, incoming_message) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/railway_ipc/models/consumed_message.rb', line 26

def self.create_processing(consumer, incoming_message)
  # rubocop:disable Style/RedundantSelf
  self.create!(
    uuid: incoming_message.uuid,
    status: STATUS_PROCESSING,
    message_type: incoming_message.type,
    user_uuid: incoming_message.user_uuid,
    correlation_id: incoming_message.correlation_id,
    queue: consumer.queue_name,
    exchange: consumer.exchange_name,
    encoded_message: incoming_message.payload
  )
  # rubocop:enable Style/RedundantSelf
end

Instance Method Details

#processed?Boolean

Returns:

  • (Boolean)


49
50
51
52
53
# File 'lib/railway_ipc/models/consumed_message.rb', line 49

def processed?
  # rubocop:disable Style/RedundantSelf
  self.status == STATUS_SUCCESS
  # rubocop:enable Style/RedundantSelf
end

#update_with_lock(job) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/railway_ipc/models/consumed_message.rb', line 41

def update_with_lock(job)
  with_lock('FOR UPDATE NOWAIT') do
    job.run
    self.status = job.status
    save
  end
end