Class: CodexNotify::SlackDeliveryWorker
- Inherits:
-
Object
- Object
- CodexNotify::SlackDeliveryWorker
- Defined in:
- lib/codex_notify/slack_delivery_worker.rb
Defined Under Namespace
Classes: Result
Constant Summary collapse
- STALE_THREAD_CODES =
%w[thread_not_found message_not_found invalid_ts].freeze
- DRAIN_BUDGET =
10.0- MAX_IMMEDIATE_ATTEMPTS =
3- MAX_AMBIGUOUS_ATTEMPTS =
3- BACKOFF_CAP =
8.0
Instance Method Summary collapse
- #drain(channel:, budget: DRAIN_BUDGET) ⇒ Object
-
#initialize(outbox:, client:, store:, clock: -> { Time.now.utc }, monotonic_clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, sleeper: Kernel.method(:sleep), random: Random.new, inter_message_delay: 0.0) ⇒ SlackDeliveryWorker
constructor
A new instance of SlackDeliveryWorker.
Constructor Details
#initialize(outbox:, client:, store:, clock: -> { Time.now.utc }, monotonic_clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, sleeper: Kernel.method(:sleep), random: Random.new, inter_message_delay: 0.0) ⇒ SlackDeliveryWorker
Returns a new instance of SlackDeliveryWorker.
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/codex_notify/slack_delivery_worker.rb', line 16 def initialize(outbox:, client:, store:, clock: -> { Time.now.utc }, monotonic_clock: -> { Process.clock_gettime(Process::CLOCK_MONOTONIC) }, sleeper: Kernel.method(:sleep), random: Random.new, inter_message_delay: 0.0) @outbox = outbox @client = client @store = store @clock = clock @monotonic_clock = monotonic_clock @sleeper = sleeper @random = random @inter_message_delay = end |
Instance Method Details
#drain(channel:, budget: DRAIN_BUDGET) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/codex_notify/slack_delivery_worker.rb', line 28 def drain(channel:, budget: DRAIN_BUDGET) counts = { delivered: [], deferred: [], failed: [], needs_review: [] } locked = @outbox.try_drain_lock do deadline = monotonic_now + budget drain_jobs(channel.to_s, deadline, counts) end return Result.new(**counts) if locked counts[:deferred] = @outbox.jobs.select { |job| job['channel'] == channel.to_s }.map { |job| job['id'] } Result.new(**counts) end |