1
0
Fork 0
mirror of https://github.com/benbusby/farside.git synced 2025-04-20 10:58:42 +00:00
farside/lib/farside/server.ex
Ben Busby 7693a6b063
Add env var for toggling cron task on/off
FARSIDE_CRON allows turning on/off the scheduled instance availability
check that occurs every 5 minutes by setting the variable to 1 (on) or 0
(off). The default behavior is "on".
2023-07-17 17:46:39 -06:00

25 lines
614 B
Elixir

defmodule Farside.Server do
use GenServer
import Crontab.CronExpression
def init(init_arg) do
{:ok, init_arg}
end
def start_link(arg) do
test = System.get_env("FARSIDE_TEST")
cron = System.get_env("FARSIDE_CRON")
if test == "1" || cron == "0" do
IO.puts("Skipping sync job setup...")
else
Farside.Scheduler.new_job()
|> Quantum.Job.set_name(:sync)
|> Quantum.Job.set_schedule(~e[*/5 * * * *])
|> Quantum.Job.set_task(fn -> Farside.Instances.sync() end)
|> Farside.Scheduler.add_job()
end
GenServer.start_link(__MODULE__, arg)
end
end