Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Polling for Image Generation Status Using Request IDs #33

Open
skushagra9 opened this issue Feb 23, 2025 · 3 comments
Open

Implement Polling for Image Generation Status Using Request IDs #33

skushagra9 opened this issue Feb 23, 2025 · 3 comments
Assignees

Comments

@skushagra9
Copy link

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
}
@skushagra9
Copy link
Author

skushagra9 commented Feb 23, 2025

If anyone is interested to pick this up , I can provide help
I have already implemented it in my project
@hkirat @yashmakhija

@hkirat
Copy link
Contributor

hkirat commented Feb 24, 2025

yeah this is good

@skushagra9
Copy link
Author

yeah this is good

Thanks @hkirat
I have done it exactly what I have shown in the description, and works fine
I can help if anyone interested to solve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants