Browse Source

Separete metrics scheduling from job logic

undefined
Piotr Orzechowski 3 months ago
parent
commit
c25fd67cce

+ 14
- 0
ch10/todo_metrics/lib/todo/cron.ex View File

@@ -0,0 +1,14 @@
defmodule Todo.Cron do
use Task

def start_link(_) do
IO.puts("Starting cron")
Task.start_link(&loop/0)
end

defp loop() do
Process.sleep(:timer.seconds(10))
Todo.Metrics.start()
loop()
end
end

+ 5
- 12
ch10/todo_metrics/lib/todo/metrics.ex View File

@@ -1,21 +1,14 @@
defmodule Todo.Metrics do
use Task

def start_link(_) do
IO.puts("Starting metrics")
Task.start_link(&loop/0)
def start() do
Task.start(&execute/0)
end

defp loop() do
Process.sleep(:timer.seconds(10))
IO.inspect(collect_metrics())
loop()
end

defp collect_metrics() do
[
defp execute() do
IO.inspect([
memory_usage: :erlang.memory(:total),
process_count: :erlang.system_info(:process_count)
]
])
end
end

+ 1
- 1
ch10/todo_metrics/lib/todo/system.ex View File

@@ -3,7 +3,7 @@ defmodule Todo.System do
def start_link() do
Supervisor.start_link(
[
Todo.Metrics,
Todo.Cron,
Todo.ProcessRegistry,
Todo.Database,
Todo.Cache

Loading…
Cancel
Save