azure-functions - Azure 函数有时会在出队时启动多个实例
问题描述
我有一个相当简单的天蓝色函数,设置如下:
{
"queues": {
"maxPollingInterval": 2000,
"visibilityTimeout": "00:10:00",
"maxDequeueCount": 3,
"batchSize": 12,
"newBatchThreshold": 6
}
}
我注意到有时当函数失败时,它会按预期将消息出队,然后重试再次执行该函数。问题是有时它会在同一条消息上启动两个实例。这是已知的行为吗?我的功能如下所示。在抛出异常之前我应该做些什么吗?
[FunctionName("MoveCopyFilesFolders")]
public static void Run([QueueTrigger("xx", Connection = "StorageConnStr")]string jobIdStr, TraceWriter log)
{
log.Info($"MoveCopyFilesFolders processed: {jobIdStr}");
Dictionary<string, string> properties = new Dictionary<string, string> { { "service", "xx" }, { "jobid", jobIdStr } };
KK.Common.Instrumentation.AILogger logger = new KK.Common.Instrumentation.AILogger(configuration.ApplicationInsightsKey, properties);
try
{
logger.WriteTrace($"Start moving/copy files/folders for jobid: {jobIdStr}", SeverityLevel.Verbose);
var jobId = Int32.Parse(jobIdStr);
var moveCopyRepo = new CopyMoveRepository(configuration.DBConnectionString);
var appRegRepo = new AppRegistrationRepository(configuration.DBConnectionString);
CopyOrMoveItemsService.Run(jobId, moveCopyRepo, appRegRepo, logger);
logger.WriteTrace("End move/copy files for site", SeverityLevel.Information);
logger.Flush();
}
catch (Exception ex)
{
log.Info(ex.Message);
logger.WriteException(ex);
logger.Flush();
throw ex;
}
}
我看到的行为是函数按预期启动,只有一个实例。当失败时,有时会在同一条消息上启动两个实例。我可以看到,因为我添加了 10 条具有不同 id 的消息作为输入,并且在失败后两个实例以相同的 id 运行。
解决方案
推荐阅读
- google-apps-script - 在 Google Drive API 的 Apps 脚本中启用高级 Google 服务 - 是否需要付费?
- ansible - 使用 Ansible 中的 authorized_key 模块将多个公共 ssh 密钥分配给用户定义
- c# - 从 C# 中的 DropDownList 中选择日、月和年日期
- java - 使用 exoplayer 在 android 9 和 10 上播放流时出错
- python-3.x - psycopg2 命名游标保留=True
- javascript - 如何解决 Object.defineProperty 的可配置问题?
- mysql - 如何使用 GROUP_CONCAT 在 GROUP BY 之后加入?
- python - 查找两个字符串之间的所有公共子字符串,不考虑大小写和顺序
- ios - 制作具有功能的独立类并在 InterfaceController 类中使用它
- list - 更改项目符号和文本之间的距离 | 用于 Word 的 API JavaScript