- Mastodon API: Unsubscribe followers when they unfollow a user
- AdminAPI: Add "godmode" while fetching user statuses (i.e. admin can see private statuses)
- Improve digest email template
-- Replaced [pleroma_job_queue](https://git.pleroma.social/pleroma/pleroma_job_queue) with [Oban](https://github.com/sorentwo/oban)
+- Replaced [pleroma_job_queue](https://git.pleroma.social/pleroma/pleroma_job_queue) and `Pleroma.Web.Federator.RetryQueue` with [Oban](https://github.com/sorentwo/oban) (see [`docs/config.md`](docs/config.md) on migrating customized worker / retry settings).
- Introduced [quantum](https://github.com/quantum-elixir/quantum-core) job scheduler
### Fixed
config :pleroma, Oban,
repo: Pleroma.Repo,
verbose: false,
- prune: {:maxage, 60 * 60 * 24 * 7},
+ prune: {:maxlen, 1500},
queues: [
activity_expiration: 10,
federator_incoming: 50,
queues: false,
prune: :disabled
+config :pleroma, Pleroma.Scheduler, jobs: []
+
config :pleroma, Pleroma.ScheduledActivity,
daily_user_limit: 2,
total_user_limit: 3,
[Oban](https://github.com/sorentwo/oban) asynchronous job processor configuration.
+Configuration options described in [Oban readme](https://github.com/sorentwo/oban#usage):
+* `repo` - app's Ecto repo (`Pleroma.Repo`)
+* `verbose` - logs verbosity
+* `prune` - non-retryable jobs [pruning settings](https://github.com/sorentwo/oban#pruning) (`:disabled` / `{:maxlen, value}` / `{:maxage, value}`)
+* `queues` - job queues (see below)
+
Pleroma has the following queues:
+* `activity_expiration` - Activity expiration
* `federator_outgoing` - Outgoing federation
* `federator_incoming` - Incoming federation
-* `mailer` - Email sender, see [`Pleroma.Emails.Mailer`](#pleroma-emails-mailer)
+* `mailer` - Email sender, see [`Pleroma.Emails.Mailer`](#pleromaemailsmailer)
* `transmogrifier` - Transmogrifier
* `web_push` - Web push notifications
-* `scheduled_activities` - Scheduled activities, see [`Pleroma.ScheduledActivities`](#pleromascheduledactivity)
+* `scheduled_activities` - Scheduled activities, see [`Pleroma.ScheduledActivity`](#pleromascheduledactivity)
Example:
```elixir
config :pleroma, Oban,
repo: Pleroma.Repo,
+ verbose: false,
+ prune: {:maxlen, 1500},
queues: [
federator_incoming: 50,
federator_outgoing: 50
This config contains two queues: `federator_incoming` and `federator_outgoing`. Both have the number of max concurrent jobs set to `50`.
+### Migrating `pleroma_job_queue` settings
+
+`config :pleroma_job_queue, :queues` is replaced by `config :pleroma, Oban, :queues` and uses the same format (keys are queues' names, values are max concurrent jobs numbers).
+
+### Note on running with PostgreSQL in silent mode
+
+If you are running PostgreSQL in [`silent_mode`](https://postgresqlco.nf/en/doc/param/silent_mode?version=9.1), it's advised to set [`log_destination`](https://postgresqlco.nf/en/doc/param/log_destination?version=9.1) to `syslog`,
+otherwise `postmaster.log` file may grow because of "you don't own a lock of type ShareLock" warnings (see https://github.com/sorentwo/oban/issues/52).
+
## :workers
Includes custom worker options not interpretable directly by `Oban`.
* `retries` — keyword lists where keys are `Oban` queues (see above) and values are numbers of max attempts for failed jobs.
+Example:
+
+```elixir
+config :pleroma, :workers,
+ retries: [
+ federator_incoming: 5,
+ federator_outgoing: 5
+ ]
+```
+
+### Migrating `Pleroma.Web.Federator.RetryQueue` settings
+
+* `max_retries` is replaced with `config :pleroma, :workers, retries: [federator_outgoing: 5]`
+* `enabled: false` corresponds to `config :pleroma, :workers, retries: [federator_outgoing: 1]`
+* deprecated options: `max_jobs`, `initial_timeout`
+
## Pleroma.Web.Metadata
* `providers`: a list of metadata providers to enable. Providers available:
* Pleroma.Web.Metadata.Providers.OpenGraph
]
```
+## Pleroma.Scheduler
+
+Configuration for [Quantum](https://github.com/quantum-elixir/quantum-core) jobs scheduler.
+
+See [Quantum readme](https://github.com/quantum-elixir/quantum-core#usage) for the list of supported options.
+
+Example:
+
+```elixir
+config :pleroma, Pleroma.Scheduler,
+ global: true,
+ overlap: true,
+ timezone: :utc,
+ jobs: [{"0 */6 * * * *", {Pleroma.Web.Websub, :refresh_subscriptions, []}}]
+```
+
+The above example defines a single job which invokes `Pleroma.Web.Websub.refresh_subscriptions()` every 6 hours ("0 */6 * * * *", [crontab format](https://en.wikipedia.org/wiki/Cron)).
+
## Pleroma.ScheduledActivity
* `daily_user_limit`: the number of scheduled activities a user is allowed to create in a single day (Default: `25`)
alias Pleroma.Repo
alias Pleroma.User
alias Pleroma.Web.CommonAPI
- alias Pleroma.Workers.BackgroundWorker
+ alias Pleroma.Workers.ActivityExpirationWorker
require Logger
use GenServer
import Ecto.Query
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
@schedule_interval :timer.minutes(1)
"op" => "activity_expiration",
"activity_expiration_id" => expiration.id
}
- |> BackgroundWorker.new(worker_args(:activity_expiration))
+ |> ActivityExpirationWorker.new(worker_args(:activity_expiration))
|> Repo.insert()
end)
hackney_pool_children() ++
[
Pleroma.Stats,
- {Oban, Application.get_env(:pleroma, Oban)},
+ {Oban, Pleroma.Config.get(Oban)},
%{
id: :web_push_init,
start: {Task, :start_link, [&Pleroma.Web.Push.init/0]},
defmodule Pleroma.DigestEmailWorker do
alias Pleroma.Repo
- alias Pleroma.Workers.Mailer, as: MailerWorker
+ alias Pleroma.Workers.MailerWorker
import Ecto.Query
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
def perform do
config = Pleroma.Config.get([:email_notifications, :digest])
"""
alias Pleroma.Repo
- alias Pleroma.Workers.Mailer, as: MailerWorker
+ alias Pleroma.Workers.MailerWorker
alias Swoosh.DeliveryError
@otp_app :pleroma
@spec enabled?() :: boolean()
def enabled?, do: Pleroma.Config.get([__MODULE__, :enabled])
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
@doc "add email to queue"
def deliver_async(email, config \\ []) do
@schedule_interval :timer.minutes(1)
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
def start_link(_) do
GenServer.start_link(__MODULE__, nil)
@strict_local_nickname_regex ~r/^[a-zA-Z\d]+$/
@extended_local_nickname_regex ~r/^[a-zA-Z\d_-]+$/
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
schema "users" do
field(:bio, :string)
require Logger
require Pleroma.Constants
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
# For Announce activities, we filter the recipients based on following status for any actors
# that match actual users. See issue #164 for more information about why this is necessary.
recv_timeout: 10_000
]
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
def perform(:prefetch, url) do
Logger.info("Prefetching #{inspect(url)}")
end
def publish_one(%{actor_id: actor_id} = params) do
- actor = User.get_by_id(actor_id)
+ actor = User.get_cached_by_id(actor_id)
params
|> Map.delete(:actor_id)
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.ActivityPub.Visibility
alias Pleroma.Web.Federator
- alias Pleroma.Workers.Transmogrifier, as: TransmogrifierWorker
+ alias Pleroma.Workers.TransmogrifierWorker
import Ecto.Query
require Logger
require Pleroma.Constants
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
@doc """
Modifies an incoming AP object (mastodon format) to our internal format.
alias Pleroma.Web.Federator.Publisher
alias Pleroma.Web.OStatus
alias Pleroma.Web.Websub
- alias Pleroma.Workers.Publisher, as: PublisherWorker
- alias Pleroma.Workers.Receiver, as: ReceiverWorker
- alias Pleroma.Workers.Subscriber, as: SubscriberWorker
+ alias Pleroma.Workers.PublisherWorker
+ alias Pleroma.Workers.ReceiverWorker
+ alias Pleroma.Workers.SubscriberWorker
require Logger
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
def init do
# To do: consider removing this call in favor of scheduled execution (`quantum`-based)
alias Pleroma.Activity
alias Pleroma.Config
alias Pleroma.User
- alias Pleroma.Workers.Publisher, as: PublisherWorker
+ alias Pleroma.Workers.PublisherWorker
require Logger
"""
@spec enqueue_one(module(), Map.t()) :: :ok
def enqueue_one(module, %{} = params) do
- worker_args =
- if max_attempts = Pleroma.Config.get([:workers, :retries, :federator_outgoing]) do
- [max_attempts: max_attempts]
- else
- []
- end
+ worker_args = Pleroma.Workers.WorkerHelper.worker_args(:federator_outgoing)
%{"op" => "publish_one", "module" => to_string(module), "params" => params}
|> PublisherWorker.new(worker_args)
alias Pleroma.Web.OAuth.Token
alias Pleroma.Workers.BackgroundWorker
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
def start_link(_), do: GenServer.start_link(__MODULE__, %{})
defmodule Pleroma.Web.Push do
alias Pleroma.Repo
- alias Pleroma.Workers.WebPusher
+ alias Pleroma.Workers.WebPusherWorker
require Logger
- defdelegate worker_args(queue), to: Pleroma.Workers.Helper
+ import Pleroma.Workers.WorkerHelper, only: [worker_args: 1]
def init do
unless enabled() do
def send(notification) do
%{"op" => "web_push", "notification_id" => notification.id}
- |> WebPusher.new(worker_args(:web_push))
+ |> WebPusherWorker.new(worker_args(:web_push))
|> Repo.insert()
end
end
end
def publish_one(%{recipient_id: recipient_id} = params) do
- recipient = User.get_by_id(recipient_id)
+ recipient = User.get_cached_by_id(recipient_id)
params
|> Map.delete(:recipient_id)
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# 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
+
+ @impl Oban.Worker
+ def perform(
+ %{
+ "op" => "activity_expiration",
+ "activity_expiration_id" => activity_expiration_id
+ },
+ _job
+ ) do
+ Pleroma.ActivityExpirationWorker.perform(:execute, activity_expiration_id)
+ end
+end
alias Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy
alias Pleroma.Web.OAuth.Token.CleanWorker
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "background",
max_attempts: 1
@impl Oban.Worker
def perform(%{"op" => "fetch_initial_posts", "user_id" => user_id}, _job) do
- user = User.get_by_id(user_id)
+ user = User.get_cached_by_id(user_id)
User.perform(:fetch_initial_posts, user)
end
def perform(%{"op" => "deactivate_user", "user_id" => user_id, "status" => status}, _job) do
- user = User.get_by_id(user_id)
+ user = User.get_cached_by_id(user_id)
User.perform(:deactivate_async, user, status)
end
def perform(%{"op" => "delete_user", "user_id" => user_id}, _job) do
- user = User.get_by_id(user_id)
+ user = User.get_cached_by_id(user_id)
User.perform(:delete, user)
end
},
_job
) do
- blocker = User.get_by_id(blocker_id)
+ blocker = User.get_cached_by_id(blocker_id)
User.perform(:blocks_import, blocker, blocked_identifiers)
end
},
_job
) do
- follower = User.get_by_id(follower_id)
+ follower = User.get_cached_by_id(follower_id)
User.perform(:follow_import, follower, followed_identifiers)
end
activity = Activity.get_by_id(activity_id)
Pleroma.Web.RichMedia.Helpers.perform(:fetch, activity)
end
-
- def perform(
- %{"op" => "activity_expiration", "activity_expiration_id" => activity_expiration_id},
- _job
- ) do
- Pleroma.ActivityExpirationWorker.perform(:execute, activity_expiration_id)
- end
end
+++ /dev/null
-# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
-# SPDX-License-Identifier: AGPL-3.0-only
-
-defmodule Pleroma.Workers.Helper do
- def worker_args(queue) do
- if max_attempts = Pleroma.Config.get([:workers, :retries, queue]) do
- [max_attempts: max_attempts]
- else
- []
- end
- end
-end
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Workers.Mailer do
+defmodule Pleroma.Workers.MailerWorker do
alias Pleroma.User
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "mailer",
max_attempts: 1
@impl Oban.Worker
def perform(%{"op" => "email", "encoded_email" => encoded_email, "config" => config}, _job) do
- email =
- encoded_email
- |> Base.decode64!()
- |> :erlang.binary_to_term()
-
- Pleroma.Emails.Mailer.deliver(email, config)
+ encoded_email
+ |> Base.decode64!()
+ |> :erlang.binary_to_term()
+ |> Pleroma.Emails.Mailer.deliver(config)
end
def perform(%{"op" => "digest_email", "user_id" => user_id}, _job) do
- user = User.get_by_id(user_id)
- Pleroma.DigestEmailWorker.perform(user)
+ user_id
+ |> User.get_cached_by_id()
+ |> Pleroma.DigestEmailWorker.perform()
end
end
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Workers.Publisher do
+defmodule Pleroma.Workers.PublisherWorker do
alias Pleroma.Activity
alias Pleroma.Web.Federator
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "federator_outgoing",
max_attempts: 1
+ def backoff(attempt) when is_integer(attempt) do
+ Pleroma.Workers.WorkerHelper.sidekiq_backoff(attempt, 5)
+ end
+
@impl Oban.Worker
def perform(%{"op" => "publish", "activity_id" => activity_id}, _job) do
activity = Activity.get_by_id(activity_id)
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Workers.Receiver do
+defmodule Pleroma.Workers.ReceiverWorker do
alias Pleroma.Web.Federator
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "federator_incoming",
max_attempts: 1
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.ScheduledActivityWorker do
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "scheduled_activities",
max_attempts: 1
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Workers.Subscriber do
+defmodule Pleroma.Workers.SubscriberWorker do
alias Pleroma.Repo
alias Pleroma.Web.Federator
alias Pleroma.Web.Websub
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "federator_outgoing",
max_attempts: 1
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Workers.Transmogrifier do
+defmodule Pleroma.Workers.TransmogrifierWorker do
alias Pleroma.User
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "transmogrifier",
max_attempts: 1
@impl Oban.Worker
def perform(%{"op" => "user_upgrade", "user_id" => user_id}, _job) do
- user = User.get_by_id(user_id)
+ user = User.get_cached_by_id(user_id)
Pleroma.Web.ActivityPub.Transmogrifier.perform(:user_upgrade, user)
end
end
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Workers.WebPusher do
+defmodule Pleroma.Workers.WebPusherWorker do
alias Pleroma.Notification
alias Pleroma.Repo
- # Note: `max_attempts` is intended to be overridden in `new/1` call
+ # Note: `max_attempts` is intended to be overridden in `new/2` call
use Oban.Worker,
queue: "web_push",
max_attempts: 1
--- /dev/null
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Workers.WorkerHelper do
+ alias Pleroma.Config
+
+ def worker_args(queue) do
+ case Config.get([:workers, :retries, queue]) do
+ nil -> []
+ max_attempts -> [max_attempts: max_attempts]
+ end
+ end
+
+ def sidekiq_backoff(attempt, pow \\ 4, base_backoff \\ 15) do
+ backoff =
+ :math.pow(attempt, pow) +
+ base_backoff +
+ :rand.uniform(2 * base_backoff) * attempt
+
+ trunc(backoff)
+ end
+end
"id" => "pleroma:fakeid"
}
},
- all_enqueued(worker: Pleroma.Workers.Publisher)
+ all_enqueued(worker: Pleroma.Workers.PublisherWorker)
)
end
end
alias Pleroma.Web.ActivityPub.UserView
alias Pleroma.Web.ActivityPub.Utils
alias Pleroma.Web.CommonAPI
- alias Pleroma.Workers.Receiver, as: ReceiverWorker
+ alias Pleroma.Workers.ReceiverWorker
setup_all do
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
alias Pleroma.Tests.ObanHelpers
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Federator
- alias Pleroma.Workers.Publisher, as: PublisherWorker
+ alias Pleroma.Workers.PublisherWorker
use Pleroma.DataCase
use Oban.Testing, repo: Pleroma.Repo
alias Pleroma.Web.Websub
alias Pleroma.Web.Websub.WebsubClientSubscription
alias Pleroma.Web.Websub.WebsubServerSubscription
- alias Pleroma.Workers.Subscriber, as: SubscriberWorker
+ alias Pleroma.Workers.SubscriberWorker
import Pleroma.Factory
import Tesla.Mock