Skip to content

Implement Polling for Image Generation Status Using Request IDs #33

Description

@skushagra9

Instead of polling all the images, and checking all of them if they are Generated or not, once we generate images, pass on the request_ids to the frontend, and use these request_ids to poll the backend,

Here's the backend polling endpoint :

router.get("/poll/images/:requestId", async (req, res) => {
    const requestId = req.params.requestId;
    const request = await prisma.requests.findUnique({
        where: {
            requestId: requestId
        }
    })
    if (request?.status === "completed") {
        const image = request?.imageGenerated;
        res.status(200).json({ message: "success", imageGenerated: image });
    } else {
        res.status(400).json({ message: "pending" });
    }
})

Please note for adding this change, it would require structural DB change, where we will have another Table - Requests

model Requests {
  id             String   @id @default(auto()) @map("_id") @db.ObjectId
  status         String   @default("pending") // pending, completed, failed
  requestId      String   @unique
  stripeId       String
  imageGenerated String?
  createdAt      DateTime @default(now())
  updatedAt      DateTime @updatedAt
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions