fastify-ximagepipeline
getStatus
Fetch a MediaQueue job record with its media relation from the database.
getStatus
Programmatic counterpart to the GET /image-pipeline/status/:jobId HTTP endpoint. Queries the MediaQueue record directly via Prisma and includes the associated Media row when the job is COMPLETE.
Signature
fastify.xImagePipeline.getStatus(jobId: string): Promise<MediaQueueRecord | null>
interface MediaQueueRecord {
id: string
status: "PENDING" | "PROCESSING" | "COMPLETE" | "REJECTED" | "FAILED"
sourceType: string
sourceId: string
attempts: number
error: string | null
media: MediaRecord | null // populated when status === "COMPLETE"
createdAt: Date
updatedAt: Date
}
Params
| Name | Type | Required | Description |
|---|---|---|---|
jobId | string | Yes | Job ID returned by the upload endpoint |
Returns
The MediaQueue record with the media relation included, or null if no job with that ID exists.
Throws
Does not throw for missing jobs — returns null. Throws on database errors.
Examples
Check job status in a Fastify route
fastify.get("/jobs/:id", async (request, reply) => {
const job = await fastify.xImagePipeline.getStatus(request.params.id);
if (!job) {
return reply.code(404).send({ error: "Job not found" });
}
if (job.status === "COMPLETE") {
return { status: job.status, urls: job.media.urls, blurhash: job.media.blurhash };
}
return { status: job.status };
});
Background task — process completed jobs
async function syncCompletedJobs(userIds) {
const updates = await Promise.all(
userIds.map(async (userId) => {
const pendingJob = await prisma.mediaQueue.findFirst({
where: { sourceId: userId, sourceType: "avatar", status: { not: "COMPLETE" } },
});
if (!pendingJob) return null;
const job = await fastify.xImagePipeline.getStatus(pendingJob.id);
if (job?.status === "COMPLETE") {
return prisma.user.update({
where: { id: userId },
data: { avatarUrl: job.media.urls.sm },
});
}
return null;
})
);
return updates.filter(Boolean).length;
}
See Also
- GET /image-pipeline/status/:jobId — HTTP equivalent
- listMedia(sourceType, sourceId) — List all completed media for a source
AI Context
package: "@xenterprises/fastify-ximagepipeline"
method: fastify.xImagePipeline.getStatus(jobId)
use-when: Programmatically fetch a MediaQueue job record with its media relation — same data as the HTTP status route
returns: MediaQueue record with media relation | null
