+ @websub Application.get_env(:pleroma, :websub)
+ @ostatus Application.get_env(:pleroma, :ostatus)
+ @httpoison Application.get_env(:pleroma, :httpoison)
+ @max_jobs 10
+
+ def start_link do
+ spawn(fn ->
+ Process.sleep(1000 * 60 * 1) # 1 minute
+ 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 * 6) # 6 hours
+ enqueue(:refresh_subscriptions, nil)
+ end)
+ end
+
+ def handle(:request_subscription, websub) do
+ Logger.debug("Refreshing #{websub.topic}")
+ with {:ok, websub } <- Websub.request_subscription(websub) do
+ Logger.debug("Successfully refreshed #{websub.topic}")
+ else
+ _e -> Logger.debug("Couldn't refresh #{websub.topic}")
+ end
+ end