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.ScheduledActivityWorker do
7 Sends scheduled activities to the job queue.
11 alias Pleroma.ScheduledActivity
13 alias Pleroma.Web.CommonAPI
17 @schedule_interval :timer.minutes(1)
20 GenServer.start_link(__MODULE__, nil)
24 if Config.get([ScheduledActivity, :enabled]) do
32 def perform(:execute, scheduled_activity_id) do
34 {:ok, scheduled_activity} = ScheduledActivity.delete(scheduled_activity_id)
35 %User{} = user = User.get_cached_by_id(scheduled_activity.user_id)
36 {:ok, _result} = CommonAPI.post(user, scheduled_activity.params)
40 "#{__MODULE__} Couldn't create a status from the scheduled activity: #{inspect(error)}"
45 def handle_info(:perform, state) do
46 ScheduledActivity.due_activities(@schedule_interval)
47 |> Enum.each(fn scheduled_activity ->
48 PleromaJobQueue.enqueue(:scheduled_activities, __MODULE__, [:execute, scheduled_activity.id])
56 Process.send_after(self(), :perform, @schedule_interval)