是不是可以注册一个回调函数来waitUntilDBInstanceAvailable()? [英] Is it possible to register a callback function to waitUntilDBInstanceAvailable()?

查看:217
本文介绍了是不是可以注册一个回调函数来waitUntilDBInstanceAvailable()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用AWS SDK的PHP,并有一个命令行工具等待一个数据库实例可以使用<创建的href="http://docs.aws.amazon.com/aws-sdk-php-2/latest/class-Aws.Rds.RdsClient.html#_waitUntilDBInstanceAvailable"相对=nofollow> 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.

这篇关于是不是可以注册一个回调函数来waitUntilDBInstanceAvailable()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆