-
Notifications
You must be signed in to change notification settings - Fork 10
Document : moving transform job to celery and adding callback url #437
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
27dbfa7
commiting everything all at once
nishika26 9e92a28
format fixing
nishika26 cd2fd2c
all left changes and test case fixes
nishika26 cdc34e4
fixing fast execute job
nishika26 9225aa9
ci fail fixing
nishika26 1759942
ci failing fix trial
nishika26 34405cb
ci failing fix trial
nishika26 ef76fc7
code rabbit pr review
nishika26 0b0eb4c
code rabbit pr review
nishika26 6dd6609
small change
nishika26 4006b2e
Merge branch 'main' into enhancement/doc_transform_to_celery
nishika26 7317a6f
alembic prev migration change
nishika26 f50b5ea
pr review changes
nishika26 ac79b08
coderabbit pr review fix
nishika26 55a60f3
test case fix
nishika26 9368563
Merge branch 'main' into enhancement/doc_transform_to_celery
nishika26 f6e32ab
alembic revision fix
nishika26 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
backend/app/alembic/versions/eed36ae3c79a_alter_doc_transform_table_for_celery.py
This file contains hidden or 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,39 @@ | ||
| """alter doc transform table for celery | ||
|
|
||
| Revision ID: eed36ae3c79a | ||
| Revises: ecda6b144627 | ||
| Create Date: 2025-11-12 20:08:39.774862 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| import sqlmodel.sql.sqltypes | ||
| from sqlalchemy.dialects import postgresql | ||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = "eed36ae3c79a" | ||
| down_revision = "ecda6b144627" | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| op.add_column( | ||
| "doc_transformation_job", | ||
| sa.Column("task_id", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
| ) | ||
| op.add_column( | ||
| "doc_transformation_job", | ||
| sa.Column("trace_id", sqlmodel.sql.sqltypes.AutoString(), nullable=True), | ||
| ) | ||
| op.alter_column( | ||
| "doc_transformation_job", "created_at", new_column_name="inserted_at" | ||
| ) | ||
|
|
||
|
|
||
| def downgrade(): | ||
| op.alter_column( | ||
| "doc_transformation_job", "inserted_at", new_column_name="created_at" | ||
| ) | ||
| op.drop_column("doc_transformation_job", "trace_id") | ||
| op.drop_column("doc_transformation_job", "task_id") |
This file contains hidden or 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 hidden or 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,45 +1,97 @@ | ||
| from uuid import UUID | ||
| import logging | ||
|
|
||
| from fastapi import APIRouter, HTTPException, Query, Path as FastPath | ||
| from fastapi import APIRouter, HTTPException, Query, Path | ||
|
|
||
| from app.api.deps import CurrentUserOrgProject, SessionDep | ||
| from app.crud.doc_transformation_job import DocTransformationJobCrud | ||
| from app.models import DocTransformationJob, DocTransformationJobs | ||
| from app.crud import DocTransformationJobCrud, DocumentCrud | ||
| from app.models import ( | ||
| DocTransformationJobPublic, | ||
| DocTransformationJobsPublic, | ||
| TransformedDocumentPublic, | ||
| ) | ||
| from app.utils import APIResponse | ||
| from app.services.documents.helpers import build_job_schema, build_job_schemas | ||
| from app.core.cloud import get_cloud_storage | ||
|
|
||
|
|
||
| router = APIRouter(prefix="/documents/transformations", tags=["doc_transformation_job"]) | ||
| logger = logging.getLogger(__name__) | ||
| router = APIRouter(prefix="/documents/transformation", tags=["documents"]) | ||
|
|
||
|
|
||
| @router.get( | ||
| "/{job_id}", | ||
| description="Get the status and details of a document transformation job.", | ||
| response_model=APIResponse[DocTransformationJob], | ||
| response_model=APIResponse[DocTransformationJobPublic], | ||
| ) | ||
| def get_transformation_job( | ||
nishika26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| session: SessionDep, | ||
| current_user: CurrentUserOrgProject, | ||
| job_id: UUID = FastPath(description="Transformation job ID"), | ||
| job_id: UUID = Path(..., description="Transformation job ID"), | ||
| include_url: bool = Query( | ||
| False, description="Include a signed URL for the transformed document" | ||
| ), | ||
| ): | ||
| crud = DocTransformationJobCrud(session, current_user.project_id) | ||
| job = crud.read_one(job_id) | ||
| return APIResponse.success_response(job) | ||
| job_crud = DocTransformationJobCrud(session, current_user.project_id) | ||
| doc_crud = DocumentCrud(session, current_user.project_id) | ||
|
|
||
| job = job_crud.read_one(job_id) | ||
| storage = ( | ||
| get_cloud_storage(session=session, project_id=current_user.project_id) | ||
| if include_url | ||
| else None | ||
| ) | ||
|
|
||
| job_schema = build_job_schema( | ||
| job=job, | ||
| doc_crud=doc_crud, | ||
| include_url=include_url, | ||
| storage=storage, | ||
| ) | ||
| return APIResponse.success_response(job_schema) | ||
nishika26 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| @router.get( | ||
| "/", | ||
| description="Get the status and details of multiple document transformation jobs by IDs.", | ||
| response_model=APIResponse[DocTransformationJobs], | ||
| response_model=APIResponse[DocTransformationJobsPublic], | ||
| ) | ||
| def get_multiple_transformation_jobs( | ||
| session: SessionDep, | ||
| current_user: CurrentUserOrgProject, | ||
| job_ids: list[UUID] = Query( | ||
| description="List of transformation job IDs", min=1, max_length=100 | ||
| ..., | ||
| description="List of transformation job IDs", | ||
| min_items=1, | ||
| max_items=100, | ||
| ), | ||
| include_url: bool = Query( | ||
| False, description="Include a signed URL for each transformed document" | ||
| ), | ||
| ): | ||
| crud = DocTransformationJobCrud(session, project_id=current_user.project_id) | ||
| jobs = crud.read_each(set(job_ids)) | ||
| jobs_not_found = set(job_ids) - {job.id for job in jobs} | ||
| job_crud = DocTransformationJobCrud(session, project_id=current_user.project_id) | ||
| doc_crud = DocumentCrud(session, project_id=current_user.project_id) | ||
|
|
||
| jobs = job_crud.read_each(set(job_ids)) | ||
| jobs_found_ids = {job.id for job in jobs} | ||
| jobs_not_found = set(job_ids) - jobs_found_ids | ||
|
|
||
| storage = ( | ||
| get_cloud_storage(session=session, project_id=current_user.project_id) | ||
| if include_url | ||
| else None | ||
| ) | ||
|
|
||
| job_schemas = build_job_schemas( | ||
| jobs=jobs, | ||
| doc_crud=doc_crud, | ||
| include_url=include_url, | ||
| storage=storage, | ||
| ) | ||
|
|
||
| return APIResponse.success_response( | ||
| DocTransformationJobs(jobs=jobs, jobs_not_found=list(jobs_not_found)) | ||
| DocTransformationJobsPublic( | ||
| jobs=job_schemas, | ||
| jobs_not_found=list(jobs_not_found), | ||
| ) | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.