Skip to content

Commit ba5b2ab

Browse files
committed
remove unused envvar, remove extraneous comments
1 parent 37f1276 commit ba5b2ab

File tree

10 files changed

+60
-76
lines changed

10 files changed

+60
-76
lines changed

apps/sim/app/api/cron/cleanup-stale-executions/route.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createLogger } from '@sim/logger'
44
import { and, eq, inArray, lt, sql } from 'drizzle-orm'
55
import { type NextRequest, NextResponse } from 'next/server'
66
import { verifyCronAuth } from '@/lib/auth/internal'
7-
import { JOB_RETENTION_HOURS } from '@/lib/core/async-jobs'
7+
import { JOB_RETENTION_HOURS, JOB_STATUS } from '@/lib/core/async-jobs'
88
import { getMaxExecutionTimeout } from '@/lib/core/execution-limits'
99

1010
const logger = createLogger('CleanupStaleExecutions')
@@ -88,12 +88,14 @@ export async function GET(request: NextRequest) {
8888
const staleAsyncJobs = await db
8989
.update(asyncJobs)
9090
.set({
91-
status: 'failed',
91+
status: JOB_STATUS.FAILED,
9292
completedAt: new Date(),
9393
error: `Job terminated: stuck in processing for more than ${STALE_THRESHOLD_MINUTES} minutes`,
9494
updatedAt: new Date(),
9595
})
96-
.where(and(eq(asyncJobs.status, 'processing'), lt(asyncJobs.startedAt, staleThreshold)))
96+
.where(
97+
and(eq(asyncJobs.status, JOB_STATUS.PROCESSING), lt(asyncJobs.startedAt, staleThreshold))
98+
)
9799
.returning({ id: asyncJobs.id })
98100

99101
asyncJobsMarkedFailed = staleAsyncJobs.length
@@ -115,7 +117,7 @@ export async function GET(request: NextRequest) {
115117
.delete(asyncJobs)
116118
.where(
117119
and(
118-
inArray(asyncJobs.status, ['completed', 'failed']),
120+
inArray(asyncJobs.status, [JOB_STATUS.COMPLETED, JOB_STATUS.FAILED]),
119121
lt(asyncJobs.completedAt, retentionThreshold)
120122
)
121123
)

apps/sim/app/api/jobs/[jobId]/route.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { createLogger } from '@sim/logger'
22
import { type NextRequest, NextResponse } from 'next/server'
33
import { checkHybridAuth } from '@/lib/auth/hybrid'
4-
import { getJobQueue } from '@/lib/core/async-jobs'
4+
import { getJobQueue, JOB_STATUS } from '@/lib/core/async-jobs'
55
import { generateRequestId } from '@/lib/core/utils/request'
66
import { createErrorResponse } from '@/app/api/workflows/utils'
77

@@ -48,7 +48,7 @@ export async function GET(
4848
return createErrorResponse('Access denied', 403)
4949
}
5050

51-
const mappedStatus = job.status === 'pending' ? 'queued' : job.status
51+
const mappedStatus = job.status === JOB_STATUS.PENDING ? 'queued' : job.status
5252

5353
const response: any = {
5454
success: true,
@@ -59,23 +59,23 @@ export async function GET(
5959
},
6060
}
6161

62-
if (job.status === 'completed') {
62+
if (job.status === JOB_STATUS.COMPLETED) {
6363
response.output = job.output
6464
response.metadata.completedAt = job.completedAt
6565
if (job.startedAt && job.completedAt) {
6666
response.metadata.duration = job.completedAt.getTime() - job.startedAt.getTime()
6767
}
6868
}
6969

70-
if (job.status === 'failed') {
70+
if (job.status === JOB_STATUS.FAILED) {
7171
response.error = job.error
7272
response.metadata.completedAt = job.completedAt
7373
if (job.startedAt && job.completedAt) {
7474
response.metadata.duration = job.completedAt.getTime() - job.startedAt.getTime()
7575
}
7676
}
7777

78-
if (job.status === 'processing' || job.status === 'pending') {
78+
if (job.status === JOB_STATUS.PROCESSING || job.status === JOB_STATUS.PENDING) {
7979
response.estimatedDuration = 180000
8080
}
8181

apps/sim/lib/core/async-jobs/backends/database.ts

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
import { asyncJobs, db } from '@sim/db'
22
import { createLogger } from '@sim/logger'
33
import { eq } from 'drizzle-orm'
4-
import type {
5-
EnqueueOptions,
6-
Job,
7-
JobMetadata,
8-
JobQueueBackend,
9-
JobStatus,
10-
JobType,
4+
import {
5+
type EnqueueOptions,
6+
JOB_STATUS,
7+
type Job,
8+
type JobMetadata,
9+
type JobQueueBackend,
10+
type JobStatus,
11+
type JobType,
1112
} from '@/lib/core/async-jobs/types'
1213

1314
const logger = createLogger('DatabaseJobQueue')
@@ -44,7 +45,7 @@ export class DatabaseJobQueue implements JobQueueBackend {
4445
id: jobId,
4546
type,
4647
payload: payload as Record<string, unknown>,
47-
status: 'pending',
48+
status: JOB_STATUS.PENDING,
4849
createdAt: now,
4950
attempts: 0,
5051
maxAttempts: options?.maxAttempts ?? 3,
@@ -68,7 +69,7 @@ export class DatabaseJobQueue implements JobQueueBackend {
6869
await db
6970
.update(asyncJobs)
7071
.set({
71-
status: 'processing',
72+
status: JOB_STATUS.PROCESSING,
7273
startedAt: now,
7374
attempts: 1,
7475
updatedAt: now,
@@ -84,7 +85,7 @@ export class DatabaseJobQueue implements JobQueueBackend {
8485
await db
8586
.update(asyncJobs)
8687
.set({
87-
status: 'completed',
88+
status: JOB_STATUS.COMPLETED,
8889
completedAt: now,
8990
output: output as Record<string, unknown>,
9091
updatedAt: now,
@@ -100,7 +101,7 @@ export class DatabaseJobQueue implements JobQueueBackend {
100101
await db
101102
.update(asyncJobs)
102103
.set({
103-
status: 'failed',
104+
status: JOB_STATUS.FAILED,
104105
completedAt: now,
105106
error,
106107
updatedAt: now,

apps/sim/lib/core/async-jobs/backends/redis.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
66

77
vi.mock('@sim/logger', () => loggerMock)
88

9-
import { JOB_RETENTION_SECONDS } from '@/lib/core/async-jobs/types'
9+
import { JOB_RETENTION_SECONDS, JOB_STATUS } from '@/lib/core/async-jobs/types'
1010
import { RedisJobQueue } from './redis'
1111

1212
describe('RedisJobQueue', () => {
@@ -31,7 +31,7 @@ describe('RedisJobQueue', () => {
3131

3232
const [key, data] = localRedis.hset.mock.calls[0]
3333
expect(key).toBe(`async-jobs:job:${jobId}`)
34-
expect(data.status).toBe('pending')
34+
expect(data.status).toBe(JOB_STATUS.PENDING)
3535
expect(data.type).toBe('workflow-execution')
3636
})
3737

@@ -54,7 +54,7 @@ describe('RedisJobQueue', () => {
5454
await localQueue.completeJob(jobId, { result: 'success' })
5555

5656
expect(localRedis.hset).toHaveBeenCalledWith(`async-jobs:job:${jobId}`, {
57-
status: 'completed',
57+
status: JOB_STATUS.COMPLETED,
5858
completedAt: expect.any(String),
5959
output: JSON.stringify({ result: 'success' }),
6060
updatedAt: expect.any(String),
@@ -85,7 +85,7 @@ describe('RedisJobQueue', () => {
8585
await localQueue.markJobFailed(jobId, error)
8686

8787
expect(localRedis.hset).toHaveBeenCalledWith(`async-jobs:job:${jobId}`, {
88-
status: 'failed',
88+
status: JOB_STATUS.FAILED,
8989
completedAt: expect.any(String),
9090
error,
9191
updatedAt: expect.any(String),
@@ -137,7 +137,7 @@ describe('RedisJobQueue', () => {
137137
id: 'run_test',
138138
type: 'workflow-execution',
139139
payload: JSON.stringify({ foo: 'bar' }),
140-
status: 'completed',
140+
status: JOB_STATUS.COMPLETED,
141141
createdAt: now.toISOString(),
142142
startedAt: now.toISOString(),
143143
completedAt: now.toISOString(),
@@ -154,7 +154,7 @@ describe('RedisJobQueue', () => {
154154
expect(job?.id).toBe('run_test')
155155
expect(job?.type).toBe('workflow-execution')
156156
expect(job?.payload).toEqual({ foo: 'bar' })
157-
expect(job?.status).toBe('completed')
157+
expect(job?.status).toBe(JOB_STATUS.COMPLETED)
158158
expect(job?.output).toEqual({ result: 'ok' })
159159
expect(job?.metadata.workflowId).toBe('wf_123')
160160
})

apps/sim/lib/core/async-jobs/backends/redis.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type Redis from 'ioredis'
33
import {
44
type EnqueueOptions,
55
JOB_RETENTION_SECONDS,
6+
JOB_STATUS,
67
type Job,
78
type JobMetadata,
89
type JobQueueBackend,
@@ -77,7 +78,7 @@ export class RedisJobQueue implements JobQueueBackend {
7778
id: jobId,
7879
type,
7980
payload,
80-
status: 'pending',
81+
status: JOB_STATUS.PENDING,
8182
createdAt: now,
8283
attempts: 0,
8384
maxAttempts: options?.maxAttempts ?? 3,
@@ -100,7 +101,7 @@ export class RedisJobQueue implements JobQueueBackend {
100101
const now = new Date()
101102

102103
await this.redis.hset(KEYS.job(jobId), {
103-
status: 'processing',
104+
status: JOB_STATUS.PROCESSING,
104105
startedAt: now.toISOString(),
105106
attempts: '1',
106107
updatedAt: now.toISOString(),
@@ -114,7 +115,7 @@ export class RedisJobQueue implements JobQueueBackend {
114115
const key = KEYS.job(jobId)
115116

116117
await this.redis.hset(key, {
117-
status: 'completed',
118+
status: JOB_STATUS.COMPLETED,
118119
completedAt: now.toISOString(),
119120
output: JSON.stringify(output),
120121
updatedAt: now.toISOString(),
@@ -129,7 +130,7 @@ export class RedisJobQueue implements JobQueueBackend {
129130
const key = KEYS.job(jobId)
130131

131132
await this.redis.hset(key, {
132-
status: 'failed',
133+
status: JOB_STATUS.FAILED,
133134
completedAt: now.toISOString(),
134135
error,
135136
updatedAt: now.toISOString(),

apps/sim/lib/core/async-jobs/backends/trigger-dev.ts

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import { createLogger } from '@sim/logger'
22
import { runs, tasks } from '@trigger.dev/sdk'
3-
import type {
4-
EnqueueOptions,
5-
Job,
6-
JobMetadata,
7-
JobQueueBackend,
8-
JobStatus,
9-
JobType,
3+
import {
4+
type EnqueueOptions,
5+
JOB_STATUS,
6+
type Job,
7+
type JobMetadata,
8+
type JobQueueBackend,
9+
type JobStatus,
10+
type JobType,
1011
} from '@/lib/core/async-jobs/types'
1112

1213
const logger = createLogger('TriggerDevJobQueue')
@@ -27,22 +28,22 @@ function mapTriggerDevStatus(status: string): JobStatus {
2728
switch (status) {
2829
case 'QUEUED':
2930
case 'WAITING_FOR_DEPLOY':
30-
return 'pending'
31+
return JOB_STATUS.PENDING
3132
case 'EXECUTING':
3233
case 'RESCHEDULED':
3334
case 'FROZEN':
34-
return 'processing'
35+
return JOB_STATUS.PROCESSING
3536
case 'COMPLETED':
36-
return 'completed'
37+
return JOB_STATUS.COMPLETED
3738
case 'CANCELED':
3839
case 'FAILED':
3940
case 'CRASHED':
4041
case 'INTERRUPTED':
4142
case 'SYSTEM_FAILURE':
4243
case 'EXPIRED':
43-
return 'failed'
44+
return JOB_STATUS.FAILED
4445
default:
45-
return 'pending'
46+
return JOB_STATUS.PENDING
4647
}
4748
}
4849

@@ -61,9 +62,6 @@ export class TriggerDevJobQueue implements JobQueueBackend {
6162
throw new Error(`Unknown job type: ${type}`)
6263
}
6364

64-
// Merge metadata into payload so it's available when retrieving job status.
65-
// This ensures access control checks work correctly since getJob() extracts
66-
// workflowId and userId from the payload.
6765
const enrichedPayload =
6866
options?.metadata && typeof payload === 'object' && payload !== null
6967
? { ...payload, ...options.metadata }
@@ -94,7 +92,7 @@ export class TriggerDevJobQueue implements JobQueueBackend {
9492
startedAt: run.startedAt ? new Date(run.startedAt) : undefined,
9593
completedAt: run.finishedAt ? new Date(run.finishedAt) : undefined,
9694
attempts: run.attemptCount ?? 1,
97-
maxAttempts: 3, // trigger.dev doesn't expose maxAttempts, use default
95+
maxAttempts: 3,
9896
error: run.error?.message,
9997
output: run.output as unknown,
10098
metadata,
@@ -105,24 +103,9 @@ export class TriggerDevJobQueue implements JobQueueBackend {
105103
}
106104
}
107105

108-
/**
109-
* No-op for trigger.dev - job start is handled by the task runner
110-
*/
111-
async startJob(_jobId: string): Promise<void> {
112-
// No-op: trigger.dev handles job start internally
113-
}
106+
async startJob(_jobId: string): Promise<void> {}
114107

115-
/**
116-
* No-op for trigger.dev - completion is handled by the task runner
117-
*/
118-
async completeJob(_jobId: string, _output: unknown): Promise<void> {
119-
// No-op: trigger.dev handles completion internally
120-
}
108+
async completeJob(_jobId: string, _output: unknown): Promise<void> {}
121109

122-
/**
123-
* No-op for trigger.dev - failure is handled by the task runner
124-
*/
125-
async markJobFailed(_jobId: string, _error: string): Promise<void> {
126-
// No-op: trigger.dev handles failures internally
127-
}
110+
async markJobFailed(_jobId: string, _error: string): Promise<void> {}
128111
}

apps/sim/lib/core/async-jobs/config.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,25 +11,17 @@ let cachedBackendType: AsyncBackendType | null = null
1111
/**
1212
* Determines which async backend to use based on environment configuration.
1313
* Follows the fallback chain: trigger.dev → redis → database
14-
*
15-
* This mirrors the pattern used by:
16-
* - Socket.IO rooms (RedisRoomManager → MemoryRoomManager)
17-
* - Document processing queue (Redis → in-memory)
18-
* - Rate limiting (Redis → database)
1914
*/
2015
export function getAsyncBackendType(): AsyncBackendType {
21-
// Check trigger.dev first
2216
if (isTriggerDevEnabled) {
2317
return 'trigger-dev'
2418
}
2519

26-
// Check Redis availability
2720
const redis = getRedisClient()
2821
if (redis) {
2922
return 'redis'
3023
}
3124

32-
// Fall back to database
3325
return 'database'
3426
}
3527

apps/sim/lib/core/async-jobs/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ export type {
1414
JobStatus,
1515
JobType,
1616
} from './types'
17-
export { JOB_RETENTION_HOURS, JOB_RETENTION_SECONDS } from './types'
17+
export { JOB_RETENTION_HOURS, JOB_RETENTION_SECONDS, JOB_STATUS } from './types'

apps/sim/lib/core/async-jobs/types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,14 @@ export const JOB_RETENTION_HOURS = 24
88
/** Retention period for completed/failed jobs (in seconds, for Redis TTL) */
99
export const JOB_RETENTION_SECONDS = JOB_RETENTION_HOURS * 60 * 60
1010

11-
export type JobStatus = 'pending' | 'processing' | 'completed' | 'failed'
11+
export const JOB_STATUS = {
12+
PENDING: 'pending',
13+
PROCESSING: 'processing',
14+
COMPLETED: 'completed',
15+
FAILED: 'failed',
16+
} as const
17+
18+
export type JobStatus = (typeof JOB_STATUS)[keyof typeof JOB_STATUS]
1219

1320
export type JobType = 'workflow-execution' | 'schedule-execution' | 'webhook-execution'
1421

apps/sim/lib/core/config/env.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,6 @@ export const env = createEnv({
345345
NEXT_PUBLIC_BRAND_BACKGROUND_COLOR: z.string().regex(/^#[0-9A-Fa-f]{6}$/).optional(), // Brand background color (hex format)
346346

347347
// Feature Flags
348-
NEXT_PUBLIC_TRIGGER_DEV_ENABLED: z.boolean().optional(), // Client-side gate for async executions UI
349348
NEXT_PUBLIC_SSO_ENABLED: z.boolean().optional(), // Enable SSO login UI components
350349
NEXT_PUBLIC_CREDENTIAL_SETS_ENABLED: z.boolean().optional(), // Enable credential sets (email polling) on self-hosted
351350
NEXT_PUBLIC_ACCESS_CONTROL_ENABLED: z.boolean().optional(), // Enable access control (permission groups) on self-hosted
@@ -377,7 +376,6 @@ export const env = createEnv({
377376
NEXT_PUBLIC_BRAND_ACCENT_COLOR: process.env.NEXT_PUBLIC_BRAND_ACCENT_COLOR,
378377
NEXT_PUBLIC_BRAND_ACCENT_HOVER_COLOR: process.env.NEXT_PUBLIC_BRAND_ACCENT_HOVER_COLOR,
379378
NEXT_PUBLIC_BRAND_BACKGROUND_COLOR: process.env.NEXT_PUBLIC_BRAND_BACKGROUND_COLOR,
380-
NEXT_PUBLIC_TRIGGER_DEV_ENABLED: process.env.NEXT_PUBLIC_TRIGGER_DEV_ENABLED,
381379
NEXT_PUBLIC_SSO_ENABLED: process.env.NEXT_PUBLIC_SSO_ENABLED,
382380
NEXT_PUBLIC_CREDENTIAL_SETS_ENABLED: process.env.NEXT_PUBLIC_CREDENTIAL_SETS_ENABLED,
383381
NEXT_PUBLIC_ACCESS_CONTROL_ENABLED: process.env.NEXT_PUBLIC_ACCESS_CONTROL_ENABLED,

0 commit comments

Comments
 (0)