declare queues on genserver init

This commit is contained in:
Álvaro 2024-05-04 01:10:21 +02:00
parent 080b18c6be
commit 420b693728
2 changed files with 3 additions and 2 deletions

View File

@ -6,10 +6,11 @@ defmodule Scrapper.Queue.MatchQueue do
GenServer.start_link(__MODULE__, {}, name: __MODULE__) GenServer.start_link(__MODULE__, {}, name: __MODULE__)
end end
@spec init({}) :: {:ok, {AMQP.Channel.t(), AMQP.Connection.t()}} @spec init({}) :: {:ok, %{channel: AMQP.Channel.t(), connection: AMQP.Connection.t()}}
def init({}) do def init({}) do
{:ok, connection} = AMQP.Connection.open() {:ok, connection} = AMQP.Connection.open()
{:ok, channel} = AMQP.Channel.open(connection) {:ok, channel} = AMQP.Channel.open(connection)
AMQP.Queue.declare(channel, "match", durable: true)
{:ok, %{:channel => channel, :connection => connection}} {:ok, %{:channel => channel, :connection => connection}}
end end

View File

@ -9,6 +9,7 @@ defmodule Scrapper.Queue.PlayerQueue do
def init(_opts) do def init(_opts) do
{:ok, connection} = AMQP.Connection.open() {:ok, connection} = AMQP.Connection.open()
{:ok, channel} = AMQP.Channel.open(connection) {:ok, channel} = AMQP.Channel.open(connection)
AMQP.Queue.declare(channel, "player", durable: true)
{:ok, {channel, connection}} {:ok, {channel, connection}}
end end
@ -18,7 +19,6 @@ defmodule Scrapper.Queue.PlayerQueue do
nil -> GenServer.call(__MODULE__, {:queue_player, puuid}) nil -> GenServer.call(__MODULE__, {:queue_player, puuid})
_ -> :already_processed _ -> :already_processed
end end
end end
def handle_call({:queue_player, puuid}, _from, {channel, _} = state) do def handle_call({:queue_player, puuid}, _from, {channel, _} = state) do