Merge develop
[akkoma] / lib / pleroma / application.ex
index 86c348a0d64c5669a7b033fd59bd56a08b701eaa..8887e393536db2ef6a60bd8ee5c2ce979a40925a 100644 (file)
@@ -115,6 +115,10 @@ defmodule Pleroma.Application do
         %{
           id: Pleroma.ScheduledActivityWorker,
           start: {Pleroma.ScheduledActivityWorker, :start_link, []}
+        },
+        %{
+          id: Pleroma.QuantumScheduler,
+          start: {Pleroma.QuantumScheduler, :start_link, []}
         }
       ] ++
         hackney_pool_children() ++
@@ -161,7 +165,9 @@ defmodule Pleroma.Application do
     # See http://elixir-lang.org/docs/stable/elixir/Supervisor.html
     # for other strategies and supported options
     opts = [strategy: :one_for_one, name: Pleroma.Supervisor]
-    Supervisor.start_link(children, opts)
+    result = Supervisor.start_link(children, opts)
+    :ok = after_supervisor_start()
+    result
   end
 
   defp setup_instrumenters do
@@ -226,4 +232,19 @@ defmodule Pleroma.Application do
       :hackney_pool.child_spec(pool, options)
     end
   end
+
+  defp after_supervisor_start do
+    with digest_config <- Application.get_env(:pleroma, :email_notifications)[:digest],
+         true <- digest_config[:active],
+         %Crontab.CronExpression{} = schedule <-
+           Crontab.CronExpression.Parser.parse!(digest_config[:schedule]) do
+      Pleroma.QuantumScheduler.new_job()
+      |> Quantum.Job.set_name(:digest_emails)
+      |> Quantum.Job.set_schedule(schedule)
+      |> Quantum.Job.set_task(&Pleroma.DigestEmailWorker.run/0)
+      |> Pleroma.QuantumScheduler.add_job()
+    end
+
+    :ok
+  end
 end