feat: add RetryFailedButton component and API endpoint for retrying failed queue jobs
Build Images and Deploy / Update-PROD-Stack (push) Successful in 1m19s

This commit is contained in:
2026-03-18 19:17:06 -04:00
parent 98f08ece11
commit 45d3c62cae
3 changed files with 83 additions and 0 deletions
+2
View File
@@ -1,5 +1,6 @@
import { priceUpdateQueue, maintenanceQueue, schedulerQueue } from '@/lib/queue'
import { formatDistanceToNow } from 'date-fns'
import RetryFailedButton from '@/components/admin/RetryFailedButton'
export const dynamic = 'force-dynamic'
@@ -89,6 +90,7 @@ export default async function AdminQueuePage() {
<div className="flex items-center justify-between px-4 py-3 border-b border-surface-border">
<h3 className="font-medium text-sm">{q.name}</h3>
<div className="flex items-center gap-3 text-xs">
<RetryFailedButton queueName={q.name} count={q.failed} />
<Badge label="waiting" count={q.waiting} color="slate" />
<Badge label="active" count={q.active} color="indigo" />
<Badge label="delayed" count={q.delayed} color="amber" />
+40
View File
@@ -0,0 +1,40 @@
import { NextRequest, NextResponse } from 'next/server'
import { getServerSession } from 'next-auth'
import { authOptions } from '@/lib/auth'
import { priceUpdateQueue, maintenanceQueue, schedulerQueue } from '@/lib/queue'
import { Queue } from 'bullmq'
const QUEUES: Record<string, Queue> = {
'hashex-price-updates': priceUpdateQueue,
'hashex-maintenance': maintenanceQueue,
'hashex-scheduler': schedulerQueue,
}
export async function POST(
req: NextRequest,
{ params }: { params: { name: string } }
) {
const session = await getServerSession(authOptions)
if (!session?.user?.isAdmin) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 })
}
const queue = QUEUES[params.name]
if (!queue) {
return NextResponse.json({ error: 'Queue not found' }, { status: 404 })
}
const { action } = await req.json() as { action: string }
if (action === 'retry-failed') {
await queue.retryJobs({ count: 100, state: 'failed' })
return NextResponse.json({ ok: true })
}
if (action === 'clean-failed') {
await queue.clean(0, 100, 'failed')
return NextResponse.json({ ok: true })
}
return NextResponse.json({ error: 'Unknown action' }, { status: 400 })
}
@@ -0,0 +1,41 @@
'use client'
import { useState } from 'react'
import { useRouter } from 'next/navigation'
export default function RetryFailedButton({
queueName,
count,
}: {
queueName: string
count: number
}) {
const [loading, setLoading] = useState(false)
const router = useRouter()
if (count === 0) return null
async function handleRetry() {
setLoading(true)
try {
await fetch(`/api/admin/queues/${encodeURIComponent(queueName)}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ action: 'retry-failed' }),
})
} finally {
router.refresh()
setLoading(false)
}
}
return (
<button
onClick={handleRetry}
disabled={loading}
className="text-xs px-2 py-1 rounded bg-red-500/20 text-red-400 hover:bg-red-500/30 disabled:opacity-50 transition-colors"
>
{loading ? 'Retrying…' : `Retry ${count} failed`}
</button>
)
}