X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;f=lib%2Fpleroma%2Fworkers%2Fscheduled_activity_worker.ex;h=dd9986fe4345747749847be96f4eb0ce64576a68;hb=014f91c1c3504d7e1f4407491d42223c79c0de05;hp=5109d7f759aa77bd33a61fcc2088ba6905678d8d;hpb=652cc6ba4b7a0494cc96ef4a9bfcaa3b5e5be60e;p=akkoma
diff --git a/lib/pleroma/workers/scheduled_activity_worker.ex b/lib/pleroma/workers/scheduled_activity_worker.ex
index 5109d7f75..dd9986fe4 100644
--- a/lib/pleroma/workers/scheduled_activity_worker.ex
+++ b/lib/pleroma/workers/scheduled_activity_worker.ex
@@ -1,5 +1,5 @@
# 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
@@ -17,7 +17,7 @@ defmodule Pleroma.Workers.ScheduledActivityWorker do
require Logger
@impl Oban.Worker
- def perform(%{"activity_id" => activity_id}, _job) do
+ def perform(%Job{args: %{"activity_id" => activity_id}}) do
if Config.get([ScheduledActivity, :enabled]) do
case Pleroma.Repo.get(ScheduledActivity, activity_id) do
%ScheduledActivity{} = scheduled_activity ->
@@ -29,12 +29,14 @@ defmodule Pleroma.Workers.ScheduledActivityWorker do
end
end
- defp post_activity(%ScheduledActivity{} = scheduled_activity) do
- try do
- {:ok, scheduled_activity} = ScheduledActivity.delete(scheduled_activity)
- %User{} = user = User.get_cached_by_id(scheduled_activity.user_id)
- {:ok, _result} = CommonAPI.post(user, scheduled_activity.params)
- rescue
+ defp post_activity(%ScheduledActivity{user_id: user_id, params: params} = scheduled_activity) do
+ params = Map.new(params, fn {key, value} -> {String.to_existing_atom(key), value} end)
+
+ 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)}"