Make all green

This commit is contained in:
Zamil Majdy 2024-08-28 15:50:58 -05:00
parent c9989c47ec
commit b3d873a4b9
8 changed files with 50 additions and 20 deletions

View File

@ -120,7 +120,7 @@ async def create_graph_execution(
graph_id: str, graph_id: str,
graph_version: int, graph_version: int,
nodes_input: list[tuple[str, BlockInput]], nodes_input: list[tuple[str, BlockInput]],
user_id: str, user_id: str | None = None,
) -> tuple[str, list[ExecutionResult]]: ) -> tuple[str, list[ExecutionResult]]:
""" """
Create a new AgentGraphExecution record. Create a new AgentGraphExecution record.
@ -148,7 +148,7 @@ async def create_graph_execution(
}, },
"userId": user_id, "userId": user_id,
}, },
include={"AgentNodeExecutions": {"include": EXECUTION_RESULT_INCLUDE}}, include={"AgentNodeExecutions": {"include": EXECUTION_RESULT_INCLUDE}}, # type: ignore
) )
return result.id, [ return result.id, [
@ -284,7 +284,7 @@ async def get_graph_execution(
""" """
execution = await AgentGraphExecution.prisma().find_first( execution = await AgentGraphExecution.prisma().find_first(
where={"id": graph_exec_id, "userId": user_id}, where={"id": graph_exec_id, "userId": user_id},
include={"AgentNodeExecutions": {"include": EXECUTION_RESULT_INCLUDE}}, include={"AgentNodeExecutions": {"include": EXECUTION_RESULT_INCLUDE}}, # type: ignore
) )
return execution return execution

View File

@ -294,6 +294,7 @@ async def get_graphs_meta(
Args: Args:
filter_by: An optional filter to either select templates or active graphs. filter_by: An optional filter to either select templates or active graphs.
user_id: An optional user ID to filter the graphs by.
Returns: Returns:
list[GraphMeta]: A list of objects representing the retrieved graph metadata. list[GraphMeta]: A list of objects representing the retrieved graph metadata.

View File

@ -466,7 +466,7 @@ class ExecutionManager(AppService):
@expose @expose
def add_execution( def add_execution(
self, graph_id: str, data: BlockInput, user_id: str self, graph_id: str, data: BlockInput, user_id: str | None = None
) -> dict[str, Any]: ) -> dict[str, Any]:
graph: Graph | None = self.run_and_wait(get_graph(graph_id, user_id=user_id)) graph: Graph | None = self.run_and_wait(get_graph(graph_id, user_id=user_id))
if not graph: if not graph:

View File

@ -37,7 +37,8 @@ class ExecutionScheduler(AppService):
def __refresh_jobs_from_db(self, scheduler: BackgroundScheduler): def __refresh_jobs_from_db(self, scheduler: BackgroundScheduler):
schedules = self.run_and_wait(model.get_active_schedules(self.last_check)) schedules = self.run_and_wait(model.get_active_schedules(self.last_check))
for schedule in schedules: for schedule in schedules:
self.last_check = max(self.last_check, schedule.last_updated) if schedule.last_updated:
self.last_check = max(self.last_check, schedule.last_updated)
if not schedule.is_enabled: if not schedule.is_enabled:
log(f"Removing recurring job {schedule.id}: {schedule.schedule}") log(f"Removing recurring job {schedule.id}: {schedule.schedule}")

View File

@ -0,0 +1,20 @@
-- RedefineTables
PRAGMA foreign_keys=OFF;
CREATE TABLE "new_AgentGraphExecutionSchedule" (
"id" TEXT NOT NULL PRIMARY KEY,
"agentGraphId" TEXT NOT NULL,
"agentGraphVersion" INTEGER NOT NULL DEFAULT 1,
"schedule" TEXT NOT NULL,
"isEnabled" BOOLEAN NOT NULL DEFAULT true,
"inputData" TEXT NOT NULL,
"lastUpdated" DATETIME NOT NULL,
"userId" TEXT,
CONSTRAINT "AgentGraphExecutionSchedule_agentGraphId_agentGraphVersion_fkey" FOREIGN KEY ("agentGraphId", "agentGraphVersion") REFERENCES "AgentGraph" ("id", "version") ON DELETE RESTRICT ON UPDATE CASCADE,
CONSTRAINT "AgentGraphExecutionSchedule_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE SET NULL ON UPDATE CASCADE
);
INSERT INTO "new_AgentGraphExecutionSchedule" ("agentGraphId", "agentGraphVersion", "id", "inputData", "isEnabled", "lastUpdated", "schedule", "userId") SELECT "agentGraphId", "agentGraphVersion", "id", "inputData", "isEnabled", "lastUpdated", "schedule", "userId" FROM "AgentGraphExecutionSchedule";
DROP TABLE "AgentGraphExecutionSchedule";
ALTER TABLE "new_AgentGraphExecutionSchedule" RENAME TO "AgentGraphExecutionSchedule";
CREATE INDEX "AgentGraphExecutionSchedule_isEnabled_idx" ON "AgentGraphExecutionSchedule"("isEnabled");
PRAGMA foreign_key_check;
PRAGMA foreign_keys=ON;

View File

@ -0,0 +1,8 @@
-- DropForeignKey
ALTER TABLE "AgentGraphExecutionSchedule" DROP CONSTRAINT "AgentGraphExecutionSchedule_userId_fkey";
-- AlterTable
ALTER TABLE "AgentGraphExecutionSchedule" ALTER COLUMN "userId" DROP NOT NULL;
-- AddForeignKey
ALTER TABLE "AgentGraphExecutionSchedule" ADD CONSTRAINT "AgentGraphExecutionSchedule_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE;

View File

@ -12,11 +12,11 @@ generator client {
// User model to mirror Auth provider users // User model to mirror Auth provider users
model User { model User {
id String @id // This should match the Supabase user ID id String @id // This should match the Supabase user ID
email String @unique email String @unique
name String? name String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
// Relations // Relations
AgentGraphs AgentGraph[] AgentGraphs AgentGraph[]
@ -184,8 +184,8 @@ model AgentGraphExecutionSchedule {
lastUpdated DateTime @updatedAt lastUpdated DateTime @updatedAt
// Link to User model // Link to User model
userId String userId String?
user User @relation(fields: [userId], references: [id]) user User? @relation(fields: [userId], references: [id])
@@index([isEnabled]) @@index([isEnabled])
} }

View File

@ -11,11 +11,11 @@ generator client {
// User model to mirror Auth provider users // User model to mirror Auth provider users
model User { model User {
id String @id // This should match the Supabase user ID id String @id // This should match the Supabase user ID
email String @unique email String @unique
name String? name String?
createdAt DateTime @default(now()) createdAt DateTime @default(now())
updatedAt DateTime @updatedAt updatedAt DateTime @updatedAt
// Relations // Relations
AgentGraphs AgentGraph[] AgentGraphs AgentGraph[]
@ -183,8 +183,8 @@ model AgentGraphExecutionSchedule {
lastUpdated DateTime @updatedAt lastUpdated DateTime @updatedAt
// Link to User model // Link to User model
userId String userId String?
user User @relation(fields: [userId], references: [id]) user User? @relation(fields: [userId], references: [id])
@@index([isEnabled]) @@index([isEnabled])
} }