fix(2meet-data-optimizer): entity health sees a running backfill
- Backfill batches are scheduled with (entity, group) args; the health panel looked for (entity) alone, never saw one and kept offering to start a backfill, which resets the group's checkpoint - is_backfill_active() checks every group of the entity - Unit bootstrap: wp_next_scheduled() stub honours hook + args - Verify: EntityHealthBackfillTest (2 new); unit 711, phpcs 0, stan OK - PR: PR-137 (manual F-11)
This commit is contained in:
@@ -325,7 +325,20 @@ final class TMDO_Entity_Health {
|
|||||||
return TMDO_Mode_Manager::ALL_MODES[ $idx - 1 ];
|
return TMDO_Mode_Manager::ALL_MODES[ $idx - 1 ];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Whether a backfill batch is scheduled for any group of the entity. Batches
|
||||||
|
* are scheduled with (entity, group) args, so looking for (entity) alone
|
||||||
|
* never found one (2.4.2 PR-137).
|
||||||
|
*
|
||||||
|
* @param string $entity_type Entity type.
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
private static function is_backfill_active( string $entity_type ): bool {
|
private static function is_backfill_active( string $entity_type ): bool {
|
||||||
return (bool) wp_next_scheduled( 'wpdo_entity_backfill_batch', array( $entity_type ) );
|
foreach ( TMDO_Entity_Registry::get_groups_for_type( $entity_type ) as $group ) {
|
||||||
|
if ( wp_next_scheduled( 'wpdo_entity_backfill_batch', array( $entity_type, $group ) ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -180,7 +180,7 @@ if ( ! function_exists( 'do_action_ref_array' ) ) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( ! function_exists( 'wp_next_scheduled' ) ) {
|
if ( ! function_exists( 'wp_next_scheduled' ) ) {
|
||||||
function wp_next_scheduled( string $hook ): int|false { return false; }
|
function wp_next_scheduled( string $hook, array $args = array() ): int|false { return $GLOBALS['_wp_next_scheduled'][ $hook ][ md5( serialize( $args ) ) ] ?? false; }
|
||||||
}
|
}
|
||||||
if ( ! function_exists( 'wp_schedule_event' ) ) {
|
if ( ! function_exists( 'wp_schedule_event' ) ) {
|
||||||
function wp_schedule_event( int $t, string $r, string $h ): bool { return true; }
|
function wp_schedule_event( int $t, string $r, string $h ): bool { return true; }
|
||||||
|
|||||||
@@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Backfill batches are scheduled per (entity, group) — REST backfill and
|
||||||
|
* TMDO_Core re-chain `wpdo_entity_backfill_batch` with both args. The health
|
||||||
|
* panel looked for (entity) alone, never found a running backfill and kept
|
||||||
|
* offering to start one; starting one resets the group's checkpoint
|
||||||
|
* (2.4.2 PR-137, manual F-11).
|
||||||
|
*/
|
||||||
|
class EntityHealthBackfillTest extends TestCase {
|
||||||
|
|
||||||
|
protected function setUp(): void {
|
||||||
|
$GLOBALS['_wp_next_scheduled'] = array();
|
||||||
|
TMDO_Entity_Registry::init();
|
||||||
|
TMDO_Entity_Registry::register_adapter( 'user', new TMDO_Adapter_User() );
|
||||||
|
TMDO_Entity_Registry::register_group( 'user', 'eh_one', array( array( 'key' => 'eh_a', 'type' => 'text' ) ) );
|
||||||
|
TMDO_Entity_Registry::register_group( 'user', 'eh_two', array( array( 'key' => 'eh_b', 'type' => 'text' ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown(): void {
|
||||||
|
$GLOBALS['_wp_next_scheduled'] = array();
|
||||||
|
TMDO_Entity_Registry::init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private function backfill_active( string $entity_type ): bool {
|
||||||
|
$m = new ReflectionMethod( TMDO_Entity_Health::class, 'is_backfill_active' );
|
||||||
|
$m->setAccessible( true );
|
||||||
|
return (bool) $m->invoke( null, $entity_type );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_a_backfill_scheduled_for_one_group_is_seen(): void {
|
||||||
|
$GLOBALS['_wp_next_scheduled']['wpdo_entity_backfill_batch'][ md5( serialize( array( 'user', 'eh_two' ) ) ) ] = time() + 5;
|
||||||
|
|
||||||
|
$this->assertTrue( $this->backfill_active( 'user' ) );
|
||||||
|
$this->assertFalse( $this->backfill_active( 'post' ), 'other entities are not affected' );
|
||||||
|
}
|
||||||
|
|
||||||
|
public function test_no_scheduled_batch_means_no_backfill(): void {
|
||||||
|
$this->assertFalse( $this->backfill_active( 'user' ) );
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user