Send push notification into own task

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
chapril
Thomas Citharel 7 months ago
parent d87261a6fb
commit 926dd01272
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
  1. 9
      lib/service/notifier/push.ex

@ -25,7 +25,14 @@ defmodule Mobilizon.Service.Notifier.Push do
options = Keyword.put_new(options, :locale, locale)
%Page{elements: subscriptions} = Users.list_user_push_subscriptions(user_id, 1, 100)
Enum.each(subscriptions, &send_subscription(activity, convert_subscription(&1), options))
subscriptions
|> Enum.map(&convert_subscription/1)
|> Enum.map(fn subscription ->
Task.async(fn -> send_subscription(activity, subscription, options) end)
end)
|> Task.await_many(10_000)
{:ok, :sent}
else
{:ok, :skipped}

Loading…
Cancel
Save