DEV Community

Cover image for Scheduling Workflows: POST, Poll, and Callback – Picking the Right One. Part 2.
Datapult
Datapult

Posted on

Scheduling Workflows: POST, Poll, and Callback – Picking the Right One. Part 2.

You have shifts, you have users, and you have rules that need strict adherence. How do you get from here to a schedule? Let’s dive into the two main options: posting data and waiting for a callback or posting and then polling. Both have strengths, depending on your application.

Callback

Callback are great for web-facing, low-latency environments, where users can afford to sit back and wait for the schedule to be ready.

Here is how to make Datapult call back to you once your schedule is ready: Simply add these to the payload:

{
  "callbackUrl": "https://www.yourdomain.app/custom_callback_url",
  "callbackAuthenticationHeaderName": "AnyHeaderYouWant",
  "callbackAuthenticationHeaderValue": "AnySecretYouWant"
}
Enter fullscreen mode Exit fullscreen mode

We will callback 3 times with exponential backoff and in case every callback yields a 5xx from you, we will send you an email with the error message that your server gave us. How helpful is that?

Polling

Maybe you are testing locally; maybe you cannot expose a route for us - for whatever reason callbacks are not possible - you can poll our servers for a solution. Here is how:

  1. Set the fields above to null or a dummy domain.
  2. POST your payload.
  3. The post message will return an integer id.
  4. Use this ID to GET /api/schedule/{id}. If you get a 204 No Content the payload is not ready. It will never take more than 10 minutes.
  5. Repeat step 4 until you get a 200.

Conclusion

While callbacks can reduce load your setup might not allow for it. Be using polling and done right, you can ensure a smooth UX to show progress. Both flows are supported and it’s up to you to configure according to your need.

Top comments (0)