Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/breatheco-de/apiv2
Browse files Browse the repository at this point in the history
  • Loading branch information
jefer94 committed Feb 8, 2025
2 parents 3782a40 + 4c4bf72 commit f01d73b
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 90 deletions.
2 changes: 1 addition & 1 deletion breathecode/activity/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def get_attendancy_log_per_cohort_user(cohort_user_id: int):
logger.info("History log saved")


@task(bind=True, priority=TaskPriority.ACADEMY.value)
@task(bind=True, priority=TaskPriority.ACTIVITY.value)
def upload_activities(self, task_manager_id: int, **_):

def extract_data():
Expand Down
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()
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 breathecode/assignments/management/commands/sync_assignments.py

This file was deleted.

2 changes: 2 additions & 0 deletions breathecode/assignments/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,11 @@ class FinalProject(models.Model):


ERROR = "ERROR"
IGNORED = "IGNORED"
LEARNPACK_WEBHOOK_STATUS = (
(PENDING, "Pending"),
(DONE, "Done"),
(IGNORED, "Ignored"),
(ERROR, "Error"),
)

Expand Down
10 changes: 10 additions & 0 deletions breathecode/monitoring/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
RepositorySubscription,
RepositoryWebhook,
Supervisor,
StripeEvent,
SupervisorIssue,
)
from .signals import github_webhook
Expand Down Expand Up @@ -328,3 +329,12 @@ class NoPaginationAdmin(admin.ModelAdmin):
list_filter = ["method"]
search_fields = ["path", "method"]
actions = [delete_all]



@admin.register(StripeEvent)
class StripeEventAdmin(admin.ModelAdmin):
list_display = ('stripe_id', 'type', 'status', 'updated_at', 'created_at')
list_filter = ('status', 'type')
search_fields = ('stripe_id',)

3 changes: 3 additions & 0 deletions breathecode/registry/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
OriginalityWrapper,
ProjectValidator,
QuizValidator,
StarterValidator,
)

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -1069,6 +1070,8 @@ def test_asset(asset: Asset, log_errors=False):
validator = None
if asset.asset_type == "LESSON":
validator = LessonValidator(asset, log_errors)
if asset.asset_type == "STARTER":
validator = StarterValidator(asset, log_errors)
elif asset.asset_type == "EXERCISE":
validator = ExerciseValidator(asset, log_errors)
elif asset.asset_type == "PROJECT":
Expand Down
3 changes: 3 additions & 0 deletions breathecode/registry/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,9 @@ class ArticleValidator(AssetValidator):
warns = []
errors = ["readme"]

class StarterValidator(AssetValidator):
warns = []
errors = ["readme"]

class ExerciseValidator(AssetValidator):
warns = ["difficulty"]
Expand Down
4 changes: 3 additions & 1 deletion breathecode/sql_keywords.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"CASE",
"WHEN",
"THEN",
"END",
"IFNULL",
"ISNULL",
"COALESCE",
Expand Down Expand Up @@ -170,7 +171,8 @@
"CONVERT",
"IF",
"LAST_INSERT_ID",
"NULLIF"
"NULLIF",
"WITH"
],
"blacklist": [
"FILTER",
Expand Down

0 comments on commit f01d73b

Please sign in to comment.