Refactor dets repo, dockerfile, and url type; add logger level func

This commit is contained in:
mitchell 2019-12-15 23:20:21 -05:00
parent faaf12ba42
commit fe413d2a5e
5 changed files with 19 additions and 6 deletions

View File

@ -1,6 +1,6 @@
FROM elixir:1.9-slim as build
WORKDIR /root/shortnr/service
WORKDIR /root/shortnr
COPY . .
RUN mix local.hex --force
@ -11,7 +11,7 @@ RUN env MIX_ENV=prod mix release
FROM debian:buster-20191014-slim
WORKDIR /home/shortnr
COPY --from=build /root/shortnr/service/_build/prod/rel/service/ .
COPY --from=build /root/shortnr/_build/prod/rel/service/ .
RUN apt-get update && apt-get install -y --no-install-recommends \
libtinfo5=6.1+20181013-2+deb10u2 \

View File

@ -5,4 +5,9 @@ config :service,
config :logger, :console,
format: "date=$date time=$time level=$level$levelpad message=\"$message\" $metadata\n",
metadata: [:port, :file, :line, :crash_reason, :stack]
metadata: [:port, :file, :line, :crash_reason, :stack],
level:
(fn
:prod -> :info
_ -> :debug
end).(Mix.env())

View File

@ -46,7 +46,7 @@ defmodule Shortnr.Router do
end
def handle_errors(conn, %{kind: _kind, reason: reason, stack: stack}) do
Logger.error(inspect(reason), stack: inspect(stack))
Logger.error(reason, stack: stack)
{:error, {:internal_server_error, "internal server error"}, conn}
|> Text.encode_response()

View File

@ -3,7 +3,10 @@ defmodule Shortnr.URL.Repo.DETS do
@impl true
def get(key) do
{:ok, :dets.lookup(:urls, key) |> List.first() |> elem(1)}
case :dets.lookup(:urls, key) |> List.first() do
{_, url} -> {:ok, url}
nil -> {:ok, nil}
end
end
@impl true

View File

@ -8,7 +8,12 @@ defmodule Shortnr.URL do
updated_at: DateTime.utc_now(),
url: %URI{}
@type t :: %__MODULE__{id: String.t(), url: URI.t()}
@type t :: %__MODULE__{
id: String.t(),
url: URI.t(),
created_at: DateTime.t(),
updated_at: DateTime.t()
}
@spec create(String.t(), module()) :: {:ok, String.t()} | Transport.error()
def create(url, repo) do