[#1149] Refactoring: GenServer workers renamed to daemons, `use Oban.Worker` moved...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 2 Sep 2019 11:57:40 +0000 (14:57 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Mon, 2 Sep 2019 11:57:40 +0000 (14:57 +0300)
19 files changed:
config/config.exs
lib/pleroma/application.ex
lib/pleroma/daemons/activity_expiration_daemon.ex [moved from lib/pleroma/activity_expiration_worker.ex with 96% similarity]
lib/pleroma/daemons/digest_email_daemon.ex [moved from lib/pleroma/digest_email_worker.ex with 96% similarity]
lib/pleroma/daemons/scheduled_activity_daemon.ex [moved from lib/pleroma/scheduled_activity_worker.ex with 96% similarity]
lib/pleroma/workers/activity_expiration_worker.ex
lib/pleroma/workers/background_worker.ex
lib/pleroma/workers/digest_emails_worker.ex
lib/pleroma/workers/mailer_worker.ex
lib/pleroma/workers/publisher_worker.ex
lib/pleroma/workers/receiver_worker.ex
lib/pleroma/workers/scheduled_activity_worker.ex
lib/pleroma/workers/subscriber_worker.ex
lib/pleroma/workers/transmogrifier_worker.ex
lib/pleroma/workers/web_pusher_worker.ex
lib/pleroma/workers/worker_helper.ex
test/daemons/activity_expiration_daemon_test.exs [moved from test/activity_expiration_worker_test.exs with 86% similarity]
test/daemons/digest_email_daemon_test.exs [moved from test/web/digest_email_worker_test.exs with 88% similarity]
test/daemons/scheduled_activity_daemon_test.exs [moved from test/scheduled_activity_worker_test.exs with 82% similarity]

index 6fb4a09695524cdf1e522e01f05c30fdc5ccc390..b742a650d0fabec1d62058e6ea143e87844dcec6 100644 (file)
@@ -54,7 +54,7 @@ config :pleroma, Pleroma.Repo,
 scheduled_jobs =
   with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest],
        true <- digest_config[:active] do
-    [{digest_config[:schedule], {Pleroma.DigestEmailWorker, :perform, []}}]
+    [{digest_config[:schedule], {Pleroma.Daemons.DigestEmailDaemon, :perform, []}}]
   else
     _ -> []
   end
index f8f866dbde63e04e3ca996acad1339a861f2ec68..0c27027a0ec1de9ca2640d798526d4d80c97ea5a 100644 (file)
@@ -36,8 +36,8 @@ defmodule Pleroma.Application do
         Pleroma.Emoji,
         Pleroma.Captcha,
         Pleroma.FlakeId,
-        Pleroma.ScheduledActivityWorker,
-        Pleroma.ActivityExpirationWorker
+        Pleroma.Daemons.ScheduledActivityDaemon,
+        Pleroma.Daemons.ActivityExpirationDaemon
       ] ++
         cachex_children() ++
         hackney_pool_children() ++
similarity index 96%
rename from lib/pleroma/activity_expiration_worker.ex
rename to lib/pleroma/daemons/activity_expiration_daemon.ex
index c0820c202253d6e41faf96a64a4e550b664d85ce..cab7628c4069beca0b4ca066e9da0cb60edec5b2 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.ActivityExpirationWorker do
+defmodule Pleroma.Daemons.ActivityExpirationDaemon do
   alias Pleroma.Activity
   alias Pleroma.ActivityExpiration
   alias Pleroma.Config
similarity index 96%
rename from lib/pleroma/digest_email_worker.ex
rename to lib/pleroma/daemons/digest_email_daemon.ex
index 5be7cf26b3820e50496d89aa1b82e4532d870c72..462ad2c55eaa5f3b0e9a7d5715bf1ef5f42d7cd2 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.DigestEmailWorker do
+defmodule Pleroma.Daemons.DigestEmailDaemon do
   alias Pleroma.Repo
   alias Pleroma.Workers.DigestEmailsWorker
 
similarity index 96%
rename from lib/pleroma/scheduled_activity_worker.ex
rename to lib/pleroma/daemons/scheduled_activity_daemon.ex
index c41a542de4003818d810b50ec256592b53d37a58..aee5f723a05fdc953b8afb93ca30041f1340e699 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.ScheduledActivityWorker do
+defmodule Pleroma.Daemons.ScheduledActivityDaemon do
   @moduledoc """
   Sends scheduled activities to the job queue.
   """
index 60dd3febab951e15c2d58250ab64b2cefbda4b4c..4e3e4195f7201472d15e963a770b0e6b5d141f2b 100644 (file)
@@ -3,11 +3,6 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Workers.ActivityExpirationWorker do
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "activity_expiration",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "activity_expiration"
 
   @impl Oban.Worker
@@ -18,6 +13,6 @@ defmodule Pleroma.Workers.ActivityExpirationWorker do
         },
         _job
       ) do
-    Pleroma.ActivityExpirationWorker.perform(:execute, activity_expiration_id)
+    Pleroma.Daemons.ActivityExpirationDaemon.perform(:execute, activity_expiration_id)
   end
 end
index b9aef3a926073fac9724119e0de4e53b7d260236..082f20ab7882443ebeaed821c9a0a77d15690ff8 100644 (file)
@@ -8,11 +8,6 @@ defmodule Pleroma.Workers.BackgroundWorker do
   alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
   alias Pleroma.Web.OAuth.Token.CleanWorker
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "background",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "background"
 
   @impl Oban.Worker
index ca073ce67e4a04a053c7dfdf6c0a3850c39e5a9b..3e5a836d084cf985d27516809ca733d3f3edc391 100644 (file)
@@ -5,17 +5,12 @@
 defmodule Pleroma.Workers.DigestEmailsWorker do
   alias Pleroma.User
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "digest_emails",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "digest_emails"
 
   @impl Oban.Worker
   def perform(%{"op" => "digest_email", "user_id" => user_id}, _job) do
     user_id
     |> User.get_cached_by_id()
-    |> Pleroma.DigestEmailWorker.perform()
+    |> Pleroma.Daemons.DigestEmailDaemon.perform()
   end
 end
index a4bd54a6cd0467a39f9052d92aa62daaf95bcb0a..1b7a0eb3ea58d6edf333579a75b7f658aef5007e 100644 (file)
@@ -3,11 +3,6 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Workers.MailerWorker do
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "mailer",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "mailer"
 
   @impl Oban.Worker
index a3ac22635e540ace4a38f8fd957df3a09381ebc6..455f7fc7eafe28f00e9ebd270bfaf62dbe16878d 100644 (file)
@@ -6,11 +6,6 @@ defmodule Pleroma.Workers.PublisherWorker do
   alias Pleroma.Activity
   alias Pleroma.Web.Federator
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "federator_outgoing",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "federator_outgoing"
 
   def backoff(attempt) when is_integer(attempt) do
index 3cc415ce411379fd0511741064d9b1afb2ac70bd..83d528a660f83d69dbba201366753c82f2318991 100644 (file)
@@ -5,11 +5,6 @@
 defmodule Pleroma.Workers.ReceiverWorker do
   alias Pleroma.Web.Federator
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "federator_incoming",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "federator_incoming"
 
   @impl Oban.Worker
index 936bb64d366d6e8182de61c64fc3226b83c46b87..ca7d53af1e82f6f6a4967eb9dbb5200a25e1b134 100644 (file)
@@ -3,15 +3,10 @@
 # SPDX-License-Identifier: AGPL-3.0-only
 
 defmodule Pleroma.Workers.ScheduledActivityWorker do
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "scheduled_activities",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "scheduled_activities"
 
   @impl Oban.Worker
   def perform(%{"op" => "execute", "activity_id" => activity_id}, _job) do
-    Pleroma.ScheduledActivityWorker.perform(:execute, activity_id)
+    Pleroma.Daemons.ScheduledActivityDaemon.perform(:execute, activity_id)
   end
 end
index 4fb994554e05c84d4dbb20cf38c338c89a02b727..fc490e300fd6a5c6dbaca496fdbc6c690c58f1c8 100644 (file)
@@ -7,11 +7,6 @@ defmodule Pleroma.Workers.SubscriberWorker do
   alias Pleroma.Web.Federator
   alias Pleroma.Web.Websub
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "federator_outgoing",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "federator_outgoing"
 
   @impl Oban.Worker
index 6fecc2bf946d498b371f094e90496d7a77ee5f31..b581a2f86713eebbb9c406adc9811d11a6f3957d 100644 (file)
@@ -5,11 +5,6 @@
 defmodule Pleroma.Workers.TransmogrifierWorker do
   alias Pleroma.User
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "transmogrifier",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "transmogrifier"
 
   @impl Oban.Worker
index 4c2591a5c32dc43f4f4877918f6257be9f510d0f..bea2baffb26d8dfc359c7abdcae3ced872ccfcf4 100644 (file)
@@ -6,11 +6,6 @@ defmodule Pleroma.Workers.WebPusherWorker do
   alias Pleroma.Notification
   alias Pleroma.Repo
 
-  # Note: `max_attempts` is intended to be overridden in `new/2` call
-  use Oban.Worker,
-    queue: "web_push",
-    max_attempts: 1
-
   use Pleroma.Workers.WorkerHelper, queue: "web_push"
 
   @impl Oban.Worker
index b12f198d47f5772b9a856448eff129ec61a3c2aa..358efa14a2c170073eeb81612c92628f211b1fbb 100644 (file)
@@ -27,6 +27,11 @@ defmodule Pleroma.Workers.WorkerHelper do
     queue = Keyword.fetch!(opts, :queue)
 
     quote do
+      # Note: `max_attempts` is intended to be overridden in `new/2` call
+      use Oban.Worker,
+        queue: unquote(queue),
+        max_attempts: 1
+
       def enqueue(op, params, worker_args \\ []) do
         params = Map.merge(%{"op" => op}, params)
         queue_atom = String.to_atom(unquote(queue))
similarity index 86%
rename from test/activity_expiration_worker_test.exs
rename to test/daemons/activity_expiration_daemon_test.exs
index 939d912f1a4b96787443f63d0bf87a161c993065..31f4a70a638ecdf997d4ecd1cbf9bfb39bbcaf26 100644 (file)
@@ -10,7 +10,7 @@ defmodule Pleroma.ActivityExpirationWorkerTest do
   test "deletes an activity" do
     activity = insert(:note_activity)
     expiration = insert(:expiration_in_the_past, %{activity_id: activity.id})
-    Pleroma.ActivityExpirationWorker.perform(:execute, expiration.id)
+    Pleroma.Daemons.ActivityExpirationDaemon.perform(:execute, expiration.id)
 
     refute Repo.get(Activity, activity.id)
   end
similarity index 88%
rename from test/web/digest_email_worker_test.exs
rename to test/daemons/digest_email_daemon_test.exs
index 5dfd920fa8066d33d5cec9935d2f5e1ed45f32ef..3168f3b9a76c963296c7a0843591efb6c31a0258 100644 (file)
@@ -2,11 +2,11 @@
 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.DigestEmailWorkerTest do
+defmodule Pleroma.DigestEmailDaemonTest do
   use Pleroma.DataCase
   import Pleroma.Factory
 
-  alias Pleroma.DigestEmailWorker
+  alias Pleroma.Daemons.DigestEmailDaemon
   alias Pleroma.Tests.ObanHelpers
   alias Pleroma.User
   alias Pleroma.Web.CommonAPI
@@ -23,7 +23,7 @@ defmodule Pleroma.DigestEmailWorkerTest do
     User.switch_email_notifications(user2, "digest", true)
     CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
 
-    DigestEmailWorker.perform()
+    DigestEmailDaemon.perform()
     ObanHelpers.perform_all()
     # Performing job(s) enqueued at previous step
     ObanHelpers.perform_all()
similarity index 82%
rename from test/scheduled_activity_worker_test.exs
rename to test/daemons/scheduled_activity_daemon_test.exs
index e3ad1244e09c9d44a7525ca93b5785ea1f88e174..32820b2b7eec7ee96656a1166c78c1c5cfff8ff0 100644 (file)
@@ -2,7 +2,7 @@
 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
 # SPDX-License-Identifier: AGPL-3.0-only
 
-defmodule Pleroma.ScheduledActivityWorkerTest do
+defmodule Pleroma.ScheduledActivityDaemonTest do
   use Pleroma.DataCase
   alias Pleroma.ScheduledActivity
   import Pleroma.Factory
@@ -10,7 +10,7 @@ defmodule Pleroma.ScheduledActivityWorkerTest do
   test "creates a status from the scheduled activity" do
     user = insert(:user)
     scheduled_activity = insert(:scheduled_activity, user: user, params: %{status: "hi"})
-    Pleroma.ScheduledActivityWorker.perform(:execute, scheduled_activity.id)
+    Pleroma.Daemons.ScheduledActivityDaemon.perform(:execute, scheduled_activity.id)
 
     refute Repo.get(ScheduledActivity, scheduled_activity.id)
     activity = Repo.all(Pleroma.Activity) |> Enum.find(&(&1.actor == user.ap_id))