PluginProbe ʕ •ᴥ•ʔ
Transferito: WP Migration / trunk
Transferito: WP Migration vtrunk
trunk 11.4.0 12.0.0 13.1.0 14.0.0 14.0.11 14.0.7 14.1.0 14.1.1 14.1.2 14.1.3 14.1.4
transferito / vendor / aws / aws-sdk-php / src / Waiter.php
transferito / vendor / aws / aws-sdk-php / src Last commit date
ACMPCA 11 months ago ARCZonalShift 11 months ago AccessAnalyzer 11 months ago Account 11 months ago Acm 11 months ago AlexaForBusiness 11 months ago Amplify 11 months ago AmplifyBackend 11 months ago AmplifyUIBuilder 11 months ago Api 11 months ago ApiGateway 11 months ago ApiGatewayManagementApi 11 months ago ApiGatewayV2 11 months ago AppConfig 11 months ago AppConfigData 11 months ago AppFabric 11 months ago AppIntegrationsService 11 months ago AppMesh 11 months ago AppRegistry 11 months ago AppRunner 11 months ago AppSync 11 months ago Appflow 11 months ago ApplicationAutoScaling 11 months ago ApplicationCostProfiler 11 months ago ApplicationDiscoveryService 11 months ago ApplicationInsights 11 months ago Appstream 11 months ago Arn 11 months ago Athena 11 months ago AuditManager 11 months ago AugmentedAIRuntime 11 months ago AutoScaling 11 months ago AutoScalingPlans 11 months ago B2bi 11 months ago BCMDataExports 11 months ago Backup 11 months ago BackupGateway 11 months ago BackupStorage 11 months ago Batch 11 months ago Bedrock 11 months ago BedrockAgent 11 months ago BedrockAgentRuntime 11 months ago BedrockRuntime 11 months ago BillingConductor 11 months ago Braket 11 months ago Budgets 11 months ago Chime 11 months ago ChimeSDKIdentity 11 months ago ChimeSDKMediaPipelines 11 months ago ChimeSDKMeetings 11 months ago ChimeSDKMessaging 11 months ago ChimeSDKVoice 11 months ago CleanRooms 11 months ago CleanRoomsML 11 months ago ClientSideMonitoring 11 months ago Cloud9 11 months ago CloudControlApi 11 months ago CloudDirectory 11 months ago CloudFormation 11 months ago CloudFront 11 months ago CloudFrontKeyValueStore 11 months ago CloudHSMV2 11 months ago CloudHsm 11 months ago CloudSearch 11 months ago CloudSearchDomain 11 months ago CloudTrail 11 months ago CloudTrailData 11 months ago CloudWatch 11 months ago CloudWatchEvents 11 months ago CloudWatchEvidently 11 months ago CloudWatchLogs 11 months ago CloudWatchRUM 11 months ago CodeArtifact 11 months ago CodeBuild 11 months ago CodeCatalyst 11 months ago CodeCommit 11 months ago CodeDeploy 11 months ago CodeGuruProfiler 11 months ago CodeGuruReviewer 11 months ago CodeGuruSecurity 11 months ago CodePipeline 11 months ago CodeStar 11 months ago CodeStarNotifications 11 months ago CodeStarconnections 11 months ago CognitoIdentity 11 months ago CognitoIdentityProvider 11 months ago CognitoSync 11 months ago Comprehend 11 months ago ComprehendMedical 11 months ago ComputeOptimizer 11 months ago ConfigService 11 months ago Configuration 11 months ago Connect 11 months ago ConnectCampaignService 11 months ago ConnectCases 11 months ago ConnectContactLens 11 months ago ConnectParticipant 11 months ago ConnectWisdomService 11 months ago ControlTower 11 months ago CostExplorer 11 months ago CostOptimizationHub 11 months ago CostandUsageReportService 11 months ago Credentials 11 months ago Crypto 11 months ago CustomerProfiles 11 months ago DAX 11 months ago DLM 11 months ago DataExchange 11 months ago DataPipeline 11 months ago DataSync 11 months ago DataZone 11 months ago DatabaseMigrationService 11 months ago DefaultsMode 11 months ago Detective 11 months ago DevOpsGuru 11 months ago DeviceFarm 11 months ago DirectConnect 11 months ago DirectoryService 11 months ago DocDB 11 months ago DocDBElastic 11 months ago DynamoDb 11 months ago DynamoDbStreams 11 months ago EBS 11 months ago EC2InstanceConnect 11 months ago ECRPublic 11 months ago EKS 11 months ago EKSAuth 11 months ago EMRContainers 11 months ago EMRServerless 11 months ago Ec2 11 months ago Ecr 11 months ago Ecs 11 months ago Efs 11 months ago ElastiCache 11 months ago ElasticBeanstalk 11 months ago ElasticInference 11 months ago ElasticLoadBalancing 11 months ago ElasticLoadBalancingV2 11 months ago ElasticTranscoder 11 months ago ElasticsearchService 11 months ago Emr 11 months ago Endpoint 11 months ago EndpointDiscovery 11 months ago EndpointV2 11 months ago EntityResolution 11 months ago EventBridge 11 months ago Exception 11 months ago FIS 11 months ago FMS 11 months ago FSx 11 months ago FinSpaceData 11 months ago Firehose 11 months ago ForecastQueryService 11 months ago ForecastService 11 months ago FraudDetector 11 months ago FreeTier 11 months ago GameLift 11 months ago Glacier 11 months ago GlobalAccelerator 11 months ago Glue 11 months ago GlueDataBrew 11 months ago Greengrass 11 months ago GreengrassV2 11 months ago GroundStation 11 months ago GuardDuty 11 months ago Handler 11 months ago Health 11 months ago HealthLake 11 months ago Honeycode 11 months ago IVS 11 months ago IVSRealTime 11 months ago Iam 11 months ago Identity 11 months ago IdentityStore 11 months ago ImportExport 11 months ago Inspector 11 months ago Inspector2 11 months ago InspectorScan 11 months ago InternetMonitor 11 months ago IoT1ClickDevicesService 11 months ago IoT1ClickProjects 11 months ago IoTAnalytics 11 months ago IoTDeviceAdvisor 11 months ago IoTEvents 11 months ago IoTEventsData 11 months ago IoTFleetHub 11 months ago IoTFleetWise 11 months ago IoTJobsDataPlane 11 months ago IoTRoboRunner 11 months ago IoTSecureTunneling 11 months ago IoTSiteWise 11 months ago IoTThingsGraph 11 months ago IoTTwinMaker 11 months ago IoTWireless 11 months ago Iot 11 months ago IotDataPlane 11 months ago Kafka 11 months ago KafkaConnect 11 months ago KendraRanking 11 months ago Keyspaces 11 months ago Kinesis 11 months ago KinesisAnalytics 11 months ago KinesisAnalyticsV2 11 months ago KinesisVideo 11 months ago KinesisVideoArchivedMedia 11 months ago KinesisVideoMedia 11 months ago KinesisVideoSignalingChannels 11 months ago KinesisVideoWebRTCStorage 11 months ago Kms 11 months ago LakeFormation 11 months ago Lambda 11 months ago LaunchWizard 11 months ago LexModelBuildingService 11 months ago LexModelsV2 11 months ago LexRuntimeService 11 months ago LexRuntimeV2 11 months ago LicenseManager 11 months ago LicenseManagerLinuxSubscriptions 11 months ago LicenseManagerUserSubscriptions 11 months ago Lightsail 11 months ago LocationService 11 months ago LookoutEquipment 11 months ago LookoutMetrics 11 months ago LookoutforVision 11 months ago MQ 11 months ago MTurk 11 months ago MWAA 11 months ago MachineLearning 11 months ago Macie2 11 months ago MainframeModernization 11 months ago ManagedBlockchain 11 months ago ManagedBlockchainQuery 11 months ago ManagedGrafana 11 months ago MarketplaceAgreement 11 months ago MarketplaceCatalog 11 months ago MarketplaceCommerceAnalytics 11 months ago MarketplaceDeployment 11 months ago MarketplaceEntitlementService 11 months ago MarketplaceMetering 11 months ago MediaConnect 11 months ago MediaConvert 11 months ago MediaLive 11 months ago MediaPackage 11 months ago MediaPackageV2 11 months ago MediaPackageVod 11 months ago MediaStore 11 months ago MediaStoreData 11 months ago MediaTailor 11 months ago MedicalImaging 11 months ago MemoryDB 11 months ago MigrationHub 11 months ago MigrationHubConfig 11 months ago MigrationHubOrchestrator 11 months ago MigrationHubRefactorSpaces 11 months ago MigrationHubStrategyRecommendations 11 months ago Mobile 11 months ago Multipart 11 months ago Neptune 11 months ago Neptunedata 11 months ago NetworkFirewall 11 months ago NetworkManager 11 months ago NimbleStudio 11 months ago OAM 11 months ago OSIS 11 months ago Omics 11 months ago OpenSearchServerless 11 months ago OpenSearchService 11 months ago OpsWorks 11 months ago OpsWorksCM 11 months ago Organizations 11 months ago Outposts 11 months ago PI 11 months ago Panorama 11 months ago PaymentCryptography 11 months ago PaymentCryptographyData 11 months ago PcaConnectorAd 11 months ago Personalize 11 months ago PersonalizeEvents 11 months ago PersonalizeRuntime 11 months ago Pinpoint 11 months ago PinpointEmail 11 months ago PinpointSMSVoice 11 months ago PinpointSMSVoiceV2 11 months ago Pipes 11 months ago Polly 11 months ago Pricing 11 months ago PrivateNetworks 11 months ago PrometheusService 11 months ago Proton 11 months ago QBusiness 11 months ago QConnect 11 months ago QLDB 11 months ago QLDBSession 11 months ago QuickSight 11 months ago RAM 11 months ago RDSDataService 11 months ago Rds 11 months ago RecycleBin 11 months ago Redshift 11 months ago RedshiftDataAPIService 11 months ago RedshiftServerless 11 months ago Rekognition 11 months ago Repostspace 11 months ago ResilienceHub 11 months ago ResourceExplorer2 11 months ago ResourceGroups 11 months ago ResourceGroupsTaggingAPI 11 months ago Retry 11 months ago RoboMaker 11 months ago RolesAnywhere 11 months ago Route53 11 months ago Route53Domains 11 months ago Route53RecoveryCluster 11 months ago Route53RecoveryControlConfig 11 months ago Route53RecoveryReadiness 11 months ago Route53Resolver 11 months ago S3 11 months ago S3Control 11 months ago S3Outposts 11 months ago SSMContacts 11 months ago SSMIncidents 11 months ago SSO 11 months ago SSOAdmin 11 months ago SSOOIDC 11 months ago SageMaker 11 months ago SageMakerFeatureStoreRuntime 11 months ago SageMakerGeospatial 11 months ago SageMakerMetrics 11 months ago SageMakerRuntime 11 months ago SagemakerEdgeManager 11 months ago SavingsPlans 11 months ago Scheduler 11 months ago Schemas 11 months ago Script 11 months ago SecretsManager 11 months ago SecurityHub 11 months ago SecurityLake 11 months ago ServerlessApplicationRepository 11 months ago ServiceCatalog 11 months ago ServiceDiscovery 11 months ago ServiceQuotas 11 months ago Ses 11 months ago SesV2 11 months ago Sfn 11 months ago Shield 11 months ago Signature 11 months ago SimSpaceWeaver 11 months ago Sms 11 months ago SnowBall 11 months ago SnowDeviceManagement 11 months ago Sns 11 months ago Sqs 11 months ago Ssm 11 months ago SsmSap 11 months ago StorageGateway 11 months ago Sts 11 months ago Support 11 months ago SupportApp 11 months ago Swf 11 months ago Synthetics 11 months ago Textract 11 months ago TimestreamQuery 11 months ago TimestreamWrite 11 months ago Tnb 11 months ago Token 11 months ago TranscribeService 11 months ago Transfer 11 months ago Translate 11 months ago TrustedAdvisor 11 months ago VPCLattice 11 months ago VerifiedPermissions 11 months ago VoiceID 11 months ago WAFV2 11 months ago Waf 11 months ago WafRegional 11 months ago WellArchitected 11 months ago WorkDocs 11 months ago WorkLink 11 months ago WorkMail 11 months ago WorkMailMessageFlow 11 months ago WorkSpaces 11 months ago WorkSpacesThinClient 11 months ago WorkSpacesWeb 11 months ago XRay 11 months ago data 11 months ago drs 11 months ago finspace 11 months ago imagebuilder 11 months ago ivschat 11 months ago kendra 11 months ago mgn 11 months ago signer 11 months ago AbstractConfigurationProvider.php 11 months ago AwsClient.php 11 months ago AwsClientInterface.php 11 months ago AwsClientTrait.php 11 months ago CacheInterface.php 11 months ago ClientResolver.php 11 months ago Command.php 11 months ago CommandInterface.php 11 months ago CommandPool.php 11 months ago ConfigurationProviderInterface.php 11 months ago DoctrineCacheAdapter.php 11 months ago EndpointParameterMiddleware.php 11 months ago HandlerList.php 11 months ago HasDataTrait.php 11 months ago HasMonitoringEventsTrait.php 11 months ago HashInterface.php 11 months ago HashingStream.php 11 months ago History.php 11 months ago IdempotencyTokenMiddleware.php 11 months ago InputValidationMiddleware.php 11 months ago JsonCompiler.php 11 months ago LruArrayCache.php 11 months ago Middleware.php 11 months ago MockHandler.php 11 months ago MonitoringEventsInterface.php 11 months ago MultiRegionClient.php 11 months ago PhpHash.php 11 months ago PresignUrlMiddleware.php 11 months ago Psr16CacheAdapter.php 11 months ago PsrCacheAdapter.php 11 months ago QueryCompatibleInputMiddleware.php 11 months ago RequestCompressionMiddleware.php 11 months ago ResponseContainerInterface.php 11 months ago Result.php 11 months ago ResultInterface.php 11 months ago ResultPaginator.php 11 months ago RetryMiddleware.php 11 months ago RetryMiddlewareV2.php 11 months ago Sdk.php 11 months ago StreamRequestPayloadMiddleware.php 11 months ago TraceMiddleware.php 11 months ago Waiter.php 11 months ago WrappedHttpHandler.php 11 months ago functions.php 11 months ago
Waiter.php
267 lines
1 <?php
2 namespace Aws;
3
4 use Aws\Exception\AwsException;
5 use GuzzleHttp\Promise\Coroutine;
6 use GuzzleHttp\Promise\PromiseInterface;
7 use GuzzleHttp\Promise\PromisorInterface;
8 use GuzzleHttp\Promise\RejectedPromise;
9
10 /**
11 * "Waiters" are associated with an AWS resource (e.g., EC2 instance), and poll
12 * that resource and until it is in a particular state.
13
14 * The Waiter object produces a promise that is either a.) resolved once the
15 * waiting conditions are met, or b.) rejected if the waiting conditions cannot
16 * be met or has exceeded the number of allowed attempts at meeting the
17 * conditions. You can use waiters in a blocking or non-blocking way, depending
18 * on whether you call wait() on the promise.
19
20 * The configuration for the waiter must include information about the operation
21 * and the conditions for wait completion.
22 */
23 class Waiter implements PromisorInterface
24 {
25 /** @var AwsClientInterface Client used to execute each attempt. */
26 private $client;
27
28 /** @var string Name of the waiter. */
29 private $name;
30
31 /** @var array Params to use with each attempt operation. */
32 private $args;
33
34 /** @var array Waiter configuration. */
35 private $config;
36
37 /** @var array Default configuration options. */
38 private static $defaults = ['initDelay' => 0, 'before' => null];
39
40 /** @var array Required configuration options. */
41 private static $required = [
42 'acceptors',
43 'delay',
44 'maxAttempts',
45 'operation',
46 ];
47
48 /**
49 * The array of configuration options include:
50 *
51 * - acceptors: (array) Array of acceptor options
52 * - delay: (int) Number of seconds to delay between attempts
53 * - maxAttempts: (int) Maximum number of attempts before failing
54 * - operation: (string) Name of the API operation to use for polling
55 * - before: (callable) Invoked before attempts. Accepts command and tries.
56 *
57 * @param AwsClientInterface $client Client used to execute commands.
58 * @param string $name Waiter name.
59 * @param array $args Command arguments.
60 * @param array $config Waiter config that overrides defaults.
61 *
62 * @throws \InvalidArgumentException if the configuration is incomplete.
63 */
64 public function __construct(
65 AwsClientInterface $client,
66 $name,
67 array $args = [],
68 array $config = []
69 ) {
70 $this->client = $client;
71 $this->name = $name;
72 $this->args = $args;
73
74 // Prepare and validate config.
75 $this->config = $config + self::$defaults;
76 foreach (self::$required as $key) {
77 if (!isset($this->config[$key])) {
78 throw new \InvalidArgumentException(
79 'The provided waiter configuration was incomplete.'
80 );
81 }
82 }
83 if ($this->config['before'] && !is_callable($this->config['before'])) {
84 throw new \InvalidArgumentException(
85 'The provided "before" callback is not callable.'
86 );
87 }
88 }
89
90 /**
91 * @return Coroutine
92 */
93 public function promise(): PromiseInterface
94 {
95 return Coroutine::of(function () {
96 $name = $this->config['operation'];
97 for ($state = 'retry', $attempt = 1; $state === 'retry'; $attempt++) {
98 // Execute the operation.
99 $args = $this->getArgsForAttempt($attempt);
100 $command = $this->client->getCommand($name, $args);
101 try {
102 if ($this->config['before']) {
103 $this->config['before']($command, $attempt);
104 }
105 $result = (yield $this->client->executeAsync($command));
106 } catch (AwsException $e) {
107 $result = $e;
108 }
109
110 // Determine the waiter's state and what to do next.
111 $state = $this->determineState($result);
112 if ($state === 'success') {
113 yield $command;
114 } elseif ($state === 'failed') {
115 $msg = "The {$this->name} waiter entered a failure state.";
116 if ($result instanceof \Exception) {
117 $msg .= ' Reason: ' . $result->getMessage();
118 }
119 yield new RejectedPromise(new \RuntimeException($msg));
120 } elseif ($state === 'retry'
121 && $attempt >= $this->config['maxAttempts']
122 ) {
123 $state = 'failed';
124 yield new RejectedPromise(new \RuntimeException(
125 "The {$this->name} waiter failed after attempt #{$attempt}."
126 ));
127 }
128 }
129 });
130 }
131
132 /**
133 * Gets the operation arguments for the attempt, including the delay.
134 *
135 * @param $attempt Number of the current attempt.
136 *
137 * @return mixed integer
138 */
139 private function getArgsForAttempt($attempt)
140 {
141 $args = $this->args;
142
143 // Determine the delay.
144 $delay = ($attempt === 1)
145 ? $this->config['initDelay']
146 : $this->config['delay'];
147 if (is_callable($delay)) {
148 $delay = $delay($attempt);
149 }
150
151 // Set the delay. (Note: handlers except delay in milliseconds.)
152 if (!isset($args['@http'])) {
153 $args['@http'] = [];
154 }
155 $args['@http']['delay'] = $delay * 1000;
156
157 return $args;
158 }
159
160 /**
161 * Determines the state of the waiter attempt, based on the result of
162 * polling the resource. A waiter can have the state of "success", "failed",
163 * or "retry".
164 *
165 * @param mixed $result
166 *
167 * @return string Will be "success", "failed", or "retry"
168 */
169 private function determineState($result)
170 {
171 foreach ($this->config['acceptors'] as $acceptor) {
172 $matcher = 'matches' . ucfirst($acceptor['matcher']);
173 if ($this->{$matcher}($result, $acceptor)) {
174 return $acceptor['state'];
175 }
176 }
177
178 return $result instanceof \Exception ? 'failed' : 'retry';
179 }
180
181 /**
182 * @param Result $result Result or exception.
183 * @param array $acceptor Acceptor configuration being checked.
184 *
185 * @return bool
186 */
187 private function matchesPath($result, array $acceptor)
188 {
189 return !($result instanceof ResultInterface)
190 ? false
191 : $acceptor['expected'] == $result->search($acceptor['argument']);
192 }
193
194 /**
195 * @param Result $result Result or exception.
196 * @param array $acceptor Acceptor configuration being checked.
197 *
198 * @return bool
199 */
200 private function matchesPathAll($result, array $acceptor)
201 {
202 if (!($result instanceof ResultInterface)) {
203 return false;
204 }
205
206 $actuals = $result->search($acceptor['argument']) ?: [];
207 foreach ($actuals as $actual) {
208 if ($actual != $acceptor['expected']) {
209 return false;
210 }
211 }
212
213 return true;
214 }
215
216 /**
217 * @param Result $result Result or exception.
218 * @param array $acceptor Acceptor configuration being checked.
219 *
220 * @return bool
221 */
222 private function matchesPathAny($result, array $acceptor)
223 {
224 if (!($result instanceof ResultInterface)) {
225 return false;
226 }
227
228 $actuals = $result->search($acceptor['argument']) ?: [];
229 return in_array($acceptor['expected'], $actuals);
230 }
231
232 /**
233 * @param Result $result Result or exception.
234 * @param array $acceptor Acceptor configuration being checked.
235 *
236 * @return bool
237 */
238 private function matchesStatus($result, array $acceptor)
239 {
240 if ($result instanceof ResultInterface) {
241 return $acceptor['expected'] == $result['@metadata']['statusCode'];
242 }
243
244 if ($result instanceof AwsException && $response = $result->getResponse()) {
245 return $acceptor['expected'] == $response->getStatusCode();
246 }
247
248 return false;
249 }
250
251 /**
252 * @param Result $result Result or exception.
253 * @param array $acceptor Acceptor configuration being checked.
254 *
255 * @return bool
256 */
257 private function matchesError($result, array $acceptor)
258 {
259 if ($result instanceof AwsException) {
260 return $result->isConnectionError()
261 || $result->getAwsErrorCode() == $acceptor['expected'];
262 }
263
264 return false;
265 }
266 }
267