Skip to content

Commit

Permalink
Process job with Oban instead of using a GenServer.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Nov 18, 2024
1 parent d63e48d commit 31fc5e0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 23 deletions.
3 changes: 2 additions & 1 deletion config/runtime.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ if env == "prod" do
plugins: [
{Oban.Plugins.Cron,
crontab: [
{"0 7 * * *", Screenplay.Jobs.TakeoverToolTestingJob}
{"0 7 * * *", Screenplay.Jobs.TakeoverToolTestingJob},
{"* * * * *", Screenplay.Jobs.Reminders}
]},
Oban.Plugins.Pruner,
Oban.Plugins.Lifeline,
Expand Down
1 change: 0 additions & 1 deletion lib/screenplay/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ defmodule Screenplay.Application do
# Start the Endpoint (http/https)
ScreenplayWeb.Endpoint,
Screenplay.OutfrontTakeoverTool.Alerts.State,
Screenplay.OutfrontTakeoverTool.Alerts.Reminders,
Screenplay.ScreensConfig
] ++
if Application.get_env(:screenplay, :start_cache_processes) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,21 @@
defmodule Screenplay.OutfrontTakeoverTool.Alerts.Reminders do
defmodule Screenplay.Jobs.Reminders do
@moduledoc """
Runs every minute and sends slack reminders to @pios in #ctd-pio-livepa if outdated alerts are still active.
Runs every minute and sends slack reminders to @oios in #tid-oio if outdated alerts are still active.
"""
use Oban.Worker, unique: true

require Logger
use GenServer

alias Screenplay.OutfrontTakeoverTool.Alerts.{Alert, State}

def start_link(_opts) do
GenServer.start_link(__MODULE__, %{})
end

def init(state) do
schedule_work()
{:ok, state}
end

def handle_info(:work, state) do
schedule_work()

@impl Oban.Worker
def perform(_) do
case Application.get_env(:screenplay, :slack_webhook_url) do
v when v in [nil, ""] -> Logger.info("No Slack Webhook URL found")
url -> send_slack_messages_for_outdated_alerts(url)
end

{:noreply, state}
:ok
end

defp send_slack_messages_for_outdated_alerts(url) do
Expand Down Expand Up @@ -80,9 +71,4 @@ defmodule Screenplay.OutfrontTakeoverTool.Alerts.Reminders do
end)
end
end

defp schedule_work do
# runs every minute
Process.send_after(self(), :work, 60 * 1000)
end
end

0 comments on commit 31fc5e0

Please sign in to comment.