Azure Web 作业突然停止正常工作
Azure Web Jobs suddenly stopped working properly
我编写了一个名为 "blobsUploader" 的程序,它在每晚 11 点将 csv 文件上传到 blob 容器。
每当新的 csv 文件到达 blob 容器时,名为 "blobsAdressQueue" 的队列中就会出现一条新消息,其中包含新 blob(csv 文件)的地址。
这会调用读取 csv 文件并将其所有数据存储在名为 "myDataTable".
的 Azure Table 中的 Web 作业
整个过程运行良好,但突然从过去一两个月开始,每天晚上上传新的 csv 时,Web 作业过程都会出错,来自 "blobsAddressQueue" 的消息会移动到 "blobsAddressQueue-poison" 表示消息已超过向应用程序发送尝试的最大次数。
我现在上传了一个 2018 年 6 月的 csv,肯定有效。
但是,现在带有此 blob 地址的消息位于 "blobsAddressQueue-poison".
当我检查日志时,我可以看到 5 个失败的调用:
当我进入其中一个尝试并打开 "Toggle Output" 时,这就是我得到的:
这很奇怪,因为这个文件是在 2018 年 6 月读取的!!!没有任何问题!从那时起,我没有更改我的代码或 csv 文件中的任何内容。
如果需要更多信息来回答问题,请告诉我。
此问题与 webjob 无关,而是您引用的 CsvHelper 库。我检查了源代码,发现一个字段包含引号并且该字段未被引用(转义)时将被视为错误数据。
源代码:
/// <summary>
/// Gets or sets the function that is called when bad field data is found. A field
/// has bad data if it contains a quote and the field is not quoted (escaped).
/// You can supply your own function to do other things like logging the issue
/// instead of throwing an exception.
/// Arguments: context
/// </summary>
Action<ReadingContext> BadDataFound { get; set; }
解决方案是
修改csv文件中有问题的字段
或
通过将 BadDataFound 设置为 null 来忽略错误数据:
csv.Configuration.BadDataFound = null;
示例代码:
static void Main(string[] args)
{
using (var reader = new StreamReader(@"C:\Users\toml\Desktop\test.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.BadDataFound = null;
var records = csv.GetRecords<Foo>();
foreach(var item in records)
{
Console.WriteLine(item.Name);
}
}
Console.ReadKey();
}
}
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
无效的 CSV 样本:
Id,Name
1,one"
2,two
有效的 CSV 样本:
Id,Name
1,"one""
2,two
我编写了一个名为 "blobsUploader" 的程序,它在每晚 11 点将 csv 文件上传到 blob 容器。
每当新的 csv 文件到达 blob 容器时,名为 "blobsAdressQueue" 的队列中就会出现一条新消息,其中包含新 blob(csv 文件)的地址。
这会调用读取 csv 文件并将其所有数据存储在名为 "myDataTable".
的 Azure Table 中的 Web 作业整个过程运行良好,但突然从过去一两个月开始,每天晚上上传新的 csv 时,Web 作业过程都会出错,来自 "blobsAddressQueue" 的消息会移动到 "blobsAddressQueue-poison" 表示消息已超过向应用程序发送尝试的最大次数。
我现在上传了一个 2018 年 6 月的 csv,肯定有效。 但是,现在带有此 blob 地址的消息位于 "blobsAddressQueue-poison".
当我检查日志时,我可以看到 5 个失败的调用:
当我进入其中一个尝试并打开 "Toggle Output" 时,这就是我得到的:
如果需要更多信息来回答问题,请告诉我。
此问题与 webjob 无关,而是您引用的 CsvHelper 库。我检查了源代码,发现一个字段包含引号并且该字段未被引用(转义)时将被视为错误数据。
源代码:
/// <summary>
/// Gets or sets the function that is called when bad field data is found. A field
/// has bad data if it contains a quote and the field is not quoted (escaped).
/// You can supply your own function to do other things like logging the issue
/// instead of throwing an exception.
/// Arguments: context
/// </summary>
Action<ReadingContext> BadDataFound { get; set; }
解决方案是
修改csv文件中有问题的字段
或
通过将 BadDataFound 设置为 null 来忽略错误数据:
csv.Configuration.BadDataFound = null;
示例代码:
static void Main(string[] args)
{
using (var reader = new StreamReader(@"C:\Users\toml\Desktop\test.csv"))
using (var csv = new CsvReader(reader))
{
csv.Configuration.BadDataFound = null;
var records = csv.GetRecords<Foo>();
foreach(var item in records)
{
Console.WriteLine(item.Name);
}
}
Console.ReadKey();
}
}
public class Foo
{
public int Id { get; set; }
public string Name { get; set; }
}
无效的 CSV 样本:
Id,Name
1,one"
2,two
有效的 CSV 样本:
Id,Name
1,"one""
2,two