Merge branch 'feature/optimize_rich_media_parser' into 'develop'
[akkoma] / lib / pleroma / workers / background_worker.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.BackgroundWorker do
6 alias Pleroma.Activity
7 alias Pleroma.User
8 alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
9 alias Pleroma.Web.OAuth.Token.CleanWorker
10
11 use Pleroma.Workers.WorkerHelper, queue: "background"
12
13 @impl Oban.Worker
14 def perform(%{"op" => "fetch_initial_posts", "user_id" => user_id}, _job) do
15 user = User.get_cached_by_id(user_id)
16 User.perform(:fetch_initial_posts, user)
17 end
18
19 def perform(%{"op" => "deactivate_user", "user_id" => user_id, "status" => status}, _job) do
20 user = User.get_cached_by_id(user_id)
21 User.perform(:deactivate_async, user, status)
22 end
23
24 def perform(%{"op" => "delete_user", "user_id" => user_id}, _job) do
25 user = User.get_cached_by_id(user_id)
26 User.perform(:delete, user)
27 end
28
29 def perform(
30 %{
31 "op" => "blocks_import",
32 "blocker_id" => blocker_id,
33 "blocked_identifiers" => blocked_identifiers
34 },
35 _job
36 ) do
37 blocker = User.get_cached_by_id(blocker_id)
38 User.perform(:blocks_import, blocker, blocked_identifiers)
39 end
40
41 def perform(
42 %{
43 "op" => "follow_import",
44 "follower_id" => follower_id,
45 "followed_identifiers" => followed_identifiers
46 },
47 _job
48 ) do
49 follower = User.get_cached_by_id(follower_id)
50 User.perform(:follow_import, follower, followed_identifiers)
51 end
52
53 def perform(%{"op" => "clean_expired_tokens"}, _job) do
54 CleanWorker.perform(:clean)
55 end
56
57 def perform(%{"op" => "media_proxy_preload", "message" => message}, _job) do
58 MediaProxyWarmingPolicy.perform(:preload, message)
59 end
60
61 def perform(%{"op" => "media_proxy_prefetch", "url" => url}, _job) do
62 MediaProxyWarmingPolicy.perform(:prefetch, url)
63 end
64
65 def perform(%{"op" => "fetch_data_for_activity", "activity_id" => activity_id}, _job) do
66 activity = Activity.get_by_id(activity_id)
67 Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
68 end
69 end