Class: CycloneLariat::Outbox::Repo::Sequel::Messages
- Inherits:
-
Object
- Object
- CycloneLariat::Outbox::Repo::Sequel::Messages
- Defined in:
- lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb
Constant Summary collapse
- LIMIT =
1000
Instance Attribute Summary collapse
-
#dataset ⇒ Object
readonly
Returns the value of attribute dataset.
Instance Method Summary collapse
- #create(msg) ⇒ Object
- #delete(uuid) ⇒ Object
- #each_with_error ⇒ Object
-
#initialize(dataset) ⇒ Messages
constructor
A new instance of Messages.
- #lock(uuid) ⇒ Object
- #transaction(&block) ⇒ Object
- #update_error(uuid, error_message) ⇒ Object
Constructor Details
#initialize(dataset) ⇒ Messages
Returns a new instance of Messages.
17 18 19 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 17 def initialize(dataset) @dataset = dataset end |
Instance Attribute Details
#dataset ⇒ Object (readonly)
Returns the value of attribute dataset.
15 16 17 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 15 def dataset @dataset end |
Instance Method Details
#create(msg) ⇒ Object
21 22 23 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 21 def create(msg) dataset.returning.insert(Outbox::Mappers::Messages.to_row(msg)).first[:uuid] end |
#delete(uuid) ⇒ Object
25 26 27 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 25 def delete(uuid) dataset.where(uuid: uuid).delete end |
#each_with_error ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 33 def each_with_error dataset .where { sending_error !~ nil } .order(::Sequel.asc(:created_at)) .limit(LIMIT) .each do |row| msg = build Outbox::Mappers::Messages.from_row(row) yield(msg) end end |
#lock(uuid) ⇒ Object
48 49 50 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 48 def lock(uuid) dataset.where(uuid: uuid).for_update.nowait end |
#transaction(&block) ⇒ Object
44 45 46 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 44 def transaction(&block) dataset.db.transaction(&block) end |
#update_error(uuid, error_message) ⇒ Object
29 30 31 |
# File 'lib/cyclone_lariat/plugins/outbox/repo/sequel/messages.rb', line 29 def update_error(uuid, ) dataset.where(uuid: uuid).update(sending_error: ) end |