Skip to content

Commit 6a010b6

Browse files
committed
Add missing send_message method to puzzle inventory job
1 parent 3573d52 commit 6a010b6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

app/jobs/puzzle_inventory_check_job.rb

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ class PuzzleInventoryCheckJob < ApplicationJob
33
retry_on StandardError, attempts: 3
44

55
def perform
6-
approved_unsent_puzzle_count = Puzzle.where(state: 0, sent_at: nil).count
6+
approved_puzzle_count = Puzzle.where(state: 0).count
77

8-
if approved_unsent_puzzle_count < 5
9-
send_low_inventory_notification(approved_unsent_puzzle_count)
8+
if approved_puzzle_count < 5
9+
send_low_inventory_notification(approved_puzzle_count)
1010
end
1111
end
1212

@@ -16,4 +16,10 @@ def send_low_inventory_notification(count)
1616
notification_message = SlackClient::Messages::LowPuzzleInventoryNotification.new(count).create
1717
send_message(notification_message, channel_id: ENV.fetch("SHIELD_NOTIFICATIONS_CHANNEL", nil))
1818
end
19+
20+
def send_message(message, channel_id:)
21+
SlackClient::Client.instance.chat_postMessage(channel: channel_id, blocks: message)
22+
rescue Slack::Web::Api::Errors::SlackError
23+
head :unprocessable_entity
24+
end
1925
end

0 commit comments

Comments
 (0)