问题描述
我有执行code(读取数据并将其存储到Azure的SQL)每隔X小时辅助角色。时序在run方法,而(真)循环使用Thread.sleep代码实现的。
I have a Worker Role that executes code (fetching data and storing it to Azure SQL) every X hours. The timing is implemented using a Thread.Sleep in the while(true) loop in the Run method.
在Web角色我想有abillity到manualy启动辅助角色的code(manualy fecth和存储数据在我的情况)。我发现,整个工作者角色可以使用Azure管理API重新启动,但它似乎是矫枉过正,特别是具有看着周围证书所需的所有工作。
In the Web Role I want to have the abillity to manualy start the code in Worker Role (manualy fecth and store data in my case). I found out that the whole Worker Role can be restarted using the Azure Management API but it seems like an overkill, especialy looking at all the work needed around certificates.
有没有更好的方式来重新从Web角色Worker角色或有工作者角色运行code从Web角色的需求呢?
Is there a better way to restart Worker Role from Web Role or have the code in Worker Role run on demand from the Web Role?
推荐答案
任何像发布一个事件,一个Azure的队列,张贴一个blob天青斑点,在Azure中的表更改记录,甚至使得SQL Azure的一些变化会工作 - Web角色会做的变化和辅助角色将等待这种变化。也许Azure的队列将是最干净的方法,虽然我不知道。
Anything like posting an event to an Azure Queue, posting a blob to Azure Blobs, changing a record in Azure Tables or even making some change in SQL Azure will work - the web role will do the change and the worker role will wait for that change. Perhaps Azure Queues would be the cleanest way, although I'm not sure.
您应该注意一个非常重要的事情是,如果你决定使用轮询 - 直到出现像查询斑点 - 你应该插入查询之间的延迟,否则该code:
One very important thing you should watch for is that if you decide to use polling - like query a blob until it appears - you should insert a delay between the queries, otherwise this code:
while( true ) {
if( storage.BlobExists( blobName ) ) {
break;
}
}
将涌入存储,你会遇到蛮横的交易费用。在SQL Azure中的情况下,你将不会看到任何费用,但会浪费在没有更好的服务能力,这会减慢你排队到SQL Azure的其他操作。
will rush into the storage and you'll encounter outrageous transaction fees. In case of SQL Azure you will not see any fees, but you'll waste the service capacity for no good and this will slow down other operations you queue to SQL Azure.
这是如何要做到:
while( true ) {
if( storage.BlobExists( blobName ) ) {
break;
}
// value should not be less that several hundred (milliseconds)
System.Threading.Thread.Sleep( 15 * 1000 );
}
这篇关于重新从Web角色的Azure工作者角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!