是不是可以注册一个回调函数来waitUntilDBInstanceAvailable()?回调、函数、waitUntilDBInstanceAvailable

由网友(把心掐死算了)分享简介:我使用AWS SDK的PHP,并有一个命令行工具等待一个数据库实例可以使用 waitUntilDBInstanceAvailable():I'm using the AWS SDK for PHP, and have a command-line tool waiting for a DB instance to b...

我使用AWS SDK的PHP,并有一个命令行工具等待一个数据库实例可以使用 waitUntilDBInstanceAvailable():

I'm using the AWS SDK for PHP, and have a command-line tool waiting for a DB instance to be created with waitUntilDBInstanceAvailable():

$this->rdsClient->waitUntilDBInstanceAvailable([
    'DBInstanceIdentifier' => 'test'
]);

有没有办法注册一个回调函数,这样每次SDK的投票RDS,我的回调函数被调用?

是这样的:

$this->rdsClient->waitUntilDBInstanceAvailable([
    'DBInstanceIdentifier' => 'test',
    'CallbackFunction'     => function() {
        echo '.';
    }
]);

这将使用户的事实,剧本仍在等待一些反馈,并没有挂随意。

That would give the user some feedback about the fact that the script is still waiting, and did not hang arbitrarily.

该医生说:

输入数组使用DescribeDBInstances操作的参数和服务员特定设置

The input array uses the parameters of the DescribeDBInstances operation and waiter specific settings

但我无法找出这些的服务员特定设置的是。

But I couldn't find out what these waiter specific settings are.

推荐答案

有一个的页专讲服务员在AWS SDK的PHP的用户指南。在该页面中也谈到了如何使用事件侦听器的侍应生。你需要直接跟服务员对象进行交互。

There is a page specifically about waiters in the AWS SDK for PHP User Guide. On that page it talks about how use event listeners with waiters. You need to interact directly with the waiter object.

// Get and configure the waiter object
$waiter = $client->getWaiter('BucketExists')
    ->setConfig(array('Bucket' => 'my-bucket'))
    ->setInterval(10)
    ->setMaxAttempts(3);

// Get the event dispatcher and register listeners for both events emitted by the waiter
$dispatcher = $waiter->getEventDispatcher();
$dispatcher->addListener('waiter.before_attempt', function () {
    echo "Checking if the wait condition has been met…n";
});
$dispatcher->addListener('waiter.before_wait', function () use ($waiter) {
    $interval = $waiter->getInterval();
    echo "Sleeping for {$interval} seconds…n";
});

$waiter->wait();

// Also Licensed under version 2.0 of the Apache License.
阅读全文

相关推荐

最新文章