diff --git a/internal/repository/prisma/dbsqlc/models.go b/internal/repository/prisma/dbsqlc/models.go index db7c4f9f9..81d7a725d 100644 --- a/internal/repository/prisma/dbsqlc/models.go +++ b/internal/repository/prisma/dbsqlc/models.go @@ -908,6 +908,7 @@ type WorkflowTriggerCronRef struct { Cron string `json:"cron"` TickerId pgtype.UUID `json:"tickerId"` Input []byte `json:"input"` + Enabled bool `json:"enabled"` } type WorkflowTriggerEventRef struct { diff --git a/internal/repository/prisma/dbsqlc/schema.sql b/internal/repository/prisma/dbsqlc/schema.sql index 0d5ecb3ae..4877ac180 100644 --- a/internal/repository/prisma/dbsqlc/schema.sql +++ b/internal/repository/prisma/dbsqlc/schema.sql @@ -597,7 +597,8 @@ CREATE TABLE "WorkflowTriggerCronRef" ( "parentId" UUID NOT NULL, "cron" TEXT NOT NULL, "tickerId" UUID, - "input" JSONB + "input" JSONB, + "enabled" BOOLEAN NOT NULL DEFAULT true ); -- CreateTable diff --git a/internal/repository/prisma/dbsqlc/tickers.sql b/internal/repository/prisma/dbsqlc/tickers.sql index 2c80c45d7..8dc94f074 100644 --- a/internal/repository/prisma/dbsqlc/tickers.sql +++ b/internal/repository/prisma/dbsqlc/tickers.sql @@ -144,11 +144,12 @@ active_cron_schedules AS ( JOIN latest_workflow_versions l ON versions."workflowId" = l."workflowId" AND versions."order" = l.max_order WHERE - "tickerId" IS NULL + "enabled" = TRUE AND + ("tickerId" IS NULL OR NOT EXISTS ( SELECT 1 FROM "Ticker" WHERE "id" = cronSchedule."tickerId" AND "isActive" = true AND "lastHeartbeatAt" >= NOW() - INTERVAL '10 seconds' ) - OR "tickerId" = @tickerId::uuid + OR "tickerId" = @tickerId::uuid) FOR UPDATE SKIP LOCKED ) UPDATE diff --git a/internal/repository/prisma/dbsqlc/tickers.sql.go b/internal/repository/prisma/dbsqlc/tickers.sql.go index a10f1e46a..f20204abf 100644 --- a/internal/repository/prisma/dbsqlc/tickers.sql.go +++ b/internal/repository/prisma/dbsqlc/tickers.sql.go @@ -206,11 +206,12 @@ active_cron_schedules AS ( JOIN latest_workflow_versions l ON versions."workflowId" = l."workflowId" AND versions."order" = l.max_order WHERE - "tickerId" IS NULL + "enabled" = TRUE AND + ("tickerId" IS NULL OR NOT EXISTS ( SELECT 1 FROM "Ticker" WHERE "id" = cronSchedule."tickerId" AND "isActive" = true AND "lastHeartbeatAt" >= NOW() - INTERVAL '10 seconds' ) - OR "tickerId" = $1::uuid + OR "tickerId" = $1::uuid) FOR UPDATE SKIP LOCKED ) UPDATE @@ -221,7 +222,7 @@ FROM active_cron_schedules WHERE cronSchedules."parentId" = active_cron_schedules."parentId" -RETURNING cronschedules."parentId", cronschedules.cron, cronschedules."tickerId", cronschedules.input, active_cron_schedules."workflowVersionId", active_cron_schedules."tenantId" +RETURNING cronschedules."parentId", cronschedules.cron, cronschedules."tickerId", cronschedules.input, cronschedules.enabled, active_cron_schedules."workflowVersionId", active_cron_schedules."tenantId" ` type PollCronSchedulesRow struct { @@ -229,6 +230,7 @@ type PollCronSchedulesRow struct { Cron string `json:"cron"` TickerId pgtype.UUID `json:"tickerId"` Input []byte `json:"input"` + Enabled bool `json:"enabled"` WorkflowVersionId pgtype.UUID `json:"workflowVersionId"` TenantId pgtype.UUID `json:"tenantId"` } @@ -247,6 +249,7 @@ func (q *Queries) PollCronSchedules(ctx context.Context, db DBTX, tickerid pgtyp &i.Cron, &i.TickerId, &i.Input, + &i.Enabled, &i.WorkflowVersionId, &i.TenantId, ); err != nil { diff --git a/internal/repository/prisma/dbsqlc/workflows.sql.go b/internal/repository/prisma/dbsqlc/workflows.sql.go index 44cf62f46..5471018a8 100644 --- a/internal/repository/prisma/dbsqlc/workflows.sql.go +++ b/internal/repository/prisma/dbsqlc/workflows.sql.go @@ -508,7 +508,7 @@ INSERT INTO "WorkflowTriggerCronRef" ( $1::uuid, $2::text, $3::jsonb -) RETURNING "parentId", cron, "tickerId", input +) RETURNING "parentId", cron, "tickerId", input, enabled ` type CreateWorkflowTriggerCronRefParams struct { @@ -525,6 +525,7 @@ func (q *Queries) CreateWorkflowTriggerCronRef(ctx context.Context, db DBTX, arg &i.Cron, &i.TickerId, &i.Input, + &i.Enabled, ) return &i, err } diff --git a/prisma/migrations/20240424091046_v0_21_9/migration.sql b/prisma/migrations/20240424091046_v0_21_9/migration.sql new file mode 100644 index 000000000..7346db4ea --- /dev/null +++ b/prisma/migrations/20240424091046_v0_21_9/migration.sql @@ -0,0 +1,2 @@ +-- AlterTable +ALTER TABLE "WorkflowTriggerCronRef" ADD COLUMN "enabled" BOOLEAN NOT NULL DEFAULT true; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 49dbcdcc0..871ada28e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -415,6 +415,9 @@ model WorkflowTriggerCronRef { // the cron expression cron String + // whether this cron is enabled or not + enabled Boolean @default(true) + // the assigned ticker ticker Ticker? @relation(fields: [tickerId], references: [id]) tickerId String? @db.Uuid