Skip to content

Commit 7bf9526

Browse files
committed
address more comments
1 parent 41e1c9c commit 7bf9526

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

apps/sim/background/workspace-notification-delivery.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -501,15 +501,15 @@ export type NotificationDeliveryResult =
501501
| { status: 'retry'; retryDelayMs: number }
502502

503503
async function buildRetryLog(params: NotificationDeliveryParams): Promise<WorkflowExecutionLog> {
504+
const conditions = [eq(workflowExecutionLogs.executionId, params.log.executionId)]
505+
if (params.log.workflowId) {
506+
conditions.push(eq(workflowExecutionLogs.workflowId, params.log.workflowId))
507+
}
508+
504509
const [storedLog] = await db
505510
.select()
506511
.from(workflowExecutionLogs)
507-
.where(
508-
and(
509-
eq(workflowExecutionLogs.executionId, params.log.executionId),
510-
eq(workflowExecutionLogs.workflowId, params.log.workflowId!)
511-
)
512-
)
512+
.where(and(...conditions))
513513
.limit(1)
514514

515515
if (storedLog) {

apps/sim/lib/core/workspace-dispatch/memory-store.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ export class MemoryWorkspaceDispatchStorage implements WorkspaceDispatchStorageA
1616
private workspaceOrder: string[] = []
1717
private laneQueues = new Map<string, string[]>()
1818
private leases = new Map<string, Map<string, number>>()
19-
private sequence = 0
2019
private cleanupInterval: NodeJS.Timeout | null = null
2120

2221
constructor() {
@@ -296,7 +295,20 @@ export class MemoryWorkspaceDispatchStorage implements WorkspaceDispatchStorageA
296295
}
297296

298297
async popNextWorkspaceId(): Promise<string | null> {
299-
return this.workspaceOrder.shift() ?? null
298+
const now = Date.now()
299+
const maxScans = this.workspaceOrder.length
300+
for (let i = 0; i < maxScans; i++) {
301+
const id = this.workspaceOrder.shift()
302+
if (!id) return null
303+
const readyAt = this.workspaceReadyAt.get(id)
304+
if (readyAt && readyAt > now) {
305+
this.workspaceOrder.push(id)
306+
continue
307+
}
308+
this.workspaceReadyAt.delete(id)
309+
return id
310+
}
311+
return null
300312
}
301313

302314
async getQueuedWorkspaceCount(): Promise<number> {
@@ -307,7 +319,12 @@ export class MemoryWorkspaceDispatchStorage implements WorkspaceDispatchStorageA
307319
return this.workspaceOrder.includes(workspaceId)
308320
}
309321

310-
async ensureWorkspaceActive(workspaceId: string): Promise<void> {
322+
private workspaceReadyAt = new Map<string, number>()
323+
324+
async ensureWorkspaceActive(workspaceId: string, readyAt?: number): Promise<void> {
325+
if (readyAt && readyAt > Date.now()) {
326+
this.workspaceReadyAt.set(workspaceId, readyAt)
327+
}
311328
this.ensureWorkspaceQueued(workspaceId)
312329
}
313330

@@ -473,6 +490,7 @@ export class MemoryWorkspaceDispatchStorage implements WorkspaceDispatchStorageA
473490
this.workspaceOrder = []
474491
this.laneQueues.clear()
475492
this.leases.clear()
493+
this.workspaceReadyAt.clear()
476494
}
477495

478496
dispose(): void {

0 commit comments

Comments
 (0)