-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Remove support for "second" level schedules * Install celery and packages * Add custom celery OpenSearch backend * Configure celery and celery worker * Add celery tasks endpoints to frontend * Change validate and suggest response format * Remove env load from models task * Fix validate and suggest tests * ESLint fix * bump actions/setup-python@v4 * PyCurl * Install curl dependencies * Install packages * Update apt-get * Update ap_scheduler to use celery * Remove return value from suggestions celery task * Frontend error handling * Fix _get_object_from_dict and add Task model * update manual_integration_test, add defaults * Remove task ready endpoint * Remove dependency on AsyncResult * Remove username/password from result backend * Remove python serializers * Add tasks tests * Use opensearch_save_meta_as_text=False * Add task tests and TaskResult pre * Swiple worker --loglevel=warning
- Loading branch information
1 parent
1f8778d
commit ffc02d5
Showing
34 changed files
with
1,279 additions
and
194 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
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 fastapi import APIRouter | ||
from fastapi.params import Depends | ||
from app.core.users import current_active_user | ||
from app.models.task import TaskResultResponse | ||
from app.repositories.task import TaskRepository, get_task_repository | ||
|
||
|
||
router = APIRouter( | ||
dependencies=[Depends(current_active_user)] | ||
) | ||
|
||
|
||
@router.get("/{task_id}", response_model=TaskResultResponse) | ||
def get_task( | ||
task_id: str, | ||
repository: TaskRepository = Depends(get_task_repository), | ||
): | ||
return repository.get(task_id) |
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,13 @@ | ||
# Use for local development only | ||
import os | ||
from dotenv import load_dotenv | ||
|
||
|
||
if __name__ == '__main__': | ||
# Load environment variables from .env file | ||
dotenv_path = os.path.join(os.path.dirname(__file__), '../../docker/.env-local') | ||
load_dotenv(dotenv_path) | ||
|
||
# Start the Celery worker | ||
from app.worker.app import celery_app | ||
celery_app.worker_main(['--app', 'app.worker.app.celery_app', 'worker', '-l', 'info', '-c', '4', '-Ofair', '--without-heartbeat', '--without-gossip', '--without-mingle']) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import json | ||
from datetime import datetime | ||
from enum import Enum | ||
from typing import Optional, Dict, Any | ||
from pydantic import Extra, validator | ||
from app.models.base_model import BaseModel | ||
|
||
|
||
class TaskStatus(str, Enum): | ||
PENDING = "PENDING" | ||
STARTED = "STARTED" | ||
RETRY = "RETRY" | ||
SUCCESS = "SUCCESS" | ||
FAILURE = "FAILURE" | ||
|
||
|
||
class Result(BaseModel): | ||
dataset_id: Optional[str] | ||
datasource_id: Optional[str] | ||
exc_message: Optional[list[str]] | ||
exc_module: Optional[str] | ||
exc_type: Optional[str] | ||
|
||
def dict(self, *args, **kwargs) -> Dict[str, Any]: | ||
_ignored = kwargs.pop('exclude_none') | ||
return super().dict(*args, exclude_none=True, **kwargs) | ||
|
||
class Config: | ||
extra = Extra.ignore | ||
|
||
|
||
class TaskResult(BaseModel): | ||
task_id: str | ||
status: TaskStatus | ||
kwargs: Optional[dict] | ||
result: Optional[Result] | ||
name: Optional[str] | ||
retries: Optional[int] | ||
date_done: Optional[datetime] | ||
|
||
@validator('result', pre=True) | ||
def ensure_result_is_dict(cls, value): | ||
if value is None: | ||
return None | ||
elif isinstance(value, dict): | ||
return value | ||
elif isinstance(value, str): | ||
try: | ||
return json.loads(value) | ||
except json.JSONDecodeError: | ||
raise ValueError("Invalid JSON string for 'result' field") | ||
else: | ||
raise ValueError("Invalid value for 'result' field") | ||
|
||
class Config: | ||
extra = Extra.ignore | ||
|
||
|
||
class TaskResultResponse(TaskResult): | ||
pass | ||
|
||
|
||
class TaskReadyResponse(BaseModel): | ||
is_ready: bool | ||
|
||
|
||
class TaskIdResponse(BaseModel): | ||
task_id: str | ||
|
||
|
||
class Task(BaseModel): | ||
result: TaskResult | ||
timestamp: str |
Oops, something went wrong.