Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Pleroma
pleroma
Commits
4977e96f
Commit
4977e96f
authored
Apr 08, 2019
by
lain
Browse files
Merge branch 'use-jobs-in-webpush' into 'develop'
Use PleromaJobQueue in Pleroma.Web.Push See merge request
!1023
parents
e19590c9
9abf832b
Pipeline
#10182
passed with stages
in 4 minutes and 49 seconds
Changes
6
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
config/config.exs
View file @
4977e96f
...
...
@@ -367,6 +367,7 @@
config
:pleroma_job_queue
,
:queues
,
federator_incoming:
50
,
federator_outgoing:
50
,
web_push:
50
,
mailer:
10
,
transmogrifier:
20
,
scheduled_activities:
10
...
...
docs/config.md
View file @
4977e96f
...
...
@@ -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:
...
...
lib/pleroma/application.ex
View file @
4977e96f
...
...
@@ -111,8 +111,8 @@ def start(_type, _args) 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
()
++
...
...
lib/pleroma/web/push/impl.ex
View file @
4977e96f
...
...
@@ -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 @@ def perform_send(
end
end
def
perform
_send
(
_
)
do
def
perform
(
_
)
do
Logger
.
warn
(
"Unknown notification type"
)
:error
end
...
...
lib/pleroma/web/push/push.ex
View file @
4977e96f
...
...
@@ -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 @@ def enabled 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
test/web/push/impl_test.exs
View file @
4977e96f
...
...
@@ -64,17 +64,19 @@ test "performs sending notifications" 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
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment