【问题标题】:Azure Web Jobs suddenly stopped working properlyAzure Web Jobs 突然停止正常工作
【发布时间】:2019-01-15 18:12:53
【问题描述】:

我编写了一个名为“blobsUploader”的程序,它每天晚上 11 点将 csv 文件上传到 blob 容器。

每当新的 csv 文件到达 blob 容器时,名为“blobsAdressQueue”的队列中就会出现一条新消息,其中包含新 blob(csv 文件)的地址。

这会调用读取 csv 文件并将其所有数据存储在名为“myDataTable”的 Azure 表中的 Web 作业。

整个过程运行良好,但突然从过去一两个月开始,每天晚上上传新的 csv 时,Web Job 过程出现错误,来自“blobsAddressQueue”的消息移动到“blobsAddressQueue-poison”表示已超过应用程序的最大传递尝试次数的消息。

我现在上传了 2018 年 6 月的 csv,它确实有效。 但是,现在带有此 blob 地址的消息位于“blobsAddressQueue-poison”中。

当我检查日志时,我可以看到 5 个失败的调用:

当我进行其中一项尝试并打开“切换输出”时,我得到的是: 这很奇怪,因为这个文件是在 2018 年 6 月读取的!!!没有任何问题!从那以后,我没有更改我的代码或 csv 文件中的任何内容。

如果需要更多信息来回答问题,请告诉我。

【问题讨论】:

  • CsvHelper 是外部引用吗,如NuGet package?如果是,您是否更新了此软件包?因为显然 something 发生了变化,否则你现在就会遇到这个问题。
  • @rickvdbosch 是的。我害怕更新这个包,所以我不会弄得更乱。此外,如果到目前为止一切都使用旧包并且没有更新任何其他内容,那么更新 csvHelper 有什么帮助?
  • 最重要的是,我刚刚尝试了 2017 年的另一个 csv(它们的结构完全相同)并且效果很好。@rickvdbosch
  • 同意@rickvdbosch,您的程序集发生了变化,可能与网络作业不工作无关。
  • @I.zv 我几周前发布了一个答案。你有机会看看吗?如果有帮助,您能否将其标记为答案,以便其他人轻松看到?

标签: azure csv web-applications azure-webjobs


【解决方案1】:

此问题与 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

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2016-07-18
    • 1970-01-01
    • 1970-01-01
    • 2018-08-03
    • 2022-01-10
    • 2017-08-22
    • 2021-02-01
    • 2016-12-29
    相关资源
    最近更新 更多