-
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.
- Loading branch information
1 parent
c3625be
commit 02950da
Showing
6 changed files
with
85 additions
and
24 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.1 on 2023-08-09 16:19 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
dependencies = [ | ||
("ayushma", "0035_auto_20230731_1407"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="document", | ||
name="uploading", | ||
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,50 @@ | ||
from time import sleep | ||
|
||
from celery import shared_task | ||
from celery.exceptions import SoftTimeLimitExceeded | ||
from django.conf import settings | ||
|
||
from ayushma.models.document import Document | ||
from ayushma.models.enums import DocumentType | ||
from ayushma.utils.upsert import upsert | ||
|
||
|
||
@shared_task(bind=True, soft_time_limit=21600) # 6 hours in seconds | ||
def upsert_doc(self, document_id: str, document_url: str = None): | ||
try: | ||
sleep(5) | ||
if not settings.OPENAI_API_KEY: | ||
print("OpenAI API key not found. Skipping test run.") | ||
return | ||
|
||
document: Document = Document.objects.get(external_id=document_id) | ||
if document.document_type == DocumentType.FILE: | ||
upsert( | ||
external_id=document.project.external_id, | ||
s3_url=document_url, | ||
document_id=document.external_id, | ||
) | ||
elif document.document_type == DocumentType.URL: | ||
upsert( | ||
external_id=document.project.external_id, | ||
url=document.text_content, | ||
document_id=document.external_id, | ||
) | ||
elif document.document_type == DocumentType.TEXT: | ||
upsert( | ||
external_id=document.project.external_id, | ||
text=document.text_content, | ||
document_id=document.external_id, | ||
) | ||
else: | ||
raise Exception("Invalid document type.") | ||
|
||
document.uploading = True | ||
document.save() | ||
|
||
except SoftTimeLimitExceeded: | ||
print("SoftTimeLimitExceeded") | ||
document.uploading = False | ||
document.save() | ||
document.delete() | ||
return |
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