WebJobs SDK 在 AzureWebJobsDashboard 连接中创建的 blob 的清理机制是啥?

Posted

技术标签:

【中文标题】WebJobs SDK 在 AzureWebJobsDashboard 连接中创建的 blob 的清理机制是啥?【英文标题】:What is the clean up mechanism for the blobs that WebJobs SDK creates in the AzureWebJobsDashboard connection?WebJobs SDK 在 AzureWebJobsDashboard 连接中创建的 blob 的清理机制是什么? 【发布时间】:2017-09-01 17:31:07 【问题描述】:

Azure WebJob SDK 使用在 AzureWebJobsStorageAzureWebJobsDashboard 应用程序设置中定义的存储连接字符串用于其日志记录和仪表板。

WebJob SDK 在AzureWebJobsStorage 中创建以下 blob 容器:

azure-webjobs-hosts

WebJob SDK 在AzureWebJobsDashboard 中创建以下 blob 容器

azure-jobs-host-output azure-webjobs-hosts

在 WebJob 运行时,会在上述 blob 容器中创建许多 blob。如果没有清理机制,容器可能会膨胀或饱和。

上述blob容器的清理机制是什么?

更新

下面的答案是一种解决方法。此时,没有内置机制来清理 WebJobs 日志。由于 Job 长期运行,日志可能会堆积得很大。开发人员必须自己创建清理机制。 Azure Functions 是实现此类清理过程的好方法。下面的答案中提供了一个示例。

【问题讨论】:

【参考方案1】:

WebJobs SDK 在 AzureWebJobsDashboard 连接中创建的 blob 的清理机制是什么?

我还没有找到方法。 GitHub 上有一个与此主题相关的未解决问题,但尚未关闭。

No way to set webjob logging retention policy

在 GitHub 上的一个类似问题中,我们发现 Azure WebJob SDK 改变了将日志保存到 Azure 表存储的多个表的方式。我们可以很容易地每月删除表。对于在 Azure Blob 存储中写入的日志,到目前为止还没有按月分组。

WebJobs.Logging needs to support log purge / retention policies

要删除旧的 WebJob 日志,我建议您创建一个时间触发的 WebJob 来删除您想要的日志。

是否有任何 AzureFunction 代码示例显示如何进行 blob 清理?

以下代码供您参考。

// Parse the connection string and return a reference to the storage account.
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(storageConnectionString);

// Create the table client.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();

// Retrieve a reference to a container.
var container = blobClient.GetContainerReference("azure-webjobs-hosts");
// Query out all the blobs which created after 30 days
var blobs = container.GetDirectoryReference("output-logs").ListBlobs().OfType<CloudBlob>()
    .Where(b => b.Properties.LastModified < new DateTimeOffset(DateTime.Now.AddDays(-30)));
// Delete these blobs
foreach (var item in blobs)

    item.DeleteIfExists();

【讨论】:

嗨,阿莫尔,感谢您的帮助。是否有任何 AzureFunction 代码示例显示如何进行 blob 清理? 基于这个sameeraman.wordpress.com/2017/08/25/…实现了一个解决方案

以上是关于WebJobs SDK 在 AzureWebJobsDashboard 连接中创建的 blob 的清理机制是啥?的主要内容,如果未能解决你的问题,请参考以下文章

Azure webjob 似乎不尊重 MaxDequeueCount 属性

使用 azure webjobs 我如何为计划任务传递参数

长时间运行的 Azure WebJob 失败 - 客户端无法在指定的超时时间内完成操作

Azure webjobs - Unity - 如何将范围内的依赖项注入其他类

Azure WebJobs ServiceBus 返回异常:在授权上下文中找到 2 个 DNS 声明

Azure WebJobs (3.x) 连续作业未在仪表板中显示函数