Skip to content

Commit

Permalink
inform admin
Browse files Browse the repository at this point in the history
  • Loading branch information
ramibch committed Jan 4, 2024
1 parent d46ae78 commit cbfe568
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions core/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

from .models.profiles import Profile
from .email import send_email_message
from utils.telegram import report_to_admin


@db_periodic_task(crontab(hour="0", minute="5"))
Expand Down Expand Up @@ -111,16 +112,24 @@ def ask_to_verify_email():
@db_periodic_task(crontab(hour="0", minute="15"))
def remove_temporal_profiles():
# Delete all temporal profiles
Profile.objects.filter(
old_profiles = Profile.objects.filter(
category="temporal", updated__lt=datetime.now() - timedelta(days=30)
).delete()
)
message_to_admin = f"Deleted {old_profiles.count()} old temporal profiles\n\n"
old_profiles.delete()

# Delete recent temporal profiles with no fullname and no email
Profile.objects.filter(
recent_profiles = Profile.objects.filter(
category="temporal",
updated__lt=datetime.now() - timedelta(days=1),
fullname__isnull=True,
email__isnull=True,
).delete()
)
message_to_admin += f"Deleted {recent_profiles.count()} recent temporal profiles"
recent_profiles.delete()

# Inform admin about it
report_to_admin(message_to_admin)


@db_periodic_task(crontab(hour="0", minute="20"))
Expand Down

0 comments on commit cbfe568

Please sign in to comment.