【发布时间】:2018-05-04 03:24:52
【问题描述】:
我有一个名为TableStorageController.cs的班级
public class TableStorageController
{
private static Dictionary<string, BlockingCollection<CloudModelDetail>> s_dictionary = new Dictionary<string, BlockingCollection<CloudModelDetail>>();
private static StorageAccount s_azureStorageAccount;
private readonly CloudModelDetail _cloudModelDetail;
private static CancellationTokenSource s_cancellationTokenSource = new CancellationTokenSource();
private static int s_retailerId;
/// <summary>
/// Static task to log transactions to Azure Table Storage after every 5 minutes.
/// </summary>
static TableStorageController()
{
try
{
Task.Run(async () =>
{
while (true)
{
await Task.Delay(300000, s_cancellationTokenSource.Token);
foreach (var retaileridkey in s_dictionary.Keys)
{
var batchOperation = new TableBatchOperation();
while (s_dictionary[retaileridkey].Count != 0 && batchOperation.Count < 101)
{
batchOperation.InsertOrMerge(s_dictionary[retaileridkey].Take());
}
if (batchOperation?.Count != 0)
await s_azureStorageAccount.VerifyCloudTable.ExecuteBatchAsync(batchOperation);
}
}
});
}
catch (Exception ex)
{
s_log.Fatal("Azure task run failed", ex);
}
}
}
此任务每 5 分钟运行一次,并将字典中存在的任何项目记录到 Azure 表存储。 在本地运行我的代码时,我可以看到它每 5 分钟触发一次。 但是,不知何故,一旦在另一个环境(生产)中部署后,它就会失败。
谁能指出我错过了什么?
注意:我从来没有遇到过异常Azure task run failed。
【问题讨论】:
标签: c# async-await task azure-table-storage