chore: import upstream snapshot with attribution
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
CI / Migrate Dev DB (push) Has been skipped
CI / Detect Version (push) Has been cancelled
CI / Migrate DB (push) Has been cancelled
CI / Build Dev ECR (./docker/app.Dockerfile, ECR_APP) (push) Has been cancelled
CI / Build Dev ECR (./docker/db.Dockerfile, ECR_MIGRATIONS) (push) Has been cancelled
CI / Build Dev ECR (./docker/pii.Dockerfile, ECR_PII) (push) Has been cancelled
CI / Build Dev ECR (./docker/realtime.Dockerfile, ECR_REALTIME) (push) Has been cancelled
CI / Deploy Trigger.dev (Dev) (push) Has been cancelled
CI / Build AMD64 (./docker/app.Dockerfile, ECR_APP, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build AMD64 (./docker/db.Dockerfile, ECR_MIGRATIONS, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build AMD64 (./docker/pii.Dockerfile, ECR_PII, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build AMD64 (./docker/realtime.Dockerfile, ECR_REALTIME, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/app.Dockerfile, ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/db.Dockerfile, ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/pii.Dockerfile, ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Build ARM64 (GHCR Only) (./docker/realtime.Dockerfile, ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/migrations) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/pii) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/realtime) (push) Has been cancelled
CI / Create GHCR Manifests (ghcr.io/simstudioai/simstudio) (push) Has been cancelled
CI / Check Docs Changes (push) Has been cancelled
CI / Process Docs (push) Has been cancelled
CI / Create GitHub Release (push) Has been cancelled
CI / Test and Build (push) Has been cancelled
Publish CLI Package / publish-npm (push) Has been cancelled
Publish Python SDK / publish-pypi (push) Has been cancelled
Publish TypeScript SDK / publish-npm (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
import { db } from '@sim/db'
|
||||
import { outboxEvent } from '@sim/db/schema'
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { toError } from '@sim/utils/errors'
|
||||
import { and, eq } from 'drizzle-orm'
|
||||
import { NextResponse } from 'next/server'
|
||||
import { adminV1RequeueOutboxEventContract } from '@/lib/api/contracts/v1/admin'
|
||||
import { getValidationErrorMessage, parseRequest } from '@/lib/api/server'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { withAdminAuthParams } from '@/app/api/v1/admin/middleware'
|
||||
|
||||
const logger = createLogger('AdminOutboxRequeueAPI')
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const invalidOutboxEventResponse = (message: string) =>
|
||||
NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
|
||||
/**
|
||||
* POST /api/v1/admin/outbox/[id]/requeue
|
||||
*
|
||||
* Move a dead-lettered outbox event back to `pending` so the worker
|
||||
* will retry it. Resets `attempts`, `lastError`, and `availableAt` so
|
||||
* the next poll picks it up. Only dead-lettered events can be
|
||||
* requeued — completed/pending/processing rows are rejected to avoid
|
||||
* operator errors.
|
||||
*/
|
||||
export const POST = withRouteHandler(
|
||||
withAdminAuthParams<{ id: string }>(async (request, context) => {
|
||||
const parsed = await parseRequest(adminV1RequeueOutboxEventContract, request, context, {
|
||||
validationErrorResponse: (error) =>
|
||||
invalidOutboxEventResponse(getValidationErrorMessage(error, 'Invalid event ID')),
|
||||
})
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const { id } = parsed.data.params
|
||||
|
||||
try {
|
||||
const result = await db
|
||||
.update(outboxEvent)
|
||||
.set({
|
||||
status: 'pending',
|
||||
attempts: 0,
|
||||
lastError: null,
|
||||
availableAt: new Date(),
|
||||
lockedAt: null,
|
||||
processedAt: null,
|
||||
})
|
||||
.where(and(eq(outboxEvent.id, id), eq(outboxEvent.status, 'dead_letter')))
|
||||
.returning({ id: outboxEvent.id, eventType: outboxEvent.eventType })
|
||||
|
||||
if (result.length === 0) {
|
||||
return NextResponse.json(
|
||||
{
|
||||
success: false,
|
||||
error:
|
||||
'Event not found or not in dead_letter status. Only dead-lettered events can be requeued.',
|
||||
},
|
||||
{ status: 404 }
|
||||
)
|
||||
}
|
||||
|
||||
logger.info('Requeued dead-lettered outbox event', {
|
||||
eventId: result[0].id,
|
||||
eventType: result[0].eventType,
|
||||
})
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
requeued: result[0],
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Failed to requeue outbox event', { eventId: id, error: toError(error).message })
|
||||
return NextResponse.json({ success: false, error: toError(error).message }, { status: 500 })
|
||||
}
|
||||
})
|
||||
)
|
||||
@@ -0,0 +1,83 @@
|
||||
import { db } from '@sim/db'
|
||||
import { outboxEvent } from '@sim/db/schema'
|
||||
import { createLogger } from '@sim/logger'
|
||||
import { toError } from '@sim/utils/errors'
|
||||
import { and, desc, eq, sql } from 'drizzle-orm'
|
||||
import { type NextRequest, NextResponse } from 'next/server'
|
||||
import { adminV1ListOutboxContract } from '@/lib/api/contracts/v1/admin'
|
||||
import { getValidationErrorMessage, parseRequest } from '@/lib/api/server'
|
||||
import { withRouteHandler } from '@/lib/core/utils/with-route-handler'
|
||||
import { withAdminAuth } from '@/app/api/v1/admin/middleware'
|
||||
|
||||
const logger = createLogger('AdminOutboxAPI')
|
||||
|
||||
export const dynamic = 'force-dynamic'
|
||||
|
||||
const invalidOutboxQueryResponse = (message: string) =>
|
||||
NextResponse.json({ success: false, error: message }, { status: 400 })
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/outbox?status=dead_letter&eventType=...&limit=100
|
||||
*
|
||||
* Inspect outbox events for operator triage. Primary use: list
|
||||
* dead-lettered rows to reconcile Stripe state manually after a
|
||||
* permanent handler failure (e.g. Stripe account frozen, subscription
|
||||
* already canceled by another path, etc.).
|
||||
*
|
||||
* Filters:
|
||||
* - `status`: 'pending' | 'processing' | 'completed' | 'dead_letter' (default 'dead_letter')
|
||||
* - `eventType`: exact match on event_type
|
||||
* - `limit`: cap rows returned (default 100, max 500)
|
||||
*
|
||||
* Response includes aggregate counts by status for quick health read.
|
||||
*/
|
||||
export const GET = withRouteHandler(
|
||||
withAdminAuth(async (request: NextRequest) => {
|
||||
try {
|
||||
const parsed = await parseRequest(
|
||||
adminV1ListOutboxContract,
|
||||
request,
|
||||
{},
|
||||
{
|
||||
validationErrorResponse: (error) =>
|
||||
invalidOutboxQueryResponse(getValidationErrorMessage(error, 'Invalid outbox query')),
|
||||
}
|
||||
)
|
||||
if (!parsed.success) return parsed.response
|
||||
|
||||
const { status, eventType, limit } = parsed.data.query
|
||||
|
||||
const whereConditions = [eq(outboxEvent.status, status)]
|
||||
if (eventType) {
|
||||
whereConditions.push(eq(outboxEvent.eventType, eventType))
|
||||
}
|
||||
|
||||
const rows = await db
|
||||
.select()
|
||||
.from(outboxEvent)
|
||||
.where(and(...whereConditions))
|
||||
.orderBy(desc(outboxEvent.createdAt))
|
||||
.limit(limit)
|
||||
|
||||
// Aggregate counts per (status, eventType) for at-a-glance health.
|
||||
const counts = await db
|
||||
.select({
|
||||
status: outboxEvent.status,
|
||||
eventType: outboxEvent.eventType,
|
||||
count: sql<number>`count(*)::int`,
|
||||
})
|
||||
.from(outboxEvent)
|
||||
.groupBy(outboxEvent.status, outboxEvent.eventType)
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
filter: { status, eventType, limit },
|
||||
rows,
|
||||
counts,
|
||||
})
|
||||
} catch (error) {
|
||||
logger.error('Failed to list outbox events', { error: toError(error).message })
|
||||
return NextResponse.json({ success: false, error: toError(error).message }, { status: 500 })
|
||||
}
|
||||
})
|
||||
)
|
||||
Reference in New Issue
Block a user