Refactor copypasta to a private function in instance.ex
[akkoma] / lib / mix / tasks / relay_follow.ex
1 defmodule Mix.Tasks.RelayFollow do
2 use Mix.Task
3 require Logger
4 alias Pleroma.Web.ActivityPub.Relay
5
6 @shortdoc "Follows a remote relay"
7 @moduledoc """
8 Follows a remote relay
9
10 Usage: ``mix relay_follow <relay_url>``
11
12 Example: ``mix relay_follow https://example.org/relay``
13 """
14 def run([target]) do
15 Mix.Task.run("app.start")
16
17 with {:ok, activity} <- Relay.follow(target) do
18 # put this task to sleep to allow the genserver to push out the messages
19 :timer.sleep(500)
20 else
21 {:error, e} -> Mix.shell().error("Error while following #{target}: #{inspect(e)}")
22 end
23 end
24 end