Skip to content

Commit

Permalink
Give errors to Oban as 2 tuples
Browse files Browse the repository at this point in the history
Fixes cambiatus/backend/cambiatus#304
  • Loading branch information
seth-schroeder committed Jun 13, 2023
1 parent 5663ccf commit 62fb071
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
2 changes: 1 addition & 1 deletion lib/cambiatus/workers/contribution_paypal_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ defmodule Cambiatus.Workers.ContributionPaypalWorker do
{:error, _} = error ->
error

{:error, _, %{valid?: false}} ->
{:error, _, %{valid?: false}, _} ->
{:error, :invalid_changeset}
end
end
Expand Down
42 changes: 22 additions & 20 deletions lib/cambiatus/workers/monthly_digest_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,28 @@ defmodule Cambiatus.Workers.MonthlyDigestWorker do
alias Ecto.Multi

def perform(_) do
transaction =
Community
|> Community.with_news_enabled()
|> Repo.all()
|> Repo.preload([
[news: News.last_thirty_days()],
[members: User.accept_digest()],
:subdomain
])
|> Enum.filter(&Enum.any?(&1.news))
|> Enum.reduce(Multi.new(), fn community, multi ->
Enum.reduce(community.members, multi, fn member, multi ->
Oban.insert(
multi,
"#{community.symbol}-#{member.account}",
DigestEmailWorker.new(%{community_id: community.symbol, account: member.account})
)
end)
Community
|> Community.with_news_enabled()
|> Repo.all()
|> Repo.preload([
[news: News.last_thirty_days()],
[members: User.accept_digest()],
:subdomain
])
|> Enum.filter(&Enum.any?(&1.news))
|> Enum.reduce(Multi.new(), fn community, multi ->
Enum.reduce(community.members, multi, fn member, multi ->
Oban.insert(
multi,
"#{community.symbol}-#{member.account}",
DigestEmailWorker.new(%{community_id: community.symbol, account: member.account})
)
end)

Repo.transaction(transaction)
end)
|> Repo.transaction()
|> case do
{:ok, _} = success -> success
{:error, stage, _, _} -> {:error, stage}
end
end
end

0 comments on commit 62fb071

Please sign in to comment.