Skip to content

Commit

Permalink
Tweak poll interval
Browse files Browse the repository at this point in the history
  • Loading branch information
zacksiri committed Oct 31, 2024
1 parent 265c707 commit bac0ec5
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions lib/uplink/metrics/producer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ defmodule Uplink.Metrics.Producer do

@impl true
def init(opts) do
poll_interval = Keyword.get(opts, :poll_interval, 15_000)

state = %{
demand: 0,
poll_interval: Keyword.get(opts, :poll_interval, 15_000),
poll_interval: poll_interval,
cycle: 0,
previous_cpu_metrics: [],
previous_network_metrics: [],
Expand All @@ -27,15 +29,18 @@ defmodule Uplink.Metrics.Producer do
cpu_900_metrics: []
}

Process.send_after(self(), :poll, poll_interval / 3)

{:producer, state}
end

@impl true
def handle_demand(demand, state) when demand <= 0, do: {:noreply, [], state}
def handle_demand(demand, state) when demand <= 0 do
{:noreply, [], state}
end

def handle_demand(demand, state) do
Logger.info("[Metrics.Producer] handle demand #{DateTime.utc_now()}")
Process.send_after(self(), :poll, state.poll_interval)

if ready_to_fetch?(state) do
{messages, state} = load_metrics(demand, state)
Expand All @@ -48,7 +53,7 @@ defmodule Uplink.Metrics.Producer do
@impl true
def handle_info(:poll, state) do
Logger.info("[Metrics.Producer] poll #{DateTime.utc_now()}")
Process.send_after(self(), :poll, state.poll_interval)
Process.send_after(self(), :poll, state.poll_interval / 3)

if ready_to_fetch?(state) do
{messages, state} = load_metrics(0, state)
Expand Down

0 comments on commit bac0ec5

Please sign in to comment.