X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fworkers%2Fscheduled_activity_worker.ex;h=8905f4ad000a3b7be3e4651c80e3460e78a1a8fc;hb=2b7d7bbd2dc3121488592a958c29ba6a418e0104;hp=a49834fd8cf39e0a8ec3aea44e35453178656b0f;hpb=256ff09aa8068166a9f83e3159f060fd4598af76;p=akkoma
diff --git a/lib/pleroma/workers/scheduled_activity_worker.ex b/lib/pleroma/workers/scheduled_activity_worker.ex
index a49834fd8..8905f4ad0 100644
--- a/lib/pleroma/workers/scheduled_activity_worker.ex
+++ b/lib/pleroma/workers/scheduled_activity_worker.ex
@@ -1,15 +1,44 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Workers.ScheduledActivityWorker do
- # Note: `max_attempts` is intended to be overridden in `new/1` call
- use Oban.Worker,
- queue: "scheduled_activities",
- max_attempts: Pleroma.Config.get([:workers, :retries, :compile_time_default])
+ @moduledoc """
+ The worker to post scheduled activity.
+ """
+
+ use Pleroma.Workers.WorkerHelper, queue: "scheduled_activities"
+
+ alias Pleroma.Config
+ alias Pleroma.ScheduledActivity
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
+
+ require Logger
@impl Oban.Worker
- def perform(%{"op" => "execute", "activity_id" => activity_id}) do
- Pleroma.ScheduledActivityWorker.perform(:execute, activity_id)
+ def perform(%{"activity_id" => activity_id}, _job) do
+ if Config.get([ScheduledActivity, :enabled]) do
+ case Pleroma.Repo.get(ScheduledActivity, activity_id) do
+ %ScheduledActivity{} = scheduled_activity ->
+ post_activity(scheduled_activity)
+
+ _ ->
+ Logger.error("#{__MODULE__} Couldn't find scheduled activity: #{activity_id}")
+ end
+ end
+ end
+
+ defp post_activity(%ScheduledActivity{user_id: user_id, params: params} = scheduled_activity) do
+ with {:delete, {:ok, _}} <- {:delete, ScheduledActivity.delete(scheduled_activity)},
+ {:user, %User{} = user} <- {:user, User.get_cached_by_id(user_id)},
+ {:post, {:ok, _}} <- {:post, CommonAPI.post(user, params)} do
+ :ok
+ else
+ error ->
+ Logger.error(
+ "#{__MODULE__} Couldn't create a status from the scheduled activity: #{inspect(error)}"
+ )
+ end
end
end