-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Stability Enhancements and Bug Fixes (#510)
* Stability Enhancements and Bug Fixes * Fix ai name removal
- Loading branch information
Showing
11 changed files
with
134 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.2.6 on 2024-04-17 13:56 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("ayushma", "0051_project_tts_engine"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="document", | ||
name="failed", | ||
field=models.BooleanField(default=False), | ||
), | ||
] |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from celery import current_app | ||
from celery.schedules import crontab | ||
|
||
from ayushma.tasks.stale_cleanup import clean_stale_test_runs, clean_stale_upsert_doc | ||
|
||
|
||
@current_app.on_after_finalize.connect | ||
def setup_periodic_tasks(sender, **kwargs): | ||
sender.add_periodic_task( | ||
crontab(minute="*/30"), # Every 30 minutes | ||
clean_stale_test_runs.s(), | ||
name="clean_stale_test_runs", | ||
) | ||
sender.add_periodic_task( | ||
crontab(minute="*/30"), # Every 30 minutes | ||
clean_stale_upsert_doc.s(), | ||
name="clean_stale_upsert_doc", | ||
) |
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,52 @@ | ||
from datetime import timedelta | ||
|
||
from celery import shared_task | ||
from django.utils.timezone import now | ||
|
||
from ayushma.models.document import Document | ||
from ayushma.models.enums import StatusChoices | ||
from ayushma.models.testsuite import TestRun | ||
|
||
|
||
@shared_task(bind=True) | ||
def clean_stale_test_runs(self): | ||
try: | ||
# Get testRuns that are created over 6 hours ago and are still in RUNNING state | ||
test_runs = TestRun.objects.filter( | ||
created_at__lt=now() - timedelta(hours=6), | ||
status=StatusChoices.RUNNING, | ||
) | ||
|
||
# Cancel the testRuns | ||
for test_run in test_runs: | ||
print( | ||
f"Cleaning stale test run: {test_run.id}; Created at: {test_run.created_at}" | ||
) | ||
test_run.status = StatusChoices.FAILED | ||
test_run.save() | ||
except Exception as e: | ||
print(f"Error occurred while cleaning stale test runs: {e}") | ||
raise e | ||
|
||
|
||
@shared_task(bind=True) | ||
def clean_stale_upsert_doc(self): | ||
try: | ||
# Get stale Document objects that are still in UPLOADING state after 6 hours | ||
documents = Document.objects.filter( | ||
created_at__lt=now() - timedelta(hours=6), | ||
uploading=True, | ||
) | ||
|
||
# Set the documents to failed state | ||
for document in documents: | ||
print( | ||
f"Cleaning stale document: {document.id}; Created at: {document.created_at}" | ||
) | ||
document.failed = True | ||
document.uploading = False | ||
document.save() | ||
|
||
except Exception as e: | ||
print(f"Error occurred while cleaning stale test runs: {e}") | ||
raise e |
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
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