Add task to refresh an instance relay

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-10-21 11:02:28 +02:00
parent d0529a503d
commit e29704a928
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
2 changed files with 23 additions and 1 deletions

View File

@ -12,7 +12,7 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
alias Mobilizon.Actors.{Actor, Follower} alias Mobilizon.Actors.{Actor, Follower}
alias Mobilizon.Federation.ActivityPub alias Mobilizon.Federation.ActivityPub
alias Mobilizon.Federation.ActivityPub.{Activity, Transmogrifier} alias Mobilizon.Federation.ActivityPub.{Activity, Refresher, Transmogrifier}
alias Mobilizon.Federation.WebFinger alias Mobilizon.Federation.WebFinger
alias Mobilizon.GraphQL.API.Follows alias Mobilizon.GraphQL.API.Follows
@ -90,6 +90,15 @@ defmodule Mobilizon.Federation.ActivityPub.Relay do
end end
end end
def refresh(address) do
Logger.debug("We're trying to refresh a remote instance")
with {:ok, target_instance} <- fetch_actor(address),
{:ok, %Actor{} = target_actor} <- ActivityPub.get_or_fetch_actor_by_url(target_instance) do
Refresher.refresh_profile(target_actor)
end
end
@doc """ @doc """
Publish an activity to all relays following this instance Publish an activity to all relays following this instance
""" """

View File

@ -65,4 +65,17 @@ defmodule Mix.Tasks.Mobilizon.Relay do
IO.puts(:stderr, "Error while accept #{target} follow: #{inspect(e)}") IO.puts(:stderr, "Error while accept #{target} follow: #{inspect(e)}")
end end
end end
def run(["refresh", target]) do
Common.start_mobilizon()
IO.puts("Refreshing #{target}, this can take a while.")
case Relay.refresh(target) do
:ok ->
IO.puts("Refreshed #{target}")
err ->
IO.puts(:stderr, "Error while refreshing #{target}: #{inspect(err)}")
end
end
end end