forked from potsda.mn/mobilizon
Add appropriate timeouts for Repo.transactions
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
90158f1112
commit
87214b038f
|
@ -64,7 +64,7 @@ defmodule Mobilizon.Service.ActorSuspension do
|
|||
|
||||
Logger.debug("Going to run the transaction")
|
||||
|
||||
case Repo.transaction(multi) do
|
||||
case Repo.transaction(multi, timeout: 60_000) do
|
||||
{:ok, %{actor: %Actor{} = actor}} ->
|
||||
{:ok, true} = Cachex.del(:activity_pub, "actor_#{actor.preferred_username}")
|
||||
Cachable.clear_all_caches(actor)
|
||||
|
|
|
@ -29,35 +29,38 @@ defmodule Mobilizon.Service.SiteMap do
|
|||
gzip: false
|
||||
]
|
||||
|
||||
Repo.transaction(fn ->
|
||||
Events.stream_events_for_sitemap()
|
||||
|> Stream.concat(Actors.list_groups_for_stream())
|
||||
|> Stream.concat(Posts.list_posts_for_stream())
|
||||
|> Stream.concat(
|
||||
Enum.map(static_routes, fn route ->
|
||||
{url, frequency} =
|
||||
case route do
|
||||
{url, frequency} -> {url, frequency}
|
||||
url when is_binary(url) -> {url, @default_static_frequency}
|
||||
end
|
||||
Repo.transaction(
|
||||
fn ->
|
||||
Events.stream_events_for_sitemap()
|
||||
|> Stream.concat(Actors.list_groups_for_stream())
|
||||
|> Stream.concat(Posts.list_posts_for_stream())
|
||||
|> Stream.concat(
|
||||
Enum.map(static_routes, fn route ->
|
||||
{url, frequency} =
|
||||
case route do
|
||||
{url, frequency} -> {url, frequency}
|
||||
url when is_binary(url) -> {url, @default_static_frequency}
|
||||
end
|
||||
|
||||
%{url: url, updated_at: nil, frequence: frequency}
|
||||
%{url: url, updated_at: nil, frequence: frequency}
|
||||
end)
|
||||
)
|
||||
|> Stream.map(fn %{url: url, updated_at: updated_at} = args ->
|
||||
frequence = Map.get(args, :frequence, :weekly)
|
||||
|
||||
%Sitemapper.URL{
|
||||
loc: url,
|
||||
changefreq: frequence,
|
||||
lastmod: check_date_time(updated_at)
|
||||
}
|
||||
end)
|
||||
)
|
||||
|> Stream.map(fn %{url: url, updated_at: updated_at} = args ->
|
||||
frequence = Map.get(args, :frequence, :weekly)
|
||||
|
||||
%Sitemapper.URL{
|
||||
loc: url,
|
||||
changefreq: frequence,
|
||||
lastmod: check_date_time(updated_at)
|
||||
}
|
||||
end)
|
||||
|> Sitemapper.generate(config)
|
||||
|> Sitemapper.persist(config)
|
||||
|> Sitemapper.ping(config)
|
||||
|> Stream.run()
|
||||
end)
|
||||
|> Sitemapper.generate(config)
|
||||
|> Sitemapper.persist(config)
|
||||
|> Sitemapper.ping(config)
|
||||
|> Stream.run()
|
||||
end,
|
||||
timeout: :infinity
|
||||
)
|
||||
end
|
||||
|
||||
# Sometimes we use naive datetimes
|
||||
|
|
|
@ -20,27 +20,30 @@ defmodule Mobilizon.Service.Workers.SendActivityRecapWorker do
|
|||
|
||||
@impl Oban.Worker
|
||||
def perform(%Job{}) do
|
||||
Repo.transaction(fn ->
|
||||
Users.stream_users_for_recap()
|
||||
|> Enum.to_list()
|
||||
|> Repo.preload([:settings, :activity_settings])
|
||||
|> Enum.filter(&filter_elegible_users/1)
|
||||
|> Enum.map(fn %User{} = user ->
|
||||
%{
|
||||
activities: activities_for_user(user),
|
||||
user: user
|
||||
}
|
||||
end)
|
||||
|> Enum.filter(fn %{activities: activities, user: _user} -> length(activities) > 0 end)
|
||||
|> Enum.map(fn %{
|
||||
activities: activities,
|
||||
user:
|
||||
%User{settings: %Setting{group_notifications: group_notifications}} =
|
||||
user
|
||||
} ->
|
||||
Email.send(user, activities, recap: group_notifications)
|
||||
end)
|
||||
end)
|
||||
Repo.transaction(
|
||||
fn ->
|
||||
Users.stream_users_for_recap()
|
||||
|> Enum.to_list()
|
||||
|> Repo.preload([:settings, :activity_settings])
|
||||
|> Enum.filter(&filter_elegible_users/1)
|
||||
|> Enum.map(fn %User{} = user ->
|
||||
%{
|
||||
activities: activities_for_user(user),
|
||||
user: user
|
||||
}
|
||||
end)
|
||||
|> Enum.filter(fn %{activities: activities, user: _user} -> length(activities) > 0 end)
|
||||
|> Enum.map(fn %{
|
||||
activities: activities,
|
||||
user:
|
||||
%User{settings: %Setting{group_notifications: group_notifications}} =
|
||||
user
|
||||
} ->
|
||||
Email.send(user, activities, recap: group_notifications)
|
||||
end)
|
||||
end,
|
||||
timeout: :infinity
|
||||
)
|
||||
end
|
||||
|
||||
defp activities_for_user(
|
||||
|
|
|
@ -82,15 +82,18 @@ defmodule Mobilizon.Web.Email.Event do
|
|||
|> MapSet.new()
|
||||
|
||||
if MapSet.size(diff) > 0 do
|
||||
Repo.transaction(fn ->
|
||||
event_id
|
||||
|> Events.list_local_emails_user_participants_for_event_query()
|
||||
|> Repo.stream()
|
||||
|> Enum.to_list()
|
||||
|> Enum.each(
|
||||
&send_notification_for_event_update_to_participant(&1, old_event, event, diff)
|
||||
)
|
||||
end)
|
||||
Repo.transaction(
|
||||
fn ->
|
||||
event_id
|
||||
|> Events.list_local_emails_user_participants_for_event_query()
|
||||
|> Repo.stream()
|
||||
|> Enum.to_list()
|
||||
|> Enum.each(
|
||||
&send_notification_for_event_update_to_participant(&1, old_event, event, diff)
|
||||
)
|
||||
end,
|
||||
timeout: 120_000
|
||||
)
|
||||
else
|
||||
{:ok, :ok}
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue