Skip to content

Commit

Permalink
Merge pull request #67 from otakulan/feature/tgh/otp-26-elixir-1.15
Browse files Browse the repository at this point in the history
Upgrade to OTP 26, Elixir 1.15 and fix warns
  • Loading branch information
starcraft66 authored Sep 10, 2023
2 parents 8073cde + f9004ae commit 6cfeb26
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 64 deletions.
30 changes: 15 additions & 15 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@
devenv.shells.default = let
inherit (pkgs.lib) optional optionals;
erlang = pkgs.beam.interpreters.erlangR25;
elixir = pkgs.beam.packages.erlangR25.elixir_1_14;
rebar = pkgs.beam.packages.erlangR25.rebar3;
elixir = pkgs.beam.packages.erlangR26.elixir_1_15;
rebar = pkgs.rebar3;
nodejs = pkgs.nodejs_20;
in {
services.postgres = {
Expand Down
1 change: 0 additions & 1 deletion lib/lanpartyseating/logic/autoassign_logic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ defmodule Lanpartyseating.AutoAssignLogic do
alias Lanpartyseating.LastAssignedSeat, as: LastAssignedStation
alias Lanpartyseating.SettingsLogic, as: SettingsLogic
alias Lanpartyseating.StationLogic, as: StationLogic
alias Lanpartyseating.Station, as: Station
alias Lanpartyseating.Repo, as: Repo

def register_station(uid) do
Expand Down
2 changes: 1 addition & 1 deletion lib/lanpartyseating/logic/reservation_logic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ defmodule Lanpartyseating.ReservationLogic do
end
end

def cancel_reservation(id, station_number, reason) do
def cancel_reservation(id, reason) do
Reservation
|> where(station_id: ^id)
|> where([v], is_nil(v.deleted_at))
Expand Down
2 changes: 1 addition & 1 deletion lib/lanpartyseating/logic/station_logic.ex
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ defmodule Lanpartyseating.StationLogic do
end)
end

def get_station_status(station, now \\ DateTime.utc_now()) do
def get_station_status(station) do
case station do
%Station{is_closed: true} ->
%{status: :broken, reservation: nil}
Expand Down
6 changes: 3 additions & 3 deletions lib/lanpartyseating/repositories/station_status_repo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ defmodule Lanpartyseating.StationStatus do

@doc false
def changeset(reservation, attrs) do
#reservation
#|> cast(attrs, [:station_id, :tournament_id])
#|> validate_required([:station_id, :tournament_id])
reservation
|> cast(attrs, [:station_id, :tournament_id])
|> validate_required([:station_id, :tournament_id])
end
end
23 changes: 5 additions & 18 deletions lib/lanpartyseating/tasks/expire_tournament.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
defmodule Lanpartyseating.Tasks.ExpireTournament do
use GenServer, restart: :transient
import Ecto.Query
require Logger
alias Lanpartyseating.StationLogic
alias Lanpartyseating.Tournament, as: Tournament
alias Lanpartyseating.Repo, as: Repo
alias Lanpartyseating.PubSub, as: PubSub

def start_link(arg) do
Expand All @@ -30,21 +27,11 @@ defmodule Lanpartyseating.Tasks.ExpireTournament do
def handle_info(:expire_tournament, tournament_id) do
Logger.debug("Expiring tournament #{tournament_id}")

tournament =
from(t in Tournament,
where: t.id == ^tournament_id,
join: tr in assoc(t, :tournament_reservations),
join: s in assoc(tr, :station),
preload: [tournament_reservations: {tr, station: s}]
) |> Repo.one()

Enum.map(tournament.tournament_reservations, fn reservation ->
Phoenix.PubSub.broadcast(
PubSub,
"station_update",
{:stations, StationLogic.get_all_stations()}
)
end)
Phoenix.PubSub.broadcast(
PubSub,
"station_update",
{:stations, StationLogic.get_all_stations()}
)

{:stop, :normal, tournament_id}
end
Expand Down
28 changes: 8 additions & 20 deletions lib/lanpartyseating/tasks/start_tournament.ex
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
defmodule Lanpartyseating.Tasks.StartTournament do
use GenServer, restart: :transient
import Ecto.Query
require Logger
alias Lanpartyseating.StationLogic
alias Lanpartyseating.Tournament, as: Tournament
alias Lanpartyseating.Repo, as: Repo
alias Lanpartyseating.PubSub, as: PubSub

def start_link(arg) do
Expand All @@ -16,35 +13,26 @@ defmodule Lanpartyseating.Tasks.StartTournament do
def init({start_date, tournament_id}) do
delay = DateTime.diff(start_date, DateTime.truncate(DateTime.utc_now(), :second), :millisecond) |> max(0)
Logger.debug("Starting tournament #{tournament_id} in #{delay} milliseconds")
Process.send_after(self(), :expire_tournament, delay)
Process.send_after(self(), :start_tournament, delay)
{:ok, tournament_id}
end

@impl true
def handle_cast(:terminate, state) do
Logger.debug("Terminating reservation expiration task for #{state}")
Logger.debug("Terminating reservation start task for #{state}")
{:stop, :normal, state}
end

@impl true
def handle_info(:expire_tournament, tournament_id) do
def handle_info(:start_tournament, tournament_id) do
Logger.debug("Starting tournament #{tournament_id}")

tournament =
from(t in Tournament,
where: t.id == ^tournament_id,
join: tr in assoc(t, :tournament_reservations),
join: s in assoc(tr, :station),
preload: [tournament_reservations: {tr, station: s}]
) |> Repo.one()
Phoenix.PubSub.broadcast(
PubSub,
"station_update",
{:stations, StationLogic.get_all_stations()}
)

Enum.map(tournament.tournament_reservations, fn reservation ->
Phoenix.PubSub.broadcast(
PubSub,
"station_update",
{:stations, StationLogic.get_all_stations()}
)
end)
{:stop, :normal, tournament_id}
end
end
5 changes: 2 additions & 3 deletions lib/lanpartyseating_web/live/cancellation_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,18 @@ defmodule LanpartyseatingWeb.CancellationLive do

socket =
socket
|> assign(:registration_error, nil)
|> assign(:registration_error, registration_error)

{:noreply, socket}
end

def handle_event(
"cancel_station",
%{"station_id" => id, "station_number" => station_number, "cancel_reason" => reason},
%{"station_id" => id, "station_number" => _station_number, "cancel_reason" => reason},
socket
) do
ReservationLogic.cancel_reservation(
String.to_integer(id),
String.to_integer(station_number),
reason
)

Expand Down

0 comments on commit 6cfeb26

Please sign in to comment.