Ad

Python2.7 Response To Client First Then Process (shopify Webhook)

- 1 answer

I am building a webhook to connect Shopify with my dispatch. Shopify Webhook sends a json request and wait for 5 seconds, if it doesn't receive 200 back, it terminate the request and try another one.

My server at the moment handle this straightaway

  1. receive a shopify request
  2. sorting order data from shopify
  3. send request to dispatch server
  4. check response from the server
  5. response to shopify

with this sometimes it takes slightly longer than 5 seconds, so shopify send requests again while the server is updating the dispatch.

What's the best solution to fix this?

I am thinking two solutions

a. Response 200 back to shopify first then process dispatch (I am not sure how to do this with python2.7) b. Create a database to store shopify request, so shopify request just create an order record then it will receive 200 back (which should take less than 5 seconds). With this set up crontask or celery task to update dispatch

Any suggestions?

Ad

Answer

Better to use task queues. Use celery to do time taking tasks in background. As soon as you get the response from shopify, give your task to celery so that it can run the tasks in background, then you can send the 200 response back.

Ad
source: stackoverflow.com
Ad