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

All*_* Xu 5 azure azure-webjobs azure-webjobssdk

Azure的WebJob SDK使用在定义的存储连接字符串AzureWebJobsStorage,并AzureWebJobsDashboard为它的记录和仪表板应用程序设置.

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

  • azure-webjobs-hosts

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

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

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

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

更新

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

Amo*_*mor 7

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

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

无法设置 webjob 日志记录保留策略

在 GitHub 上的一个类似问题中,我们发现 Azure WebJob SDK 更改了将日志保存到 Azure 表存储的多表的方式。我们可以轻松地每月删除该表。对于在 Azure Blob 存储中写入的日志,直到现在还没有按月分组。

在此处输入图片说明

WebJobs.Logging 需要支持日志清除/保留策略

要删除旧的 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();
}
Run Code Online (Sandbox Code Playgroud)