45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { NextRequest, NextResponse } from 'next/server';
|
|
import { syncQueue } from '@/lib/queue/syncQueue';
|
|
import { getUserAuth } from '@/lib/auth/utils';
|
|
|
|
export async function GET(
|
|
request: NextRequest,
|
|
{ params }: { params: { jobId: string } }
|
|
) {
|
|
try {
|
|
const { session } = await getUserAuth();
|
|
|
|
if (!session?.user) {
|
|
return NextResponse.json({ error: 'Unauthorized' }, { status: 401 });
|
|
}
|
|
|
|
const jobId = params.jobId;
|
|
const job = await syncQueue.getJob(jobId);
|
|
|
|
if (!job) {
|
|
return NextResponse.json({ error: 'Job not found' }, { status: 404 });
|
|
}
|
|
|
|
const state = await job.getState();
|
|
const progress = job.progress;
|
|
const returnvalue = job.returnvalue;
|
|
const failedReason = job.failedReason;
|
|
|
|
return NextResponse.json({
|
|
jobId: job.id,
|
|
state,
|
|
progress,
|
|
result: returnvalue,
|
|
error: failedReason,
|
|
processedOn: job.processedOn,
|
|
finishedOn: job.finishedOn,
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to get job status:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to retrieve job status' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|