= self::STALE_AFTER_SECONDS ) { return self::result( self::ACTION_RECOVER, 0, $age ); } return self::result( self::ACTION_IN_PROGRESS, self::retry_after( $age ), $age ); } /** * How long the client should wait before it retries. * * The wait never goes past the moment the claim becomes stale, so the retry * always lands in the lazy recovery path. * * @param int $age Age of the claim in seconds. * @return int Seconds. */ public static function retry_after( $age ) { $until_stale = self::STALE_AFTER_SECONDS - (int) $age; $retry_after = min( self::MAX_RETRY_AFTER, $until_stale ); return (int) max( self::MIN_RETRY_AFTER, $retry_after ); } /** * Build the answer. * * @param string $action Action. * @param int $retry_after Seconds. * @param int $age Seconds. * @return array */ private static function result( $action, $retry_after, $age ) { return array( 'action' => $action, 'retry_after' => (int) $retry_after, 'age' => (int) $age, ); } }