-
Notifications
You must be signed in to change notification settings - Fork 363
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* plumb through agent_id * worker can access db to persist task agent rs * decorator works * does this actually work? * fix missing args * Squashed commit of the following: commit 2ea591d Author: Scott <[email protected]> Date: Thu Aug 15 17:34:28 2024 -0400 db changes * wire up agent task status with controller * return serialized json from tasks * . * raise job errors correctly and read back exception snippet * get task status in client * thanks tailwind * link to the indexing page * copypasta galore * fix type errors * lint * revert ui change * lint with new tools * will this fix tests? * fix lint * simplify restore * . * clean ups * small fixes * fix * feedback * lint * fixes * fixes, still need to check db changes * fe changes * fix all --------- Co-authored-by: Scott <[email protected]> Co-authored-by: giannis <[email protected]>
- Loading branch information
1 parent
75031b4
commit 3ef949f
Showing
34 changed files
with
626 additions
and
234 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
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,38 @@ | ||
""" | ||
Revision ID: ac3933258035 | ||
Revises: 08bcb9a24d9b | ||
Create Date: 2024-08-22 20:34:37.547325 | ||
""" | ||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = 'ac3933258035' | ||
down_revision: Union[str, None] = '08bcb9a24d9b' | ||
branch_labels: Union[str, Sequence[str], None] = None | ||
depends_on: Union[str, Sequence[str], None] = None | ||
|
||
|
||
def upgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.create_table('agent_tasks', | ||
sa.Column('agent_id', sa.String(), nullable=False), | ||
sa.Column('task_id', sa.String(), nullable=False), | ||
sa.Column('id', sa.String(), nullable=False), | ||
sa.Column('created_at', sa.DateTime(), nullable=True), | ||
sa.Column('updated_at', sa.DateTime(), nullable=True), | ||
sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ondelete='CASCADE'), | ||
sa.PrimaryKeyConstraint('id'), | ||
sa.UniqueConstraint('agent_id', 'task_id', name='unique_agent_task') | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table('agent_tasks') | ||
# ### end Alembic commands ### |
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,28 @@ | ||
from typing import List | ||
|
||
from sqlalchemy.orm import Session | ||
|
||
from backend.database_models.agent_task import AgentTask, SyncCeleryTaskMeta | ||
from backend.services.logger.utils import LoggerFactory | ||
from backend.services.transaction import validate_transaction | ||
|
||
logger = LoggerFactory().get_logger() | ||
|
||
|
||
@validate_transaction | ||
def create_agent_task(db: Session, agent_id: str, task_id: str) -> AgentTask: | ||
agent_task = AgentTask(agent_id=agent_id, task_id=task_id) | ||
db.add(agent_task) | ||
db.commit() | ||
db.refresh(agent_task) | ||
return agent_task | ||
|
||
|
||
@validate_transaction | ||
def get_agent_tasks_by_agent_id(db: Session, agent_id: str) -> List[SyncCeleryTaskMeta]: | ||
return ( | ||
db.query(SyncCeleryTaskMeta) | ||
.join(AgentTask, AgentTask.task_id == SyncCeleryTaskMeta.task_id) | ||
.filter(AgentTask.agent_id == agent_id) | ||
.all() | ||
) |
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,43 @@ | ||
from sqlalchemy import ( | ||
DateTime, | ||
ForeignKey, | ||
Integer, | ||
LargeBinary, | ||
String, | ||
Text, | ||
UniqueConstraint, | ||
) | ||
from sqlalchemy.orm import Mapped, mapped_column | ||
|
||
from backend.database_models.base import Base, MinimalBase | ||
|
||
|
||
class SyncCeleryTaskMeta(MinimalBase): | ||
__tablename__ = "sync_celery_taskmeta" | ||
|
||
id: Mapped[int] = mapped_column(Integer, primary_key=True) | ||
task_id: Mapped[str] = mapped_column(String(155), unique=True) | ||
status: Mapped[str] = mapped_column(String(50)) | ||
result: Mapped[bytes] = mapped_column(LargeBinary) | ||
date_done: Mapped[DateTime] = mapped_column(DateTime) | ||
traceback: Mapped[str] = mapped_column(Text) | ||
name: Mapped[str] = mapped_column(String(155)) | ||
args: Mapped[bytes] = mapped_column(LargeBinary) | ||
kwargs: Mapped[bytes] = mapped_column(LargeBinary) | ||
worker: Mapped[str] = mapped_column(String(155)) | ||
retries: Mapped[int] = mapped_column(Integer) | ||
queue: Mapped[str] = mapped_column(String(155)) | ||
|
||
|
||
class AgentTask(Base): | ||
__tablename__ = "agent_tasks" | ||
|
||
agent_id: Mapped[str] = mapped_column( | ||
ForeignKey("agents.id", ondelete="CASCADE"), nullable=False | ||
) | ||
|
||
task_id: Mapped[str] = mapped_column(nullable=False) | ||
|
||
__table_args__ = ( | ||
UniqueConstraint("agent_id", "task_id", name="unique_agent_task"), | ||
) |
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
Oops, something went wrong.