Class: CodexNotify::DurableSlackPublisher
- Inherits:
-
Object
- Object
- CodexNotify::DurableSlackPublisher
- Defined in:
- lib/codex_notify/durable_slack_publisher.rb
Instance Attribute Summary collapse
-
#queued_ids ⇒ Object
readonly
Returns the value of attribute queued_ids.
Instance Method Summary collapse
- #drain ⇒ Object
- #ensure_thread(key:, root_message:) ⇒ Object
-
#initialize(client:, store:, outbox:, channel:, throttle_sec: 0.0) ⇒ DurableSlackPublisher
constructor
A new instance of DurableSlackPublisher.
- #key(namespace, identity) ⇒ Object
- #publish_reply(key:, message:, recovery_root_message:) ⇒ Object
- #publish_root_or_reply(key:, message:) ⇒ Object
- #publish_standalone(key:, message:) ⇒ Object
- #reset(key:) ⇒ Object
Constructor Details
#initialize(client:, store:, outbox:, channel:, throttle_sec: 0.0) ⇒ DurableSlackPublisher
Returns a new instance of DurableSlackPublisher.
9 10 11 12 13 14 15 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 9 def initialize(client:, store:, outbox:, channel:, throttle_sec: 0.0) @store = store @outbox = outbox @channel = channel @worker = SlackDeliveryWorker.new(outbox:, client:, store:, inter_message_delay: throttle_sec) @queued_ids = [] end |
Instance Attribute Details
#queued_ids ⇒ Object (readonly)
Returns the value of attribute queued_ids.
17 18 19 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 17 def queued_ids @queued_ids end |
Instance Method Details
#drain ⇒ Object
45 46 47 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 45 def drain @worker.drain(channel: @channel) end |
#ensure_thread(key:, root_message:) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 23 def ensure_thread(key:, root_message:) return if @store.thread_ts_for(key) return if @outbox.pending_root?(key, generation: @store.generation_for(key)) enqueue(key:, action: :ensure_thread, message: ) end |
#key(namespace, identity) ⇒ Object
49 50 51 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 49 def key(namespace, identity) Digest::SHA256.hexdigest("#{namespace}\0#{identity}") end |
#publish_reply(key:, message:, recovery_root_message:) ⇒ Object
34 35 36 37 38 39 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 34 def publish_reply(key:, message:, recovery_root_message:) has_root = @store.thread_ts_for(key) || @outbox.pending_root?(key, generation: @store.generation_for(key)) return unless has_root enqueue(key:, action: :reply, message:, recovery_root_message: || ) end |
#publish_root_or_reply(key:, message:) ⇒ Object
30 31 32 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 30 def publish_root_or_reply(key:, message:) enqueue(key:, action: :root_or_reply, message:, recovery_root_message: ) end |
#publish_standalone(key:, message:) ⇒ Object
19 20 21 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 19 def publish_standalone(key:, message:) enqueue(key:, action: :standalone, message:) end |
#reset(key:) ⇒ Object
41 42 43 |
# File 'lib/codex_notify/durable_slack_publisher.rb', line 41 def reset(key:) @store.advance_generation(key) end |