Cron
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
endCheck out
Last updated