@@ -465,7 +465,7 @@ def alias_creation_report() -> List[Tuple[str, int]]:
465
465
return res
466
466
467
467
468
- def growth_stats ():
468
+ def stats ():
469
469
"""send admin stats everyday"""
470
470
if not ADMIN_EMAIL :
471
471
LOG .w ("ADMIN_EMAIL not set, nothing to do" )
@@ -480,7 +480,7 @@ def growth_stats():
480
480
481
481
today = arrow .now ().format ()
482
482
483
- report = f"""
483
+ growth_stats = f"""
484
484
Growth Stats for { today }
485
485
486
486
nb_user: { stats_today .nb_user } - { increase_percent (stats_yesterday .nb_user , stats_today .nb_user )}
@@ -507,32 +507,16 @@ def growth_stats():
507
507
nb_referred_user_upgrade: { stats_today .nb_referred_user_paid } - { increase_percent (stats_yesterday .nb_referred_user_paid , stats_today .nb_referred_user_paid )}
508
508
"""
509
509
510
- LOG .d ("report email: %s" , report )
510
+ LOG .d ("growth_stats email: %s" , growth_stats )
511
511
512
512
send_email (
513
513
ADMIN_EMAIL ,
514
514
subject = f"SimpleLogin Growth Stats for { today } " ,
515
- plaintext = report ,
515
+ plaintext = growth_stats ,
516
516
retries = 3 ,
517
517
)
518
518
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"""
536
520
Monitoring Stats for { today }
537
521
538
522
nb_alias: { stats_today .nb_alias } - { increase_percent (stats_yesterday .nb_alias , stats_today .nb_alias )}
@@ -545,32 +529,32 @@ def daily_monitoring_report():
545
529
546
530
"""
547
531
548
- report += "\n ====================================\n "
549
- report += f"""
532
+ monitoring_report += "\n ====================================\n "
533
+ monitoring_report += f"""
550
534
# Account bounce report:
551
535
"""
552
536
553
537
for email , bounces in bounce_report ():
554
- report += f"{ email } : { bounces } \n "
538
+ monitoring_report += f"{ email } : { bounces } \n "
555
539
556
- report += f"""\n
540
+ monitoring_report += f"""\n
557
541
# Alias creation report:
558
542
"""
559
543
560
544
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 "
562
546
563
- report += f"""\n
547
+ monitoring_report += f"""\n
564
548
# Full bounce detail report:
565
549
"""
566
- report += all_bounce_report ()
550
+ monitoring_report += all_bounce_report ()
567
551
568
- LOG .d ("report email: %s" , report )
552
+ LOG .d ("monitoring_report email: %s" , monitoring_report )
569
553
570
554
send_email (
571
555
MONITORING_EMAIL ,
572
556
subject = f"SimpleLogin Monitoring Report for { today } " ,
573
- plaintext = report ,
557
+ plaintext = monitoring_report ,
574
558
retries = 3 ,
575
559
)
576
560
@@ -1040,8 +1024,7 @@ def notify_hibp():
1040
1024
help = "Choose a cron job to run" ,
1041
1025
type = str ,
1042
1026
choices = [
1043
- "growth_stats" ,
1044
- "daily_monitoring_report" ,
1027
+ "stats" ,
1045
1028
"notify_trial_end" ,
1046
1029
"notify_manual_subscription_end" ,
1047
1030
"notify_premium_end" ,
@@ -1057,12 +1040,9 @@ def notify_hibp():
1057
1040
args = parser .parse_args ()
1058
1041
# wrap in an app context to benefit from app setup like database cleanup, sentry integration, etc
1059
1042
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 ()
1066
1046
elif args .job == "notify_trial_end" :
1067
1047
LOG .d ("Notify users with trial ending soon" )
1068
1048
notify_trial_end ()
0 commit comments