Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog

AsyncGenerator::get_statuspublicWC 10.5.0

Returns the current feed generation status. Initiates one if not already running.

Method of the class: AsyncGenerator{}

No Hooks.

Returns

Array. The feed generation status.

Usage

$AsyncGenerator = new AsyncGenerator();
$AsyncGenerator->get_status( ?array $args ): array;
?array $args
.
Default: null

Changelog

Since 10.5.0 Introduced.

AsyncGenerator::get_status() code WC 11.0.0

public function get_status( ?array $args = null ): array {
	$option_key = $this->get_option_key( $args );
	$status     = get_option( $option_key );

	if ( is_array( $status ) ) {
		if ( $this->validate_status( $status ) ) {
			return $status;
		}

		// Surface a failed generation to the client once, then clear it so the next poll starts a
		// fresh run. The POS clients are built to read `failed`, stop, and let their own scheduling
		// drive the next attempt, so the server must report the failure rather than silently retry
		// it. Clearing the status (rather than leaving it sticky) matters because those clients poll
		// again with force=false, which would otherwise keep re-reading the same failure forever.
		if ( self::STATE_FAILED === ( $status['state'] ?? '' ) ) {
			$this->discard_feed( $status );
			delete_option( $option_key );
			return $status;
		}

		// A stuck in-progress job most likely died because its chunk was too large for this host;
		// step the size down so the restart is more likely to fit.
		$this->reduce_chunk_size_if_stuck( $status, $option_key );

		// Whatever made the status invalid (stuck, expired, …), discard the partial feed and start fresh.
		$this->discard_feed( $status );
	}

	// Clear all previous actions to avoid race conditions.
	as_unschedule_all_actions( self::FEED_GENERATION_ACTION, array( $option_key ), 'woo-product-feed' );

	$status = array(
		'scheduled_at' => time(),
		'updated_at'   => time(),
		'completed_at' => null,
		'state'        => self::STATE_SCHEDULED,
		'progress'     => 0,
		'processed'    => 0,
		'total'        => -1,
		'args'         => $args ?? array(),
	);

	update_option( $option_key, $status );

	$this->schedule_generation_action( $option_key );

	return $status;
}