-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/breatheco-de/apiv2
- Loading branch information
Showing
9 changed files
with
58 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 13 additions & 7 deletions
20
breathecode/assignments/management/commands/assignments_garbage_collect.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,23 @@ | ||
from django.core.management.base import BaseCommand | ||
from django.db import connection | ||
from django.utils import timezone | ||
from datetime import timedelta | ||
from breathecode.assignments.models import LearnPackWebhook | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Clean data from marketing module" | ||
|
||
def handle(self, *args, **options): | ||
|
||
self.delete_old_webhooks() | ||
|
||
def delete_old_webhooks(self): | ||
cursor = connection.cursor() | ||
# status = 'ERROR' or status = 'PENDING' AND | ||
cursor.execute("DELETE FROM assignments_learnpackwebhook WHERE created_at < NOW() - INTERVAL '30 days'") | ||
def delete_old_webhooks(self, batch_size=1000): | ||
thirty_days_ago = timezone.now() - timedelta(days=5) | ||
while True: | ||
old_webhooks = LearnPackWebhook.objects.filter(created_at__lt=thirty_days_ago).exclude( | ||
status__in=["ERROR", "PENDING"] | ||
)[:batch_size] | ||
|
||
if not old_webhooks.exists(): | ||
break | ||
|
||
cursor.execute("DELETE FROM assignments_learnpackwebhook WHERE status <> 'ERROR' AND status <> 'PENDING'") | ||
old_webhooks.delete() |
23 changes: 23 additions & 0 deletions
23
breathecode/assignments/management/commands/process_assignment_telemetry.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
from django.core.management.base import BaseCommand | ||
from breathecode.assignments.models import LearnPackWebhook | ||
from breathecode.assignments.tasks import async_learnpack_webhook | ||
|
||
|
||
class Command(BaseCommand): | ||
help = "Sync academies from old breathecode" | ||
|
||
def handle(self, *args, **options): | ||
pending_webhooks = LearnPackWebhook.objects.filter(status="PENDING").order_by("created_at") | ||
processed_webhooks = {} | ||
|
||
for webhook in pending_webhooks: | ||
key = (webhook.payload.get("user_id"), webhook.payload.get("asset_id") or webhook.payload.get("slug")) | ||
if key not in processed_webhooks: | ||
self.stdout.write(self.style.NOTICE(f"Enqueued telemetry for user,asset: {str(key)}")) | ||
async_learnpack_webhook.delay(webhook.id) | ||
processed_webhooks[key] = webhook.id | ||
else: | ||
self.stdout.write(self.style.NOTICE(f"Ignored telemetry for user,asset: {str(key)}")) | ||
webhook.status = "IGNORED" | ||
webhook.status_text = "Ignored because a more recent telemetry batch was obtained." | ||
webhook.save() |
81 changes: 0 additions & 81 deletions
81
breathecode/assignments/management/commands/sync_assignments.py
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters