Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
pleroma
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
kaniini
pleroma
Commits
2e753e8c
Commit
2e753e8c
authored
7 years ago
by
lain
Browse files
Options
Downloads
Patches
Plain Diff
Refresh subscriptions.
parent
fca7390c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
lib/pleroma/web/federator/federator.ex
+15
-2
15 additions, 2 deletions
lib/pleroma/web/federator/federator.ex
lib/pleroma/web/websub/websub.ex
+15
-0
15 additions, 0 deletions
lib/pleroma/web/websub/websub.ex
test/web/websub/websub_test.exs
+15
-1
15 additions, 1 deletion
test/web/websub/websub_test.exs
with
45 additions
and
3 deletions
lib/pleroma/web/federator/federator.ex
+
15
−
2
View file @
2e753e8c
defmodule
Pleroma
.
Web
.
Federator
do
use
GenServer
alias
Pleroma
.
User
alias
Pleroma
.
Web
.
WebFinger
alias
Pleroma
.
Web
.
{
WebFinger
,
Websub
}
require
Logger
@websub
Application
.
get_env
(
:pleroma
,
:websub
)
...
...
@@ -9,14 +9,27 @@ defmodule Pleroma.Web.Federator do
@max_jobs
10
def
start_link
do
spawn
(
fn
->
Process
.
sleep
(
1000
*
60
*
1
)
# 10 minutes
enqueue
(
:refresh_subscriptions
,
nil
)
end
)
GenServer
.
start_link
(
__MODULE__
,
{
:sets
.
new
(),
:queue
.
new
()},
name:
__MODULE__
)
end
def
handle
(
:refresh_subscriptions
,
_
)
do
Logger
.
debug
(
"Federator running refresh subscriptions"
)
Websub
.
refresh_subscriptions
()
spawn
(
fn
->
Process
.
sleep
(
1000
*
60
*
60
)
# 60 minutes
enqueue
(
:refresh_subscriptions
,
nil
)
end
)
end
def
handle
(
:publish
,
activity
)
do
Logger
.
debug
(
fn
->
"Running publish for
#{
activity
.
data
[
"id"
]
}
"
end
)
with
actor
when
not
is_nil
(
actor
)
<-
User
.
get_cached_by_ap_id
(
activity
.
data
[
"actor"
])
do
Logger
.
debug
(
fn
->
"Sending
#{
activity
.
data
[
"id"
]
}
out via websub"
end
)
Pleroma
.
Web
.
Websub
.
publish
(
Pleroma
.
Web
.
OStatus
.
feed_path
(
actor
),
actor
,
activity
)
Websub
.
publish
(
Pleroma
.
Web
.
OStatus
.
feed_path
(
actor
),
actor
,
activity
)
{
:ok
,
actor
}
=
WebFinger
.
ensure_keys_present
(
actor
)
Logger
.
debug
(
fn
->
"Sending
#{
activity
.
data
[
"id"
]
}
out via salmon"
end
)
...
...
This diff is collapsed.
Click to expand it.
lib/pleroma/web/websub/websub.ex
+
15
−
0
View file @
2e753e8c
...
...
@@ -204,4 +204,19 @@ defmodule Pleroma.Web.Websub do
{
:error
,
websub
}
end
end
def
refresh_subscriptions
(
delta
\\
60
*
60
*
24
)
do
Logger
.
debug
(
"Refreshing subscriptions"
)
cut_off
=
NaiveDateTime
.
add
(
NaiveDateTime
.
utc_now
,
delta
)
query
=
from
sub
in
WebsubClientSubscription
,
where:
sub
.
valid_until
<
^
cut_off
and
sub
.
state
==
"active"
subs
=
Repo
.
all
(
query
)
Enum
.
map
(
subs
,
fn
(
sub
)
->
request_subscription
(
sub
)
end
)
end
end
This diff is collapsed.
Click to expand it.
test/web/websub/websub_test.exs
+
15
−
1
View file @
2e753e8c
...
...
@@ -7,7 +7,7 @@ end
defmodule
Pleroma
.
Web
.
WebsubTest
do
use
Pleroma
.
DataCase
alias
Pleroma
.
Web
.
Websub
alias
Pleroma
.
Web
.
Websub
.
WebsubServerSubscription
alias
Pleroma
.
Web
.
Websub
.
{
WebsubServerSubscription
,
WebsubClientSubscription
}
import
Pleroma
.
Factory
alias
Pleroma
.
Web
.
Router
.
Helpers
...
...
@@ -174,4 +174,18 @@ defmodule Pleroma.Web.WebsubTest do
signed
=
Websub
.
sign
(
"secret"
,
[[
"て"
],
[
'す'
]])
end
describe
"renewing subscriptions"
do
test
"it renews subscriptions that have less than a day of time left"
do
day
=
60
*
60
*
24
now
=
NaiveDateTime
.
utc_now
still_good
=
insert
(
:websub_client_subscription
,
%{
valid_until:
NaiveDateTime
.
add
(
now
,
2
*
day
),
topic:
"http://example.org/still_good"
,
state:
"active"
})
needs_refresh
=
insert
(
:websub_client_subscription
,
%{
valid_until:
NaiveDateTime
.
add
(
now
,
day
-
100
),
topic:
"http://example.org/needs_refresh"
,
state:
"active"
})
refresh
=
Websub
.
refresh_subscriptions
()
assert
still_good
==
Repo
.
get
(
WebsubClientSubscription
,
still_good
.
id
)
refute
needs_refresh
==
Repo
.
get
(
WebsubClientSubscription
,
needs_refresh
.
id
)
end
end
end
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment