File tree Expand file tree Collapse file tree 4 files changed +44
-55
lines changed
Expand file tree Collapse file tree 4 files changed +44
-55
lines changed Original file line number Diff line number Diff line change 3434
3535
3636app .conf .beat_schedule = {
37- # Executes every Monday morning at 7:30 a.m.
3837 "alive-every-minute" : {
3938 "task" : "config.celery.log" ,
4039 "schedule" : crontab (minute = "*/15" ),
5756 "queue" : "long" ,
5857 },
5958 },
59+ "check-inactive-admins" : {
60+ "task" : "users.tasks.check_inactive_admins" ,
61+ # schedule to every monday at 8:00
62+ "schedule" : crontab (minute = "0" , hour = "8" ),
63+ },
6064}
6165
6266
Original file line number Diff line number Diff line change 1+ import logging
2+ from datetime import datetime , timedelta
3+
4+ from celery import shared_task
5+
6+ from utils .mattermost import DevMattermost
7+
8+ from .models import User
9+
10+ logger = logging .getLogger (__name__ )
11+
12+
13+ @shared_task
14+ def check_inactive_admins () -> int :
15+ users = User .objects .filter (
16+ is_superuser = True ,
17+ last_login__lte = datetime .now ().date () - timedelta (days = 60 ),
18+ )
19+
20+ if users .count () > 10 :
21+ markdown_message = f":warning: Nombre d'administratifs inactifs : { users .count ()} \n "
22+ markdown_message += "Le nombre est trop elevé pour être affiché ici.\n "
23+ else :
24+ markdown_message = ":warning: Les administrateurs suivants n'ont pas été actifs depuis plus de 2 mois :\n "
25+ for user in users :
26+ markdown_message += (
27+ f"- { user .email } - { user .first_name } - { user .last_name } | Last login : { user .last_login } \n "
28+ )
29+
30+ mattermost = DevMattermost (msg = markdown_message )
31+ mattermost .send ()
32+
33+ return users .count ()
Original file line number Diff line number Diff line change @@ -43,18 +43,18 @@ def send(self):
4343 return True
4444
4545
46- class StartupSparte (Mattermost ):
47- """Send message in startup-sparte, channel general """
46+ class DevMattermost (Mattermost ):
47+ """Send message in dev channel"""
4848
4949 def __init__ (self , * args , ** kwargs ):
50- super ().__init__ (channel = "startup-sparte" , * args , ** kwargs ) # noqa: B026
50+ super ().__init__ (channel = settings . MATTER_DEV_CHANNEL , * args , ** kwargs ) # noqa: B026
5151
5252
53- class SwannPrivate (Mattermost ):
54- """Send a message to Swann direct channel"""
53+ class StartupSparte (Mattermost ):
54+ """Send message in startup-sparte, channel general """
5555
5656 def __init__ (self , * args , ** kwargs ):
57- super ().__init__ (channel = "@Swann " , * args , ** kwargs ) # noqa: B026
57+ super ().__init__ (channel = "startup-sparte " , * args , ** kwargs ) # noqa: B026
5858
5959
6060class Crisp (Mattermost ):
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments