wp-media / imagify-plugin

Speed up your website with lighter images without losing quality.
https://imagify.io
69 stars 24 forks source link

Check for missed schedule when waiting for lock to expire #646

Open iCaspar opened 2 years ago

iCaspar commented 2 years ago

Sub-task for #641

When optimization appears to get "stuck", it's because we've set transient to impose a 10 minute lock on the image during which time a background process (hooked on imagify_optimize_media_cron) should run to check that the optimization has completed. When that background process does not run (for whatever reason, generally the site cannot complete a loopback request, or cURL is out of order or too slow, the status of the optimization is not updated in the background, and therefore "no change in status" is reported when imagifybeat pings the status. This goes on for the 10 minutes the lock is in place. At the end of the 10 minutes, the lock is released, returning the button to it's "Optimize" state, as there is still no indication from the failed background process that optimization has either taken place or returned any error.

(Curiously enough, the optimization can run and successfully complete, but the status of the optimization is simply not available until the background process completes one way or another, causing the button to reflect no optimzation, when the image is actually ready to be used.)

In this sub-task, we begin remediation by checking on any given lock whether there is a "scheduled event is late" state in effect on the imagify_optimize_media_cron event, and if so, we will release the lock and return a notice to imagfybeat to update the status of the button/column data with some relevant information for the user.