Automattic\WooCommerce\Internal\ProductFeed\Integrations\POSCatalog

AsyncGenerator::validate_statusprivateWC 1.0

Validates the status of the feed generation.

Makes sure that the file exists for completed jobs, that scheduled jobs are not stuck, etc.

Метод класса: AsyncGenerator{}

Хуки из метода

Возвращает

true|false. True if the status is valid, false otherwise.

Использование

// private - только в коде основоного (родительского) класса
$result = $this->validate_status( $status ): bool;
$status(массив) (обязательный)
The status of the feed generation.

Код AsyncGenerator::validate_status() WC 10.5.2

private function validate_status( array $status ): bool {
	/**
	 * For completed jobs, make sure the file still exists. Regenerate otherwise.
	 *
	 * The file should typically get deleted at the same time as the status is cleared.
	 * However, something else could cause the file to disappear in the meantime (ex. manual delete).
	 *
	 * Also, if the cleanup job failed, the feed might appear as complete, but be expired.
	 */
	if ( self::STATE_COMPLETED === $status['state'] ) {
		if ( ! file_exists( $status['path'] ) ) {
			return false;
		}

		if ( ! isset( $status['completed_at'] ) ) {
			return false;
		}

		if ( $status['completed_at'] + self::FEED_EXPIRY < time() ) {
			return false;
		}
	}

	/**
	 * If the job has been scheduled more than 10 minutes ago but has not
	 * transitioned to IN_PROGRESS yet, ActionScheduler is typically stuck.
	 */

	/**
	 * Allows the timeout for a feed to remain in `scheduled` state to be changed.
	 *
	 * @param int $stuck_time The stuck time in seconds.
	 * @return int The stuck time in seconds.
	 * @since 10.5.0
	 */
	$scheduled_timeout = apply_filters( 'woocommerce_product_feed_scheduled_timeout', 10 * MINUTE_IN_SECONDS );
	if (
		self::STATE_SCHEDULED === $status['state']
		&& (
			! isset( $status['scheduled_at'] )
			|| time() - $status['scheduled_at'] > $scheduled_timeout
		)
	) {
		return false;
	}

	// All good.
	return true;
}