Skip to content

Commit 3d1a960

Browse files
committed
fix duplicated stats
1 parent 6a520e1 commit 3d1a960

File tree

2 files changed

+19
-45
lines changed

2 files changed

+19
-45
lines changed

cron.py

Lines changed: 18 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -465,7 +465,7 @@ def alias_creation_report() -> List[Tuple[str, int]]:
465465
return res
466466

467467

468-
def growth_stats():
468+
def stats():
469469
"""send admin stats everyday"""
470470
if not ADMIN_EMAIL:
471471
LOG.w("ADMIN_EMAIL not set, nothing to do")
@@ -480,7 +480,7 @@ def growth_stats():
480480

481481
today = arrow.now().format()
482482

483-
report = f"""
483+
growth_stats = f"""
484484
Growth Stats for {today}
485485
486486
nb_user: {stats_today.nb_user} - {increase_percent(stats_yesterday.nb_user, stats_today.nb_user)}
@@ -507,32 +507,16 @@ def growth_stats():
507507
nb_referred_user_upgrade: {stats_today.nb_referred_user_paid} - {increase_percent(stats_yesterday.nb_referred_user_paid, stats_today.nb_referred_user_paid)}
508508
"""
509509

510-
LOG.d("report email: %s", report)
510+
LOG.d("growth_stats email: %s", growth_stats)
511511

512512
send_email(
513513
ADMIN_EMAIL,
514514
subject=f"SimpleLogin Growth Stats for {today}",
515-
plaintext=report,
515+
plaintext=growth_stats,
516516
retries=3,
517517
)
518518

519-
520-
def daily_monitoring_report():
521-
"""send monitoring stats of the previous day"""
522-
if not MONITORING_EMAIL:
523-
LOG.w("MONITORING_EMAIL not set, nothing to do")
524-
return
525-
526-
stats_today = compute_metric2()
527-
stats_yesterday = (
528-
Metric2.filter(Metric2.date < stats_today.date)
529-
.order_by(Metric2.date.desc())
530-
.first()
531-
)
532-
533-
today = arrow.now().format()
534-
535-
report = f"""
519+
monitoring_report = f"""
536520
Monitoring Stats for {today}
537521
538522
nb_alias: {stats_today.nb_alias} - {increase_percent(stats_yesterday.nb_alias, stats_today.nb_alias)}
@@ -545,32 +529,32 @@ def daily_monitoring_report():
545529
546530
"""
547531

548-
report += "\n====================================\n"
549-
report += f"""
532+
monitoring_report += "\n====================================\n"
533+
monitoring_report += f"""
550534
# Account bounce report:
551535
"""
552536

553537
for email, bounces in bounce_report():
554-
report += f"{email}: {bounces}\n"
538+
monitoring_report += f"{email}: {bounces}\n"
555539

556-
report += f"""\n
540+
monitoring_report += f"""\n
557541
# Alias creation report:
558542
"""
559543

560544
for email, nb_alias, date in alias_creation_report():
561-
report += f"{email}, {date}: {nb_alias}\n"
545+
monitoring_report += f"{email}, {date}: {nb_alias}\n"
562546

563-
report += f"""\n
547+
monitoring_report += f"""\n
564548
# Full bounce detail report:
565549
"""
566-
report += all_bounce_report()
550+
monitoring_report += all_bounce_report()
567551

568-
LOG.d("report email: %s", report)
552+
LOG.d("monitoring_report email: %s", monitoring_report)
569553

570554
send_email(
571555
MONITORING_EMAIL,
572556
subject=f"SimpleLogin Monitoring Report for {today}",
573-
plaintext=report,
557+
plaintext=monitoring_report,
574558
retries=3,
575559
)
576560

@@ -1040,8 +1024,7 @@ def notify_hibp():
10401024
help="Choose a cron job to run",
10411025
type=str,
10421026
choices=[
1043-
"growth_stats",
1044-
"daily_monitoring_report",
1027+
"stats",
10451028
"notify_trial_end",
10461029
"notify_manual_subscription_end",
10471030
"notify_premium_end",
@@ -1057,12 +1040,9 @@ def notify_hibp():
10571040
args = parser.parse_args()
10581041
# wrap in an app context to benefit from app setup like database cleanup, sentry integration, etc
10591042
with create_light_app().app_context():
1060-
if args.job == "growth_stats":
1061-
LOG.d("Compute growth Stats")
1062-
growth_stats()
1063-
if args.job == "daily_monitoring_report":
1064-
LOG.d("Send out daily monitoring stats")
1065-
daily_monitoring_report()
1043+
if args.job == "stats":
1044+
LOG.d("Compute growth and daily monitoring stats")
1045+
stats()
10661046
elif args.job == "notify_trial_end":
10671047
LOG.d("Notify users with trial ending soon")
10681048
notify_trial_end()

crontab.yml

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
jobs:
22
- name: SimpleLogin growth stats
3-
command: python /code/cron.py -j growth_stats
4-
shell: /bin/bash
5-
schedule: "0 1 * * *"
6-
captureStderr: true
7-
8-
- name: SimpleLogin monitoring stats
9-
command: python /code/cron.py -j daily_monitoring_report
3+
command: python /code/cron.py -j stats
104
shell: /bin/bash
115
schedule: "0 0 * * *"
126
captureStderr: true

0 commit comments

Comments
 (0)