Ecommerce Shopify WordPress Discussion

Webhook Response Timing Issue

I developed an app for a client I have. They have a Shopify store, and I set up a pythonanywhere account & several webhooks which ping pythonganywhere when they are fired. I perform some advanced tasks which take a few seconds to compute and return. Shopify requires that I return code 200 to the webhook within 5 seconds. Failing to do this several times in a row causes my webhook to get deleted. For the past few months, I got around this by running a function every 15 seconds that checks to see if all the webhooks exist, and if they don't, to readd them. However, as my client's order volume has scaled, sometimes the webhook dissapears and in the short period, an order comes in, and that order information and required functions aren't being executed for that 10 second period. An order or two's information sometimes goes missing as a result. The function that is called while I process the webhook cannot be sped up. Most of the time, I can return a 200 result within 5 seconds. On some occasions, especially with high volume, it can take 10 - 15 seconds. I have to find a way to return code 200 to the webhook and then process the information I obtained from it. Example code is below: def example(): if request.method == 'POST': example_function(request.json) return json.dumps({'success':True}), 200, {'ContentType':'application/json'} How do I execute the example_function() function but return example() before it is complete?
Another great place to use the threading module. For something simple like this, you can use from threading import Thread p = Thread(target=example_function, args=(request.json,)) p.start() Instead of calling the function directly. this will start up a seperate thread just for that function and immediately continue execution. For more complex task queues you can look at Celery or DjangoApScheduler, albeit they have their own amount of over head. EDIT from multiprocessing import Process P = Process(target=example_functino, args=(request.json,)) p.start() Works in your intsance.

December 29, 2023

TurboCommerce make the better internet purchasing globaly

Turbo Multi-language Translator

Make the better internet purchasing globaly

Turbosify SEO Speed Booster

5.0 (7) Free plan available
Get better conversions by improving store loading speed Installed

Turbo Multi-language Chat - AI Customer service in one hand

TurboCommerce make the better internet purchasing globaly
Our products

The help you need, when you need it

App by Turbo Engine

3 apps • 5.0 average rating

Turbosify Speed Booster

5.0 (7)
Get better conversions by optimizing shopify store Google page speed Installed

Turbosify Translator for Wordpress Woocommerce

5.0 (74) Free Wordpress Woocommerce Plugin
Translate your wordpress website to multiple language within 1 click, no configuration needed, no No technical required

Grow your business here

Whether you want to sell products down the street or around the world, we have all the tools you need.