-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
58 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Copyright 2023 Clivern. All rights reserved. | ||
# Use of this source code is governed by the MIT | ||
# license that can be found in the LICENSE file. | ||
|
||
defmodule Lynx.Worker.SnapshotWorker do | ||
use GenServer | ||
|
||
require Logger | ||
|
||
def start_link(state) do | ||
GenServer.start_link(__MODULE__, state, name: __MODULE__) | ||
end | ||
|
||
## Callbacks | ||
@impl true | ||
def init(state) do | ||
Logger.info("Snapshor Worker Started") | ||
|
||
schedule_work() | ||
|
||
{:ok, state} | ||
end | ||
|
||
@impl true | ||
def handle_info(:fire, state) do | ||
# Reschedule once more | ||
schedule_work() | ||
|
||
{:noreply, state} | ||
end | ||
|
||
defp schedule_work do | ||
# We schedule the work to happen in 60 seconds | ||
Process.send_after(self(), :fire, 60 * 1000) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 Clivern. All rights reserved. | ||
# Use of this source code is governed by the MIT | ||
# license that can be found in the LICENSE file. | ||
|
||
defmodule Lynx.Workers do | ||
use Supervisor | ||
|
||
def start_link(init_state) do | ||
Supervisor.start_link(__MODULE__, init_state, name: __MODULE__) | ||
end | ||
|
||
@impl true | ||
def init(_init_state) do | ||
children = [ | ||
{Lynx.Worker.SnapshotWorker, %{}} | ||
] | ||
|
||
Supervisor.init(children, strategy: :one_for_one) | ||
end | ||
end |