Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .credo.exs
Original file line number Diff line number Diff line change
Expand Up @@ -178,11 +178,12 @@
{Credo.Check.Refactor.VariableRebinding, false},
{Credo.Check.Warning.LeakyEnvironment, false},
{Credo.Check.Warning.MapGetUnsafePass, false},
{Credo.Check.Warning.UnsafeToAtom, false}
{Credo.Check.Warning.UnsafeToAtom, false},

#
# Custom checks can be created using `mix credo.gen.check`.
#
{CredoCheckErrorHandlingEctoOban.Check.TransactionErrorInObanJob, []},
]
}
]
Expand Down
3 changes: 2 additions & 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 All @@ -35,6 +35,7 @@ defmodule Cambiatus.Workers.ContributionPaypalWorker do
{:ok, contribution} = Payments.get_contribution(contribution_id)
contribution = Repo.preload(contribution, :payment_callbacks)

# credo:disable-for-next-line CredoCheckErrorHandlingEctoOban.Check.TransactionErrorInObanJob
Multi.new()
|> Multi.run(:contribution, fn repo, _ ->
contribution
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
{:error, stage, _, _} -> {:error, stage}
any -> any
end
end
end
1 change: 1 addition & 0 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ defmodule Cambiatus.Mixfile do

# Dev only
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:credo_check_error_handling_ecto_oban, "~> 0.9.0", only: :dev, runtime: false},
{:sobelow, "~> 0.11.1", only: :dev},

# Test Only
Expand Down
1 change: 1 addition & 0 deletions mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"cowboy_telemetry": {:hex, :cowboy_telemetry, "0.4.0", "f239f68b588efa7707abce16a84d0d2acf3a0f50571f8bb7f56a15865aae820c", [:rebar3], [{:cowboy, "~> 2.7", [hex: :cowboy, repo: "hexpm", optional: false]}, {:telemetry, "~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "7d98bac1ee4565d31b62d59f8823dfd8356a169e7fcbb83831b8a5397404c9de"},
"cowlib": {:hex, :cowlib, "2.11.0", "0b9ff9c346629256c42ebe1eeb769a83c6cb771a6ee5960bd110ab0b9b872063", [:make, :rebar3], [], "hexpm", "2b3e9da0b21c4565751a6d4901c20d1b4cc25cbb7fd50d91d2ab6dd287bc86a9"},
"credo": {:hex, :credo, "1.6.7", "323f5734350fd23a456f2688b9430e7d517afb313fbd38671b8a4449798a7854", [:mix], [{:bunt, "~> 0.2.1", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "41e110bfb007f7eda7f897c10bf019ceab9a0b269ce79f015d54b0dcf4fc7dd3"},
"credo_check_error_handling_ecto_oban": {:hex, :credo_check_error_handling_ecto_oban, "0.9.1", "539e47a55a973d5b1c92fc3685d8cf1a2509c8ea07cbd3e471a3e212f0d8c151", [:mix], [], "hexpm", "cfe3009553f8d031b3cf35e8d29f918691119f4162c8b08b5aad4107c311ecee"},
"crontab": {:hex, :crontab, "1.1.5", "2c9439506ceb0e9045de75879e994b88d6f0be88bfe017d58cb356c66c4a5482", [:mix], [{:ecto, "~> 1.0 or ~> 2.0 or ~> 3.0", [hex: :ecto, repo: "hexpm", optional: true]}], "hexpm"},
"dataloader": {:hex, :dataloader, "1.0.10", "a42f07641b1a0572e0b21a2a5ae1be11da486a6790f3d0d14512d96ff3e3bbe9", [:mix], [{:ecto, ">= 3.4.3 and < 4.0.0", [hex: :ecto, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "54cd70cec09addf4b2ace14cc186a283a149fd4d3ec5475b155951bf33cd963f"},
"db_connection": {:hex, :db_connection, "2.4.3", "3b9aac9f27347ec65b271847e6baeb4443d8474289bd18c1d6f4de655b70c94d", [:mix], [{:connection, "~> 1.0", [hex: :connection, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "c127c15b0fa6cfb32eed07465e05da6c815b032508d4ed7c116122871df73c12"},
Expand Down