chiefonboarding / ChiefOnboarding

Free and open-source employee onboarding platform. Onboard new hires through Slack or the web portal.
https://chiefonboarding.com
GNU Affero General Public License v3.0
656 stars 121 forks source link

Polling requests in integration #358

Closed GDay closed 11 months ago

GDay commented 11 months ago

This will allow an integration to be set up to wait for a specific thing to change (or a background task to be finished).

Usecase: Say we are triggering a bulk call from a third party API. We need to wait until it's done before we can continue with the next steps in the integration. In this case, it makes sense to check a different endpoint for the status of that bulk operation. When we get back what we expected (meaning the operation has finished), we can move on.

Questions:

This is code that I wrote off the top of my head, no testing has been done, so don't worry about the details just yet.

coveralls commented 11 months ago

Coverage Status

coverage: 93.396% (-0.09%) from 93.488% when pulling 1d85ba6dd729f4bf531888ae436c6b7d750d63d0 on polling-request-integration into c2461231b2b4a8c8ecd75eeec7065afc1eed5a58 on master.

cscheng commented 11 months ago

In general, adding an optional polling object to the execute/request object is the right approach. I'm not sure whether you ever need to have other conditions than an exact match for a value in the response. At least in the case of the PandaDoc API you only need to verify the document status before continuing, so you don't need other conditions which allows you to avoid usage of eval.

GDay commented 11 months ago

@cscheng I have removed the eval and just assumed that it needs to be equal. I wanted to make this a bit more universal, but for now, this is fine. I can still extend it if necessary later on.

Feel free to review.

GDay commented 11 months ago

@cscheng All good comments. Thanks!