AHD has a pretty complex WooCommerce setup that interfaces with some third-party (and first-party) APIs, but in addition routine maintenance and bugfixes, I managed to put a few interesting solutions in place for some unique problems. I got an intimate knowledge of how WooCommerce handles webhooks
, and I added in some custom functionality that exponentially increases the time between failed webhook retries with some creative use of WP_Cron
and WordPress transients.
Confused? I was too at first, as the WooCommerce API can be a little daunting. But essentially, we're using the WP_Cron object (because we don't have access to the server to initiate a "proper" cron job) to check a transient at a set interval, then re-attempt a webhook that returned any status other than "200". If the integer stored in the transient is less than the actual time since the last attempt, we fire the hook again. If not, we increase the integer by a predetermined factor (when I wrote the class, it was 1.25; they may have found a better one by now). Then the process starts over.
I made sure that the "meta cron", as I wound up calling it, was an extremely lightweight hit every time it fires, and then dipping into the Transients API is performant as it is. It's worked out well, and when I get around to it, I'm floating the idea of making a PR to WooCommerce core that includes this functionality.