Skip to content

Commit

Permalink
1.1.1 don't let actions run for more than 25s. Add ActionScheduler pu…
Browse files Browse the repository at this point in the history
…rge cronjob.
  • Loading branch information
OllieJones committed Aug 14, 2024
1 parent 0b66fe5 commit a7fecd5
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 9 deletions.
7 changes: 4 additions & 3 deletions code/class-textdex.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public function load_batch() {
$start_time = time();
/* Give ourselves max_execution_time -10 sec to run, unless max_execution_time is very short. */
$max_time = ini_get( 'max_execution_time' );
$safe_time = ( $max_time > 30 ) ? 10 : 2;
$max_time = ( $max_time > 30 ) ? 30 : $max_time;
$safe_time = ( $max_time > 30 ) ? 5 : 2;
$end_time = $start_time + $max_time - $safe_time;
$end_time = ( $end_time > $start_time ) ? $end_time : $start_time + 1;
set_time_limit( $max_time );
Expand All @@ -113,7 +114,7 @@ public function load_batch() {
$cust->get_order_custom_field_names();
$done = false;
$another_batch = false;
while ( ! $done ) {
while( ! $done ) {
$another_batch = $this->load_next_batch();
if ( ! $another_batch ) {
$done = true;
Expand All @@ -135,7 +136,7 @@ public function load_batch() {

public function schedule_batch() {
if ( $this->have_more_batches() ) {
as_enqueue_async_action( 'fast_woo_order_lookup_textdex_action', array(), 'fast_woo_order_lookup' , true);
as_enqueue_async_action( 'fast_woo_order_lookup_textdex_action', array(), 'fast_woo_order_lookup', true );
}
}

Expand Down
2 changes: 1 addition & 1 deletion fast-woo-order-lookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* Plugin Name: Fast Woo Order Lookup
* Plugin URI: https://plumislandmedia.net/wordpress-plugins/fast-woo-order-lookup/
* Description: Look up orders faster in large WooCommerce stores with many orders.
* Version: 1.1.0
* Version: 1.1.1
* Author: Ollie Jones
* Author URI: https://github.com/OllieJones
* Text Domain: fast-woo-order-lookup
Expand Down
8 changes: 4 additions & 4 deletions languages/fast-woo-order-lookup.pot
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Copyright (C) 2024 OllieJones
# Copyright (C) 2024 Ollie Jones
# This file is distributed under the GPLv2.
msgid ""
msgstr ""
"Project-Id-Version: Fast Woo Order Lookup 1.1.0\n"
"Project-Id-Version: Fast Woo Order Lookup 1.1.1\n"
"Report-Msgid-Bugs-To: https://wordpress.org/support/plugin/fast-woo-order-lookup\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <[email protected]>\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"POT-Creation-Date: 2024-08-11T06:30:30-04:00\n"
"POT-Creation-Date: 2024-08-14T13:46:02-04:00\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"X-Generator: WP-CLI 2.9.0\n"
"X-Domain: fast-woo-order-lookup\n"
Expand All @@ -27,7 +27,7 @@ msgid "Look up orders faster in large WooCommerce stores with many orders."
msgstr ""

#. Author of the plugin
msgid "OllieJones"
msgid "Ollie Jones"
msgstr ""

#. Author URI of the plugin
Expand Down
6 changes: 5 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Tags: woocommerce, search, orders, database, performance
Requires at least: 5.9
Tested up to: 6.6.1
Requires PHP: 5.6
Stable tag: 1.1.0
Stable tag: 1.1.1
Requires Plugins: woocommerce
License: GPLv2
Text Domain: fast-woo-order-lookup
Expand Down Expand Up @@ -94,6 +94,10 @@ When you install this upgrade, the plugin repeats the indexing process to add so

== Changelog ==

= 1.1.1 August 12, 2024 =

* Limit batch runtime to 25 seconds. Include a cronjob shell script to purge stale ActionScheduler actions.

= 1.1.0 August 11, 2024 =

* Some MariaDB / MySQL versions implicitly cast integers to latin1 strings causing problems. Explicit casting fixes the issue.
Expand Down
22 changes: 22 additions & 0 deletions scripts/purge-action-scheduler
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/sh
# Purge the action scheduler.
#
# The ActionScheduler in WooCommerce (and other WordPress subsystems) accumulates complete, failed, and canceled actions.
#
# This shell script, run as a cronjob (debugged on Ubuntu GNU/Linux) deletes old actions
# to keep the wp_actionscheduler_actions table from growing too large.
# It puts an entry into /var/log/syslog saying how many actions it purged.
#
# The following crontab entry will run this purge script each day at 04:01
#
# You need to change '/var/www/html/' to the top level directory of your WordPress installation, and take off the
# leading # comment character when you put this entry into the crontab.
#
# 1 4 * * * /var/www/html/wp-content/plugins/fast-woo-order-lookup/scripts/purge-action-scheduler >>/tmp/foo 2>>/tmp/foo

cd `dirname $0`
cd ../../../..
echo -n $0 >/tmp/purge-action-scheduler$$
wp action-scheduler clean --status=complete,failed,canceled --before='60 days ago' --batch-size=1000 --pause=2 | grep deleted | tail -1 >>/tmp/purge-action-scheduler$$
logger --file /tmp/purge-action-scheduler$$
rm /tmp/purge-action-scheduler$$

0 comments on commit a7fecd5

Please sign in to comment.