Skip to content

Commit 509369d

Browse files
committed
consolidate
1 parent 121e93e commit 509369d

File tree

10 files changed

+53
-122
lines changed

10 files changed

+53
-122
lines changed

apps/sim/app/api/workflows/[id]/execute/cancel/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { type NextRequest, NextResponse } from 'next/server'
22
import { z } from 'zod'
33
import { checkHybridAuth } from '@/lib/auth/hybrid'
4-
import { requestCancellation } from '@/lib/execution/active-executors'
4+
import { requestCancellation } from '@/lib/execution/cancellation'
55

66
const CancelExecutionSchema = z.object({
77
executionId: z.string().uuid(),

apps/sim/app/api/workflows/[id]/execute/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { isTriggerDevEnabled } from '@/lib/core/config/feature-flags'
77
import { generateRequestId } from '@/lib/core/utils/request'
88
import { SSE_HEADERS } from '@/lib/core/utils/sse'
99
import { getBaseUrl } from '@/lib/core/utils/urls'
10-
import { clearCancellation } from '@/lib/execution/active-executors'
10+
import { clearCancellation } from '@/lib/execution/cancellation'
1111
import { processInputFileFields } from '@/lib/execution/files'
1212
import { preprocessExecution } from '@/lib/execution/preprocessing'
1313
import { createLogger } from '@/lib/logs/console/logger'

apps/sim/executor/execution/engine.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isCancellationRequested } from '@/lib/execution/active-executors'
1+
import { isCancellationRequested } from '@/lib/execution/cancellation'
22
import { createLogger } from '@/lib/logs/console/logger'
33
import { BlockType } from '@/executor/constants'
44
import type { DAG } from '@/executor/dag/builder'

apps/sim/lib/execution/active-executors.ts

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { getRedisClient } from '@/lib/core/config/redis'
2+
3+
const KEY_PREFIX = 'execution:cancel:'
4+
const TTL_SECONDS = 300
5+
const TTL_MS = TTL_SECONDS * 1000
6+
7+
const memoryStore = new Map<string, number>()
8+
9+
export async function requestCancellation(executionId: string): Promise<boolean> {
10+
const redis = getRedisClient()
11+
if (redis) {
12+
try {
13+
await redis.set(`${KEY_PREFIX}${executionId}`, '1', 'EX', TTL_SECONDS)
14+
return true
15+
} catch {
16+
return false
17+
}
18+
}
19+
memoryStore.set(executionId, Date.now() + TTL_MS)
20+
return true
21+
}
22+
23+
export async function isCancellationRequested(executionId: string): Promise<boolean> {
24+
const redis = getRedisClient()
25+
if (redis) {
26+
try {
27+
return (await redis.exists(`${KEY_PREFIX}${executionId}`)) === 1
28+
} catch {
29+
return false
30+
}
31+
}
32+
const expiry = memoryStore.get(executionId)
33+
if (!expiry) return false
34+
if (Date.now() > expiry) {
35+
memoryStore.delete(executionId)
36+
return false
37+
}
38+
return true
39+
}
40+
41+
export async function clearCancellation(executionId: string): Promise<void> {
42+
const redis = getRedisClient()
43+
if (redis) {
44+
try {
45+
await redis.del(`${KEY_PREFIX}${executionId}`)
46+
} catch {}
47+
return
48+
}
49+
memoryStore.delete(executionId)
50+
}

apps/sim/lib/execution/storage/adapter.ts

Lines changed: 0 additions & 6 deletions
This file was deleted.

apps/sim/lib/execution/storage/factory.ts

Lines changed: 0 additions & 27 deletions
This file was deleted.

apps/sim/lib/execution/storage/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

apps/sim/lib/execution/storage/memory-store.ts

Lines changed: 0 additions & 30 deletions
This file was deleted.

apps/sim/lib/execution/storage/redis-store.ts

Lines changed: 0 additions & 39 deletions
This file was deleted.

0 commit comments

Comments
 (0)