= self::FAILURE_LIMIT ? max( $interval, self::BACKOFF_INTERVAL ) : $interval; } /** * Whether a feed should be fetched now. * * @param array|null $entry Cache entry, or null when there is none. * @param int $interval_seconds Configured refresh interval. * @param int $now Current Unix time. */ public static function is_due( ?array $entry, int $interval_seconds, int $now ): bool { if ( null === $entry || (int) ( $entry['last_attempt'] ?? 0 ) <= 0 ) { return true; } $wait = self::effective_interval( $interval_seconds, (int) ( $entry['failures'] ?? 0 ) ); return $now - (int) $entry['last_attempt'] >= $wait; } /** * Health of a feed: pending, ok, stale or failing. * * @param array|null $entry Cache entry, or null when there is none. * @param int $interval_seconds Configured refresh interval. * @param int $now Current Unix time. */ public static function status( ?array $entry, int $interval_seconds, int $now ): string { if ( null === $entry || (int) ( $entry['last_attempt'] ?? 0 ) <= 0 ) { return self::STATUS_PENDING; } if ( (int) ( $entry['failures'] ?? 0 ) > 0 ) { return self::STATUS_FAILING; } $age = $now - (int) ( $entry['fetched_at'] ?? 0 ); return $age > self::STALE_FACTOR * max( self::MIN_INTERVAL, $interval_seconds ) ? self::STATUS_STALE : self::STATUS_OK; } }