mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-23 16:40:29 +00:00
Update DigestEmailWorker to compile and send emails via queue
This commit is contained in:
parent
168dc97c37
commit
b052a9d4d0
2 changed files with 10 additions and 7 deletions
|
@ -27,7 +27,7 @@ defmodule Mix.Tasks.Pleroma.Digest do
|
||||||
|
|
||||||
patched_user = %{user | last_digest_emailed_at: last_digest_emailed_at}
|
patched_user = %{user | last_digest_emailed_at: last_digest_emailed_at}
|
||||||
|
|
||||||
:ok = Pleroma.DigestEmailWorker.run([patched_user])
|
_user = Pleroma.DigestEmailWorker.perform(patched_user)
|
||||||
Mix.shell().info("Digest email have been sent to #{nickname} (#{user.email})")
|
Mix.shell().info("Digest email have been sent to #{nickname} (#{user.email})")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,6 +1,8 @@
|
||||||
defmodule Pleroma.DigestEmailWorker do
|
defmodule Pleroma.DigestEmailWorker do
|
||||||
import Ecto.Query
|
import Ecto.Query
|
||||||
|
|
||||||
|
@queue_name :digest_emails
|
||||||
|
|
||||||
def run do
|
def run do
|
||||||
config = Pleroma.Config.get([:email_notifications, :digest])
|
config = Pleroma.Config.get([:email_notifications, :digest])
|
||||||
negative_interval = -Map.fetch!(config, :interval)
|
negative_interval = -Map.fetch!(config, :interval)
|
||||||
|
@ -15,18 +17,19 @@ defmodule Pleroma.DigestEmailWorker do
|
||||||
select: u
|
select: u
|
||||||
)
|
)
|
||||||
|> Pleroma.Repo.all()
|
|> Pleroma.Repo.all()
|
||||||
|> run()
|
|> Enum.each(&PleromaJobQueue.enqueue(@queue_name, __MODULE__, [&1]))
|
||||||
end
|
end
|
||||||
|
|
||||||
def run([]), do: :ok
|
@doc """
|
||||||
|
Send digest email to the given user.
|
||||||
def run([user | users]) do
|
Updates `last_digest_emailed_at` field for the user and returns the updated user.
|
||||||
|
"""
|
||||||
|
@spec perform(Pleroma.User.t()) :: Pleroma.User.t()
|
||||||
|
def perform(user) do
|
||||||
with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(user) do
|
with %Swoosh.Email{} = email <- Pleroma.Emails.UserEmail.digest_email(user) do
|
||||||
Pleroma.Emails.Mailer.deliver_async(email)
|
Pleroma.Emails.Mailer.deliver_async(email)
|
||||||
end
|
end
|
||||||
|
|
||||||
Pleroma.User.touch_last_digest_emailed_at(user)
|
Pleroma.User.touch_last_digest_emailed_at(user)
|
||||||
|
|
||||||
run(users)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue