Running recurring tasks at a specific time or interval
defmodule ReactPhoenix.PriceChecker do
use GenServer
def start_link(_) do
GenServer.start_link(__MODULE__, 1)
end
def init(state) do
:timer.send_interval(1000, :work)
#could use Process.send_after for work that could take longer than interval
{:ok, state}
end
def handle_info(:work, state) do
# do important stuff
IO.puts "#{state} Important stuff in progress..."
{:noreply, state + 1}
end
end
Application.ex
children = [
ReactPhoenix.PriceChecker,
Check out
Quantum for spinning up tasks during runtime() and doing a nice config of all of them