Skip to content

Instantly share code, notes, and snippets.

@iantbutler01
Last active February 5, 2020 06:46
Show Gist options
  • Save iantbutler01/28a8fb16c49289eee0c8887274051e39 to your computer and use it in GitHub Desktop.
Save iantbutler01/28a8fb16c49289eee0c8887274051e39 to your computer and use it in GitHub Desktop.
def handle_info(:schedule_work, state) do
unless :queue.is_empty(state) do
for _ <- 0..System.schedulers_online() do
Task.Supervisor.async_nolink(CrawlerExample.WorkerSupervisor, fn ->
CrawlerExample.Worker.work(@depth_limit)
end)
end
end
schedule_work(@work_interval)
{:noreply, state}
end
def handle_info({_, :ok}, state), do: {:noreply, state}
def handle_info({:DOWN, _, :process, _pid, _exception}, state), do: {:noreply, state}
defp schedule_work(interval), do: :erlang.send_after(interval, self(), :schedule_work)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment