Class: CycloneLariat::Repo::Sequel::InboxMessages

Inherits:
Object
  • Object
show all
Defined in:
lib/cyclone_lariat/repo/sequel/inbox_messages.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset) ⇒ InboxMessages

Returns a new instance of InboxMessages.



14
15
16
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 14

def initialize(dataset)
  @dataset = dataset
end

Instance Attribute Details

#datasetObject (readonly)

Returns the value of attribute dataset.



12
13
14
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 12

def dataset
  @dataset
end

Instance Method Details

#create(msg) ⇒ Object



26
27
28
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 26

def create(msg)
  dataset.insert Mappers::InboxMessages.to_row(msg)
end

#disabled?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 22

def disabled?
  dataset.nil?
end

#each_unprocessedObject



48
49
50
51
52
53
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 48

def each_unprocessed
  dataset.where(processed_at: nil).each do |row|
    msg = build Mappers::InboxMessages.from_row(row)
    yield(msg)
  end
end

#each_with_client_errorsObject



55
56
57
58
59
60
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 55

def each_with_client_errors
  dataset.where { (processed_at !~ nil) & (client_error_message !~ nil) }.each do |row|
    msg = build Mappers::InboxMessages.from_row(row)
    yield(msg)
  end
end

#enabled?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 18

def enabled?
  !dataset.nil?
end

#exists?(uuid:) ⇒ Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 30

def exists?(uuid:)
  dataset.where(uuid: uuid).limit(1).any?
end

#find(uuid:) ⇒ Object



41
42
43
44
45
46
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 41

def find(uuid:)
  row = dataset.where(uuid: uuid).first
  return if row.nil?

  build Mappers::InboxMessages.from_row(row)
end

#processed!(uuid:, error: nil) ⇒ Object



34
35
36
37
38
39
# File 'lib/cyclone_lariat/repo/sequel/inbox_messages.rb', line 34

def processed!(uuid:, error: nil)
  data = { processed_at: ::Sequel.function(:NOW) }
  data.merge!(client_error_message: error.message, client_error_details: JSON.generate(error.details)) if error

  !dataset.where(uuid: uuid).update(data).zero?
end