From 926dd012722f7adda9812d60d43fa185e1e1c9cc Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 2 May 2022 12:07:21 +0200 Subject: [PATCH] Send push notification into own task Signed-off-by: Thomas Citharel --- lib/service/notifier/push.ex | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/service/notifier/push.ex b/lib/service/notifier/push.ex index 4fc7caac3..ecf13a239 100644 --- a/lib/service/notifier/push.ex +++ b/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}