Skip to content
This repository has been archived by the owner on Jan 4, 2025. It is now read-only.

Commit

Permalink
Add support to delete errored replay
Browse files Browse the repository at this point in the history
  • Loading branch information
mrdotb committed Feb 7, 2024
1 parent 29409b5 commit 0e4ab18
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
16 changes: 15 additions & 1 deletion lib/lor/lol/pipeline/delete_replay_worker.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Lor.Lol.DeleteReplayWorker do
@moduledoc """
A recursive job to delete replay from specific patch.
A recursive job to delete replays.
"""
use Oban.Worker

Expand All @@ -20,4 +20,18 @@ defmodule Lor.Lol.DeleteReplayWorker do
:ok
end
end

def perform(%{args: %{"state" => state}}) do
case Lor.Lol.Replay.get_by_state(state) do
{:ok, replay} ->
Lor.Lol.Replay.destroy!(replay)

%{state: state}
|> new(schedule_in: @backfill_delay)
|> Oban.insert()

{:error, _not_found} ->
:ok
end
end
end
14 changes: 14 additions & 0 deletions lib/lor/lol/resources/replay/preparations/filter_by_state.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
defmodule Lor.Lol.Replay.Preparations.FilterByState do
use Ash.Resource.Preparation
require Ash.Query

def prepare(query, _, _) do
state = Ash.Changeset.get_argument(query, :state)

query
|> Ash.Query.load([:match, key_frames: :data, chunks: :data])
|> Ash.Query.filter(state == ^state)
|> Ash.Query.sort(inserted_at: :desc)
|> Ash.Query.limit(1)
end
end
9 changes: 9 additions & 0 deletions lib/lor/lol/resources/replay/replay.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ defmodule Lor.Lol.Replay do
args: [:platform_id, :game_id]

define :get_by_game_version, action: :get_by_game_version, args: [:game_version]
define :get_by_state, action: :get_by_state, args: [:state]
define :destroy
end

Expand Down Expand Up @@ -64,6 +65,14 @@ defmodule Lor.Lol.Replay do
prepare Lor.Lol.Replay.Preparations.FilterByGameVersion
end

read :get_by_state do
get? true

argument :state, :string, allow_nil?: false

prepare Lor.Lol.Replay.Preparations.FilterByState
end

update :finish do
accept [:first_chunk_id, :last_chunk_id, :first_key_frame_id, :last_key_frame_id]

Expand Down

0 comments on commit 0e4ab18

Please sign in to comment.