mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 11:02:52 +03:00
ee92ed5213
* Update activation email * Update trial upgrade emails * Remove feedback emails * Remove feedback email test * Update welcome email (and send it earlier) * Site setup emails * Add create site emails for trialers * Add check stats email * Remove dead code * Adjust site setup emails for users who are not on trial * BCC myself on all new emails * Use old phrasing in the welcome email
47 lines
1.2 KiB
Elixir
47 lines
1.2 KiB
Elixir
defmodule Mix.Tasks.SendCheckStatsEmails do
|
|
use Mix.Task
|
|
use Plausible.Repo
|
|
require Logger
|
|
|
|
@doc """
|
|
This is scheduled to run every 6 hours.
|
|
"""
|
|
|
|
def run(args) do
|
|
Application.ensure_all_started(:plausible)
|
|
execute(args)
|
|
end
|
|
|
|
def execute(args \\ []) do
|
|
q =
|
|
from(u in Plausible.Auth.User,
|
|
left_join: ce in "check_stats_emails", on: ce.user_id == u.id,
|
|
where: is_nil(ce.id),
|
|
where:
|
|
u.inserted_at > fragment("(now() at time zone 'utc') - '14 days'::interval") and
|
|
u.inserted_at < fragment("(now() at time zone 'utc') - '7 days'::interval") and
|
|
u.last_seen < fragment("(now() at time zone 'utc') - '7 days'::interval")
|
|
)
|
|
|
|
for user <- Repo.all(q) do
|
|
if Plausible.Auth.user_completed_setup?(user) do
|
|
send_check_stats_email(args, user)
|
|
end
|
|
end
|
|
end
|
|
|
|
defp send_check_stats_email(["--dry-run"], user) do
|
|
Logger.info("DRY RUN: check stats email to #{user.name}")
|
|
end
|
|
|
|
defp send_check_stats_email(_, user) do
|
|
PlausibleWeb.Email.check_stats_email(user)
|
|
|> Plausible.Mailer.deliver_now()
|
|
|
|
Repo.insert_all("check_stats_emails", [%{
|
|
user_id: user.id,
|
|
timestamp: NaiveDateTime.utc_now()
|
|
}])
|
|
end
|
|
end
|