Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature(Conversations): Suppression des données de prise de contacts après 6 mois #1027

Merged
merged 4 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions clevercloud/conversations_delete_outdated_conversations.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash -l

# delete outdated conversations

# Do not run if this env var is not set:
if [[ -z "$CRON_TENDER_SEND_VALIDATED_ENABLED" ]]; then
echo "CRON_CONVERSATIONS_DELETE_OUTDATED_CONVERSATIONS not set. Exiting..."
exit 0
fi

# About clever cloud cronjobs:
# https://www.clever-cloud.com/doc/tools/crons/

if [[ "$INSTANCE_NUMBER" != "0" ]]; then
echo "Instance number is ${INSTANCE_NUMBER}. Stop here."
exit 0
fi

# $APP_HOME is set by default by clever cloud.
cd $APP_HOME

django-admin delete_outdated_conversations.sh
3 changes: 2 additions & 1 deletion clevercloud/cron.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"0 0 * * * $ROOT/clevercloud/siaes_export_all_siae_to_file.sh",
"15 0 * * * $ROOT/clevercloud/stats_export_user_download_list_to_file.sh",
"30 0 * * * $ROOT/clevercloud/stats_export_user_search_list_to_file.sh",
"0 6 * * * $ROOT/clevercloud/conversations_delete_outdated_conversations.sh",
"0 1 * * * $ROOT/clevercloud/tenders_update_count_fields.sh",
"0 7 * * 1 $ROOT/clevercloud/siaes_sync_with_emplois_inclusion.sh",
"5 7 * * 1 $ROOT/clevercloud/siaes_sync_c2_c4.sh",
Expand All @@ -18,4 +19,4 @@
"10 9 * * * $ROOT/clevercloud/tenders_send_siae_interested_reminder_emails.sh",
"20 9 * * * $ROOT/clevercloud/tenders_send_author_incremental.sh",
"*/5 8-15 * * 1-5 $ROOT/clevercloud/tenders_send_validated.sh"
]
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.core.management.base import BaseCommand

from lemarche.conversations.models import Conversation


class Command(BaseCommand):
"""
Command to send validated tenders

Note: run via a CRON every day
Usage: python manage.py delete_outdated_conversations
"""

def handle(self, *args, **options):
oudated_conversations = Conversation.objects.oudated_conversations()
raphodn marked this conversation as resolved.
Show resolved Hide resolved
numb_delete, _ = oudated_conversations.delete()
self.stdout.write(f"Delete {numb_delete} conversation(s)")
9 changes: 9 additions & 0 deletions lemarche/conversations/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from datetime import timedelta
from uuid import uuid4

from django.conf import settings
Expand Down Expand Up @@ -33,6 +34,14 @@ def get_conv_from_uuid(self, conv_uuid: str, version=1):
else:
return self.get(Q(sender_encoded__endswith=conv_uuid) | Q(siae_encoded__endswith=conv_uuid))

def oudated_conversations(self):
raphodn marked this conversation as resolved.
Show resolved Hide resolved
"""the conversations must be deleted after six month
So we get all conversations outdated with this method (30)
"""
# we use shortcut of 30 days x 6 month because timedelta don't accept months
six_months_ago = timezone.now() - timedelta(days=30 * 6)
return self.filter(created_at__lte=six_months_ago)


class Conversation(models.Model):
KIND_SEARCH = "SEARCH"
Expand Down