Azure搜索重试策略 [英] Azure Search RetryPolicy

查看:69
本文介绍了Azure搜索重试策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用azure搜索,并且需要实施重试策略,并按照所述方式存储失败文档的ID.

We are using azure search and need to implement a retry stratgey as well as storing the Ids of failed documents as described.

是否存在有关如何在Azure搜索中实施RetryPolicy策略的文档/示例.

Is there any documentation/samples on how to implement a RetryPolicy strategy in Azure Search.

谢谢

推荐答案

这是我使用的:

 private async Task<DocumentIndexResult> IndexWithExponentialBackoffAsync(IndexBatch<IndexModel> indexBatch)
 {
      return await Policy
           .Handle<IndexBatchException>()
           .WaitAndRetryAsync(5, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)), (ex, span) =>
           {
                indexBatch = ((IndexBatchException)ex).FindFailedActionsToRetry(indexBatch, x => x.Id);
           })
           .ExecuteAsync(async () => await _searchClient.IndexAsync(indexBatch));
 }

它使用 Polly库处理指数补偿.在这种情况下,我使用的模型IndexModel具有一个名为Id的id字段. 如果您想记录或存储失败尝试的ID,可以在WaitAndRetryAsync函数(如

It uses the Polly library to handle exponential backoff. In this case I use a model IndexModel that has a id field named Id. If you like to log or store the ids of the failed attempts you can do that in the WaitAndRetryAsync function like

((IndexBatchException)ex)ex.IndexingResults.Where(r => !r.Succeeded).Select(r => r.Key).<Do something here>

这篇关于Azure搜索重试策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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