Skip to content

Commit b95b6ed

Browse files
committed
Small refactor
1 parent c4ef55a commit b95b6ed

2 files changed

Lines changed: 6 additions & 1 deletion

File tree

app/jobs/puzzle_inventory_check_job.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,17 @@ def perform
1313
private
1414

1515
def send_low_inventory_notification(count)
16+
channel_id = ENV["SHIELD_NOTIFICATIONS_CHANNEL"]
17+
return Rails.logger.warn("SHIELD_NOTIFICATIONS_CHANNEL is not configured, skipping low inventory notification") unless channel_id
18+
1619
notification_message = SlackClient::Messages::LowPuzzleInventoryNotification.new(count).create
17-
send_message(notification_message, channel_id: ENV.fetch("SHIELD_NOTIFICATIONS_CHANNEL", nil))
20+
send_message(notification_message, channel_id: channel_id)
1821
end
1922

2023
def send_message(message, channel_id:)
2124
SlackClient::Client.instance.chat_postMessage(channel: channel_id, blocks: message)
2225
rescue Slack::Web::Api::Errors::SlackError => e
26+
Sentry.capture_exception(e)
2327
Rails.logger.error "Failed to send Slack message: #{e.message} #{e.response_metadata}"
2428
end
2529
end

test/jobs/puzzle_inventory_check_job_test.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
class PuzzleInventoryCheckJobTest < ActiveJob::TestCase
44
setup do
55
Puzzle.approved.where(sent_at: nil).delete_all
6+
ENV["SHIELD_NOTIFICATIONS_CHANNEL"] = "test-channel"
67
end
78

89
test "sends notification when fewer than 5 approved unsent puzzles exist" do

0 commit comments

Comments
 (0)