pcace
pcace

Reputation: 670

progress in a long running API? (Nodejs & express)

I have made an API which generates 3d Models. Sometimes this can take a long time (>5 min). When it succeeds it returns the 3d Model in text form with statuscode 200. When failing I return the errorcode with statuscode 400.

Is there any way / mechanism to return a progress of processes? how could I do this? and how would Browsers read this?

Cheers and thanks!

Upvotes: 0

Views: 375

Answers (1)

Drom Hour
Drom Hour

Reputation: 94

You can use next logic for this:

  1. Client doing request /generateModel to generate model;
  2. Server returns operation_id;
  3. Now client can do request /getStatus with gained operation_id;
  4. Server will answer about progress and result: { status: 0, progress: 0.02 }. Possible statuses:
  • 0 - still generating with progress (0.00-0.99)({ status: 0, progress: 0.02 });
  • 200 - done ({ status: 1 });
  • other numbers - error ({ status: 500, message: "Internal error" });
  1. Client asks server about status with some interval;
  2. When client get response with done status, client requests model /getModel;
  3. If client get response with error status, it will be displayed.

Upvotes: 1

Related Questions