|
6 | 6 | WorkflowExecutionStatus, |
7 | 7 | } from "@dafthunk/types"; |
8 | 8 | import * as crypto from "crypto"; |
9 | | -import { and, desc, eq, inArray, SQL, sql } from "drizzle-orm"; |
| 9 | +import { and, desc, eq, inArray, lte, SQL, sql } from "drizzle-orm"; |
10 | 10 | import { alias } from "drizzle-orm/sqlite-core"; |
11 | 11 | import { v7 as uuidv7 } from "uuid"; |
12 | 12 |
|
@@ -1207,31 +1207,24 @@ export async function getDueCronTriggers( |
1207 | 1207 | selectedDeployment: selectedDeployment, |
1208 | 1208 | }) |
1209 | 1209 | .from(cronTriggers) |
1210 | | - .where( |
1211 | | - and( |
1212 | | - eq(cronTriggers.active, true), |
1213 | | - sql`${cronTriggers.nextRunAt} <= ${Math.floor(now.getTime() / 1000)}` |
1214 | | - ) |
1215 | | - ) |
| 1210 | + .where(and(eq(cronTriggers.active, true), lte(cronTriggers.nextRunAt, now))) |
1216 | 1211 | .innerJoin(workflows, eq(workflows.id, cronTriggers.workflowId)) |
1217 | | - .innerJoin(latestByWorkflow, eq(latestByWorkflow.workflowId, workflows.id)) |
1218 | | - .innerJoin( |
| 1212 | + .leftJoin(latestByWorkflow, eq(latestByWorkflow.workflowId, workflows.id)) |
| 1213 | + .leftJoin( |
1219 | 1214 | latestDeployment, |
1220 | 1215 | and( |
1221 | 1216 | eq(latestDeployment.workflowId, latestByWorkflow.workflowId), |
1222 | 1217 | eq(latestDeployment.version, latestByWorkflow.latestVersion) |
1223 | 1218 | ) |
1224 | 1219 | ) |
1225 | | - .leftJoin( |
1226 | | - selectedDeployment, |
1227 | | - and( |
1228 | | - eq(selectedDeployment.workflowId, workflows.id), |
1229 | | - eq(selectedDeployment.version, cronTriggers.versionNumber) |
1230 | | - ) |
1231 | | - ) |
1232 | 1220 | .all(); |
1233 | 1221 |
|
1234 | | - return rows.map((r) => ({ |
| 1222 | + return rows |
| 1223 | + .filter(r => |
| 1224 | + r.cronTrigger.versionAlias === 'dev' || |
| 1225 | + (r.cronTrigger.versionAlias === 'latest' && r.latestDeployment) || |
| 1226 | + (r.cronTrigger.versionAlias === 'version' && r.selectedDeployment) |
| 1227 | + ).map((r) => ({ |
1235 | 1228 | cronTrigger: r.cronTrigger, |
1236 | 1229 | workflow: r.workflow, |
1237 | 1230 | deployment: |
|
0 commit comments