Skip to content

Commit

Permalink
Isolate gen token task (#530)
Browse files Browse the repository at this point in the history
* Warn if cache is down

Instead of crashing because the cache is down, only emit a warning. This
is going to lead to problem when we go multi node, but by that time, I
hope the cache usage will also be re-evaluated instead of used for
*everything*.

* gen_token task doesn't require the entire app to be started

This allow to generate a token without having to stop the app because of
a port conflict.
  • Loading branch information
geekingfrog authored Nov 24, 2024
1 parent d648b5d commit f437b73
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions lib/teiserver/helpers/cache_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ defmodule Teiserver.Helpers.CacheHelper do
"cluster_hooks",
{:cluster_hooks, :delete, Node.self(), table, keys}
)
catch
:exit, :noproc ->
Logger.warning("Cache #{table} is down")
end

def cache_delete(table, key), do: cache_delete(table, [key])
Expand All @@ -48,6 +51,9 @@ defmodule Teiserver.Helpers.CacheHelper do
"cluster_hooks",
{:cluster_hooks, :put, Node.self(), table, key, value}
)
catch
:exit, :noproc ->
Logger.warning("Cache #{table} is down")
end

@doc """
Expand Down
3 changes: 2 additions & 1 deletion lib/teiserver/mix_tasks/gen_token.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ defmodule Mix.Tasks.Teiserver.GenToken do
{parsed, _, _errors} = OptionParser.parse(args, strict: [user: :string, app: :string])
shell.info("parsed args: #{inspect(parsed)}")

Mix.Task.run("ecto.setup")
Application.ensure_all_started([:ecto, :ecto_sql, :tzdata])
Teiserver.Repo.start_link()

case parsed[:user] do
nil ->
Expand Down

0 comments on commit f437b73

Please sign in to comment.