Skip to content

Commit

Permalink
chore: OFM Reminders Job Processing Change (#557)
Browse files Browse the repository at this point in the history
* Process job with Oban instead of using a GenServer.

* Fix URL now that the base URL redirects to Places Page.
  • Loading branch information
cmaddox5 authored Nov 19, 2024
1 parent ce0f912 commit 2593fb5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 24 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 @@ -58,7 +49,7 @@ defmodule Screenplay.OutfrontTakeoverTool.Alerts.Reminders do
type: "section",
text: %{
type: "mrkdwn",
text: "Please review this Alert: #{ScreenplayWeb.Endpoint.url()}"
text: "Please review this alert: #{ScreenplayWeb.Endpoint.url()}/emergency-takeover"
}
}
]
Expand All @@ -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 2593fb5

Please sign in to comment.