-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #708 from pil0u/main
Release 2024.11.8
- Loading branch information
Showing
18 changed files
with
237 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# frozen_string_literal: true | ||
|
||
class UpdatePuzzlesDifficultyJob < ApplicationJob | ||
queue_as :default | ||
|
||
def perform | ||
puzzles = Puzzle.where(is_difficulty_final: false) | ||
|
||
if puzzles.empty? | ||
Rails.logger.info "✔ No puzzle difficulty to update" | ||
return | ||
end | ||
|
||
client = Slack::Web::Client.new | ||
channel = "#aoc-dev" | ||
|
||
puzzles.each do |puzzle| | ||
day = puzzle.date.day | ||
url = URI("https://aoc-difficulty.ew.r.appspot.com/score?year=#{puzzle.date.year}&day=#{day}") | ||
|
||
Rails.logger.info "\tUpdating difficulty for day #{day}..." | ||
response = Net::HTTP.get_response(url) | ||
|
||
if response.code != "200" || response.body.include?("error") | ||
text = "⚠️ <@URZ0F4TEF> Error updating difficulty for day #{day} (#{response.code})" | ||
message = client.chat_postMessage(channel:, text:) | ||
client.chat_postMessage(channel:, thread_ts: message["message"]["ts"], text: "#{url}\n```#{response.body}```") | ||
next | ||
end | ||
|
||
data = JSON.parse(response.body) | ||
|
||
puzzle.update( | ||
difficulty_part_1: data["1"]["quartile"], | ||
difficulty_part_2: data["2"]["quartile"], | ||
is_difficulty_final: data["1"]["final"] && data["2"]["final"] | ||
) | ||
|
||
next unless puzzle.is_difficulty_final | ||
|
||
part_1 = Puzzle::DIFFICULTY_LEVELS[puzzle.difficulty_part_1] | ||
part_2 = Puzzle::DIFFICULTY_LEVELS[puzzle.difficulty_part_2] | ||
|
||
text = <<~TEXT | ||
Estimated difficulty for day #{day} (experimental feature): | ||
- part 1 is *`#{part_1[:difficulty]}`* #{part_1[:colour]} | ||
- part 2 is *`#{part_2[:difficulty]}`* #{part_2[:colour]} | ||
TEXT | ||
|
||
client.chat_postMessage(channel: ENV.fetch("SLACK_CHANNEL", "#aoc-dev"), text:) | ||
end | ||
|
||
Rails.logger.info "✔ Puzzle difficulties updated" | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.