Send push notification into own task

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-05-02 12:07:21 +02:00
parent d87261a6fb
commit 926dd01272
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
1 changed files with 8 additions and 1 deletions

View File

@ -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}