Skip to content

Commit

Permalink
Store issue summary in database
Browse files Browse the repository at this point in the history
  • Loading branch information
roaga committed Sep 3, 2024
1 parent 1d3e0fb commit 5b5c797
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/migrations/versions/2e22d272d3b8_migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
"""Migration
Revision ID: 2e22d272d3b8
Revises: 96e56e375579
Create Date: 2024-09-02 23:08:36.978554
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '2e22d272d3b8'
down_revision = '96e56e375579'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('issue_summary',
sa.Column('group_id', sa.BigInteger(), nullable=False),
sa.Column('summary', sa.JSON(), nullable=False),
sa.Column('created_at', sa.DateTime(), nullable=False),
sa.PrimaryKeyConstraint('group_id')
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('issue_summary')
# ### end Alembic commands ###
10 changes: 9 additions & 1 deletion src/seer/automation/summarize/issue.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from seer.automation.agent.client import GptClient
from seer.automation.models import EventDetails
from seer.automation.summarize.models import SummarizeIssueRequest, SummarizeIssueResponse
from seer.db import DbIssueSummary, Session
from seer.dependency_injection import inject, injected


Expand Down Expand Up @@ -115,4 +116,11 @@ def run_summarize_issue(request: SummarizeIssueRequest):
),
}

return summarize_issue(request, **extra_kwargs)
summary = summarize_issue(request, **extra_kwargs)

with Session() as session:
db_state = DbIssueSummary(group_id=request.group_id, summary=summary.model_dump(mode="json"))
session.merge(db_state)
session.commit()

return summary
10 changes: 10 additions & 0 deletions src/seer/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -314,3 +314,13 @@ class DbSmokeTest(Base):
request_id: Mapped[str] = mapped_column(String(128), index=True, unique=True, nullable=False)
started_at: Mapped[datetime.datetime] = mapped_column(DateTime, nullable=False)
completed_at: Mapped[Optional[datetime.datetime]] = mapped_column(DateTime, nullable=True)


class DbIssueSummary(Base):
__tablename__ = "issue_summary"

group_id: Mapped[int] = mapped_column(BigInteger, primary_key=True)
summary: Mapped[dict] = mapped_column(JSON, nullable=False)
created_at: Mapped[datetime.datetime] = mapped_column(
DateTime, nullable=False, default=datetime.datetime.now(datetime.UTC)
)

0 comments on commit 5b5c797

Please sign in to comment.