-
Notifications
You must be signed in to change notification settings - Fork 246
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Toggle off ++ feeds for now-inactive members
- Loading branch information
1 parent
47b4854
commit de4700e
Showing
3 changed files
with
38 additions
and
0 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,34 @@ | ||
defmodule Changelog.ObanWorkers.FeedBouncer do | ||
@moduledoc """ | ||
This module defines the Oban worker for switching inactive members' | ||
feeds back to public mp3s | ||
""" | ||
use Oban.Worker, queue: :scheduled | ||
|
||
import Ecto.Changeset, only: [change: 2] | ||
|
||
alias Changelog.{EventLog, Feed, Policies, Repo} | ||
|
||
@impl Oban.Worker | ||
def perform(_job) do | ||
plusplus = | ||
Feed | ||
|> Feed.plusplus() | ||
|> Feed.preload_owner() | ||
|> Repo.all() | ||
|
||
for feed = %{owner: owner} <- plusplus do | ||
if !Policies.Feed.plusplus(owner) do | ||
{:ok, feed} = feed |> change(%{plusplus: false}) |> Repo.update() | ||
log("Turned off pluplus for feed ##{feed.id} owned by inactive member ##{owner.id} (#{owner.email})") | ||
Changelog.ObanWorkers.FeedUpdater.queue(feed) | ||
end | ||
end | ||
|
||
:ok | ||
end | ||
|
||
defp log(message) do | ||
EventLog.insert(message, "FeedBouncer") | ||
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