Skip to content

Instantly share code, notes, and snippets.

@georgewhewell
Created May 7, 2018 13:29
Show Gist options
  • Save georgewhewell/2323c643a9b22ffc2c16358aff6b4692 to your computer and use it in GitHub Desktop.
Save georgewhewell/2323c643a9b22ffc2c16358aff6b4692 to your computer and use it in GitHub Desktop.
defmodule MyApp.Application do
# See https://hexdocs.pm/elixir/Application.html
# for more information on OTP Applications
@moduledoc false
use Application
use Supervisor
def start(_type, _args) do
children = [
# Only children automatically started are required for all operation
# modes- otherwise use start_/1 functions
supervisor(MyApp.Repo, []),
]
opts = [strategy: :one_for_one, name: __MODULE__]
Supervisor.start_link(children, opts)
end
def start_recorder, do: Supervisor.start_child(__MODULE__, {Task.Supervisor, name: MyApp.RecordingSupervisor})
def start_metrics do
Supervisor.start_child(__MODULE__, Plug.Adapters.Cowboy.child_spec(:http, MyApp.MetricsExporter, [], port: 50010))
end
end
defmodule Mix.Tasks.Listen do
use Mix.Task
@shortdoc "Starts application with webserver and metrics"
def run(_) do
Application.ensure_all_started(:myapp)
MyApp.Application.start_metrics()
MyApp.Application.start_recorder()
Process.sleep(:infinity)
end
end
### inserts very slow, eventual timeout
14:28:52.090 [debug] QUERY OK db=3950.4ms decode=3.0ms
defmodule Mix.Tasks.Listen do
use Mix.Task
@shortdoc "Starts application with webserver and metrics"
def run(_) do
Mix.Task.run "app.start"
MyApp.Application.start_metrics()
MyApp.Application.start_recorder()
Process.sleep(:infinity)
end
end
### inserts work ok
14:26:25.285 [debug] QUERY OK db=3.6ms
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment