aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlambda <lain@soykaf.club>2019-04-08 11:53:18 +0000
committerlambda <lain@soykaf.club>2019-04-08 11:53:18 +0000
commit4977e96fa408e8148a355b3c759af34ae3ca312d (patch)
treedecc2cc28908a79df003ad668fb06cb74fa97159
parente19590c93f9adc5d743867b048aad9528810fc53 (diff)
parent9abf832b034bf3867272bd178d168c641129eff0 (diff)
downloadpleroma-4977e96fa408e8148a355b3c759af34ae3ca312d.tar.gz
Merge branch 'use-jobs-in-webpush' into 'develop'
Use PleromaJobQueue in Pleroma.Web.Push See merge request pleroma/pleroma!1023
-rw-r--r--config/config.exs1
-rw-r--r--docs/config.md1
-rw-r--r--lib/pleroma/application.ex4
-rw-r--r--lib/pleroma/web/push/impl.ex6
-rw-r--r--lib/pleroma/web/push/push.ex48
-rw-r--r--test/web/push/impl_test.exs6
6 files changed, 21 insertions, 45 deletions
diff --git a/config/config.exs b/config/config.exs
index cdbce6504..3462a37f7 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -367,6 +367,7 @@ config :pleroma, Pleroma.Web.Federator.RetryQueue,
config :pleroma_job_queue, :queues,
federator_incoming: 50,
federator_outgoing: 50,
+ web_push: 50,
mailer: 10,
transmogrifier: 20,
scheduled_activities: 10
diff --git a/docs/config.md b/docs/config.md
index 7e7fa754a..b5ea58746 100644
--- a/docs/config.md
+++ b/docs/config.md
@@ -319,6 +319,7 @@ Pleroma has the following queues:
* `federator_incoming` - Incoming federation
* `mailer` - Email sender, see [`Pleroma.Mailer`](#pleroma-mailer)
* `transmogrifier` - Transmogrifier
+* `web_push` - Web push notifications
* `scheduled_activities` - Scheduled activities, see [`Pleroma.ScheduledActivities`](#pleromascheduledactivity)
Example:
diff --git a/lib/pleroma/application.ex b/lib/pleroma/application.ex
index f0cb7d9a8..eeb415084 100644
--- a/lib/pleroma/application.ex
+++ b/lib/pleroma/application.ex
@@ -111,8 +111,8 @@ defmodule Pleroma.Application do
[
worker(Pleroma.Web.Federator.RetryQueue, []),
worker(Pleroma.Stats, []),
- worker(Pleroma.Web.Push, []),
- worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary)
+ worker(Task, [&Pleroma.Web.Push.init/0], restart: :temporary, id: :web_push_init),
+ worker(Task, [&Pleroma.Web.Federator.init/0], restart: :temporary, id: :federator_init)
] ++
streamer_child() ++
chat_child() ++
diff --git a/lib/pleroma/web/push/impl.ex b/lib/pleroma/web/push/impl.ex
index 863573185..2233480c5 100644
--- a/lib/pleroma/web/push/impl.ex
+++ b/lib/pleroma/web/push/impl.ex
@@ -19,8 +19,8 @@ defmodule Pleroma.Web.Push.Impl do
@types ["Create", "Follow", "Announce", "Like"]
@doc "Performs sending notifications for user subscriptions"
- @spec perform_send(Notification.t()) :: list(any)
- def perform_send(
+ @spec perform(Notification.t()) :: list(any) | :error
+ def perform(
%{activity: %{data: %{"type" => activity_type}, id: activity_id}, user_id: user_id} =
notif
)
@@ -50,7 +50,7 @@ defmodule Pleroma.Web.Push.Impl do
end
end
- def perform_send(_) do
+ def perform(_) do
Logger.warn("Unknown notification type")
:error
end
diff --git a/lib/pleroma/web/push/push.ex b/lib/pleroma/web/push/push.ex
index 5259e8e33..729dad02a 100644
--- a/lib/pleroma/web/push/push.ex
+++ b/lib/pleroma/web/push/push.ex
@@ -3,18 +3,20 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Push do
- use GenServer
-
alias Pleroma.Web.Push.Impl
require Logger
- ##############
- # Client API #
- ##############
+ def init do
+ unless enabled() do
+ Logger.warn("""
+ VAPID key pair is not found. If you wish to enabled web push, please run
+
+ mix web_push.gen.keypair
- def start_link do
- GenServer.start_link(__MODULE__, :ok, name: __MODULE__)
+ and add the resulting output to your configuration file.
+ """)
+ end
end
def vapid_config do
@@ -30,35 +32,5 @@ defmodule Pleroma.Web.Push do
end
def send(notification),
- do: GenServer.cast(__MODULE__, {:send, notification})
-
- ####################
- # Server Callbacks #
- ####################
-
- @impl true
- def init(:ok) do
- if enabled() do
- {:ok, nil}
- else
- Logger.warn("""
- VAPID key pair is not found. If you wish to enabled web push, please run
-
- mix web_push.gen.keypair
-
- and add the resulting output to your configuration file.
- """)
-
- :ignore
- end
- end
-
- @impl true
- def handle_cast({:send, notification}, state) do
- if enabled() do
- Impl.perform_send(notification)
- end
-
- {:noreply, state}
- end
+ do: PleromaJobQueue.enqueue(:web_push, Impl, [notification])
end
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 3f9f3d809..6bac2c9f6 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -64,17 +64,19 @@ defmodule Pleroma.Web.Push.ImplTest do
}
)
- assert Impl.perform_send(notif) == [:ok, :ok]
+ assert Impl.perform(notif) == [:ok, :ok]
end
+ @tag capture_log: true
test "returns error if notif does not match " do
- assert Impl.perform_send(%{}) == :error
+ assert Impl.perform(%{}) == :error
end
test "successful message sending" do
assert Impl.push_message(@message, @sub, @api_key, %Subscription{}) == :ok
end
+ @tag capture_log: true
test "fail message sending" do
assert Impl.push_message(
@message,