1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Daemons.ScheduledActivityDaemon do
7 Sends scheduled activities to the job queue.
11 alias Pleroma.ScheduledActivity
13 alias Pleroma.Web.CommonAPI
18 @schedule_interval :timer.minutes(1)
21 GenServer.start_link(__MODULE__, nil)
25 if Config.get([ScheduledActivity, :enabled]) do
33 def perform(:execute, scheduled_activity_id) do
35 {:ok, scheduled_activity} = ScheduledActivity.delete(scheduled_activity_id)
36 %User{} = user = User.get_cached_by_id(scheduled_activity.user_id)
37 {:ok, _result} = CommonAPI.post(user, scheduled_activity.params)
41 "#{__MODULE__} Couldn't create a status from the scheduled activity: #{inspect(error)}"
46 def handle_info(:perform, state) do
47 ScheduledActivity.due_activities(@schedule_interval)
48 |> Enum.each(fn scheduled_activity ->
49 Pleroma.Workers.ScheduledActivityWorker.enqueue(
51 %{"activity_id" => scheduled_activity.id}
60 Process.send_after(self(), :perform, @schedule_interval)