forked from thurloat/dough
parent
49b26be43e
commit
c23178c0f0
@ -1,26 +1,33 @@ |
|||||||
defmodule Dough.RequestContext do |
defmodule Dough.RequestContext do |
||||||
require Logger |
require Logger |
||||||
|
|
||||||
|
|
||||||
defstruct [:start, :close, :lookup, :cache, :ttl] |
defstruct [:start, :close, :lookup, :cache, :ttl] |
||||||
|
|
||||||
def ctx_start(ctx) do |
def ctx_start(ctx) do |
||||||
Map.put(ctx, :start, System.monotonic_time(:milliseconds)) |
Map.put(ctx, :start, System.monotonic_time(:milliseconds)) |
||||||
end |
end |
||||||
|
|
||||||
def ctx_close(ctx) do |
def ctx_close(ctx) do |
||||||
Map.put(ctx, :close, System.monotonic_time(:milliseconds)) |
Map.put(ctx, :close, System.monotonic_time(:milliseconds)) |
||||||
end |
end |
||||||
|
|
||||||
def ctx_lookup(ctx, dns_record) do |
def ctx_lookup(ctx, dns_record) do |
||||||
Map.put(ctx, :lookup, dns_record.qdlist |> List.first()) |
Map.put(ctx, :lookup, dns_record.qdlist |> List.first()) |
||||||
end |
end |
||||||
|
|
||||||
def ctx_cachehit(ctx, v) do |
def ctx_cachehit(ctx, v) do |
||||||
Map.put(ctx, :cache, v) |
Map.put(ctx, :cache, v) |
||||||
end |
end |
||||||
|
|
||||||
def ctx_ttl(ctx, ttl) do |
def ctx_ttl(ctx, ttl) do |
||||||
Map.put(ctx, :ttl, ttl) |
Map.put(ctx, :ttl, ttl) |
||||||
end |
end |
||||||
|
|
||||||
def ctx_log_out(ctx) do |
def ctx_log_out(ctx) do |
||||||
Logger.info "#{ctx.lookup.type} - #{ctx.lookup.domain} - TTL #{ctx.ttl} | #{ctx.cache} - #{ctx.close - ctx.start}ms" |
Logger.info( |
||||||
|
"#{ctx.lookup.type} - #{ctx.lookup.domain} - TTL #{ctx.ttl} | #{ctx.cache} - #{ |
||||||
|
ctx.close - ctx.start |
||||||
|
}ms" |
||||||
|
) |
||||||
end |
end |
||||||
end |
end |
||||||
|
@ -1,13 +1,13 @@ |
|||||||
defmodule Dough.NotAllowed do |
defmodule Dough.NotAllowed do |
||||||
defexception [plug_status: 405, message: "Method Not Allowed"] |
defexception plug_status: 405, message: "Method Not Allowed" |
||||||
end |
end |
||||||
|
|
||||||
defmodule Dough.ServerError do |
defmodule Dough.ServerError do |
||||||
defexception [plug_status: 500, message: "Server Error"] |
defexception plug_status: 500, message: "Server Error" |
||||||
end |
end |
||||||
|
|
||||||
defimpl Plug.Exception, for: [Dough.NotAllowed, Dough.ServerError] do |
defimpl Plug.Exception, for: [Dough.NotAllowed, Dough.ServerError] do |
||||||
def status(exc) do |
def status(exc) do |
||||||
exc.plug_status |
exc.plug_status |
||||||
end |
end |
||||||
end |
end |
||||||
|
Loading…
Reference in new issue