Skip to content

Commit

Permalink
Use cache for storing monitors
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Oct 25, 2024
1 parent f7cfd77 commit f787c19
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 40 deletions.
1 change: 0 additions & 1 deletion lib/uplink/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ defmodule Uplink.Application do
{Cluster.Supervisor, [topologies, [name: Uplink.ClusterSupervisor]]},
{Task.Supervisor, name: Uplink.TaskSupervisor},
{Plug.Cowboy, plug: Uplink.Internal, scheme: :http, port: internal_port},
{Uplink.Pipelines.Context, [name: :metrics, monitors: []]},
{Pogo.DynamicSupervisor,
[name: Uplink.PipelineSupervisor, scope: :uplink]},
{Uplink.Monitors, []},
Expand Down
7 changes: 6 additions & 1 deletion lib/uplink/monitors.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule Uplink.Monitors do
use Task

alias Uplink.Cache
alias Uplink.Pipelines
alias Uplink.Clients.Instellar

Expand All @@ -15,10 +16,14 @@ defmodule Uplink.Monitors do
end

def run(_options) do
Cache.put_new({:monitors, :metrics}, [])

Instellar.list_monitors()
|> case do
{:ok, monitors} ->
start_pipeline(monitors, :metrics)
Cache.transaction([keys: [{:monitors, :metrics}]], fn ->
start_pipeline(monitors, :metrics)
end)

error ->
{:error, error}
Expand Down
16 changes: 10 additions & 6 deletions lib/uplink/pipelines.ex
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
defmodule Uplink.Pipelines do
defdelegate get_monitors(context),
to: __MODULE__.Context,
as: :get
alias Uplink.Cache

defdelegate append_monitors(context, monitors),
to: __MODULE__.Context,
as: :append
def get_monitors(context) do
Cache.get({:monitors, context}) || []
end

def append_monitors(context, monitors) do
Cache.get_and_update({:monitors, context}, fn existing_monitors ->
{existing_monitors, existing_monitors ++ monitors}
end)
end

def start(module) do
spec = %{
Expand Down
32 changes: 0 additions & 32 deletions lib/uplink/pipelines/context.ex

This file was deleted.

0 comments on commit f787c19

Please sign in to comment.