a8c01bb10d1e755ed1e8c03aa9c35052ea36694c
[akkoma] / lib / pleroma / workers / subscriber.ex
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Workers.Subscriber do
6 alias Pleroma.Repo
7 alias Pleroma.Web.Websub
8 alias Pleroma.Web.Websub.WebsubClientSubscription
9
10 require Logger
11
12 # Note: `max_attempts` is intended to be overridden in `new/1` call
13 use Oban.Worker,
14 queue: "federator_outgoing",
15 max_attempts: Pleroma.Config.get([:workers, :retries, :compile_time_default])
16
17 @impl Oban.Worker
18 def perform(%{"op" => "refresh_subscriptions"}) do
19 Websub.refresh_subscriptions()
20 # Schedule the next run in 6 hours
21 Pleroma.Web.Federator.refresh_subscriptions(schedule_in: 3600 * 6)
22 end
23
24 def perform(%{"op" => "request_subscription", "websub_id" => websub_id}) do
25 websub = Repo.get(WebsubClientSubscription, websub_id)
26 Logger.debug("Refreshing #{websub.topic}")
27
28 with {:ok, websub} <- Websub.request_subscription(websub) do
29 Logger.debug("Successfully refreshed #{websub.topic}")
30 else
31 _e -> Logger.debug("Couldn't refresh #{websub.topic}")
32 end
33 end
34
35 def perform(%{"op" => "verify_websub", "websub_id" => websub_id}) do
36 websub = Repo.get(WebsubClientSubscription, websub_id)
37
38 Logger.debug(fn ->
39 "Running WebSub verification for #{websub.id} (#{websub.topic}, #{websub.callback})"
40 end)
41
42 Websub.verify(websub)
43 end
44 end