14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/codex_notify/outbox_commands.rb', line 14
def run(action:, id:, outbox_dir:, token:, channel:, state_file:, stdout:, stderr:)
outbox = SlackOutbox.new(outbox_dir)
case action
when :status
outbox.status_rows.each { |row| stdout.puts(JSON.generate(row)) }
0
when :retry
outbox.retry(id)
0
when :drain
unless token && channel
stderr.puts('ERROR: draining the outbox requires Slack token and channel configuration')
return 2
end
store = HookStore.new(state_file)
result = SlackDeliveryWorker.new(
outbox:,
client: SlackClient.new(token:, channel:),
store:
).drain(channel:)
failed = result.failed.any? || result.needs_review.any?
stderr.puts('ERROR: Slack delivery requires outbox review; run --outbox-status') if failed
failed ? 1 : 0
end
rescue SlackOutbox::Error => e
stderr.puts("ERROR: #{e.message}")
1
end
|