graphiti-api/spraypaint.js

Support for batch processing on response with status 202?

Closed this issue · 7 comments

Hi, I'm looking to follow this JSON:API recommendation for batch processing:

https://jsonapi.org/recommendations/#asynchronous-processing

My use case is that I have a delete that is super slow (many minutes). I would like to put that into the background job, then return the job details in the 202 response like that document says.

I look into our source code and see this

async destroy(): Promise<boolean> {

That means it will ignore the response with status 202.

I realize that there is a difficulty with implementing this feature: the model returned by the response is usually completely different from the model that is deleted. I'm not sure how to look up the appropriate model based on the type in the response.

Upon closer look. I find that you guys already did a registry for all available type:

expect(BaseModel.typeRegistry.get("posts")).to.equal(Post)

So I can just based on that and try to use it on the response.

My question is: are you guys welcome to my attempt to implement this JSON:API recommendation?

Hey @mqchau!

I would love to get this in myself - not just allowing a 202, but polling against the job automatically and performing an action when it's done. Is this something you'd like to submit a PR for?

I think the responsibility of spraypaint.js stops at deserializing the
response payload and return the object in the payload. Then the application
code can do whatever it wants.

I agree that this is the minimum responsibility, and devs should be able to do this and nothing else. But there's an optional/additional responsibility of calling a hook (like onDeferredCreate). That way we can implement a default hook (or opt-in to this behavior) of polling against a response URL.

Can I just implement the minimum responsibility approach for now?

Yes, I think that's fine

And much appreciated ❤️ 🙂