WebJobs SDK 在 AzureWebJobsDashboard 连接中创建的 blob 的清理机制是什么?
What is the clean up mechanism for the blobs that WebJobs SDK creates in the AzureWebJobsDashboard connection?
Azure WebJob SDK 使用 AzureWebJobsStorage
和 AzureWebJobsDashboard
应用程序设置中定义的存储连接字符串用于其日志记录和仪表板。
WebJob SDK 在 AzureWebJobsStorage
中创建以下 blob 容器:
azure-webjobs-hosts
WebJob SDK 在 AzureWebJobsDashboard
中创建以下 blob 容器
azure-jobs-host-output
azure-webjobs-hosts
在 WebJob 运行时,在上述 blob 容器中创建了许多 blob。如果没有清理机制,容器可能会膨胀或饱和。
上述 blob 容器的清理机制是什么?
更新
下面的答案是一种解决方法。此时,没有用于清理 WebJobs 日志的内置机制。随着作业的长期运行,日志会堆积得相当大。开发人员必须自己创建清理机制。 Azure Functions 是实现此类清理过程的好方法。下面的答案中提供了一个示例。
What is the clean up mechanism for the blobs that WebJobs SDK creates in the AzureWebJobsDashboard connection?
我还没找到办法。 GitHub 上有一个与此主题相关的未解决问题,但尚未关闭。
No way to set webjob logging retention policy
在 GitHub 的类似问题中,我们发现 Azure WebJob SDK 更改了将日志保存到多个 table 的 Azure Table 存储的方式。我们可以轻松删除每个月的 table。对于在 Azure Blob 存储中写入的日志,直到现在还没有按月分组。
WebJobs.Logging needs to support log purge / retention policies
要删除旧的 WebJob 日志,我建议您创建一个时间触发的 WebJob 来删除您想要的日志。
Is there any AzureFunction code sample shows how to do the blob cleanup?
以下代码供您参考。
// 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();
}
Azure WebJob SDK 使用 AzureWebJobsStorage
和 AzureWebJobsDashboard
应用程序设置中定义的存储连接字符串用于其日志记录和仪表板。
WebJob SDK 在 AzureWebJobsStorage
中创建以下 blob 容器:
azure-webjobs-hosts
WebJob SDK 在 AzureWebJobsDashboard
azure-jobs-host-output
azure-webjobs-hosts
在 WebJob 运行时,在上述 blob 容器中创建了许多 blob。如果没有清理机制,容器可能会膨胀或饱和。
上述 blob 容器的清理机制是什么?
更新
下面的答案是一种解决方法。此时,没有用于清理 WebJobs 日志的内置机制。随着作业的长期运行,日志会堆积得相当大。开发人员必须自己创建清理机制。 Azure Functions 是实现此类清理过程的好方法。下面的答案中提供了一个示例。
What is the clean up mechanism for the blobs that WebJobs SDK creates in the AzureWebJobsDashboard connection?
我还没找到办法。 GitHub 上有一个与此主题相关的未解决问题,但尚未关闭。
No way to set webjob logging retention policy
在 GitHub 的类似问题中,我们发现 Azure WebJob SDK 更改了将日志保存到多个 table 的 Azure Table 存储的方式。我们可以轻松删除每个月的 table。对于在 Azure Blob 存储中写入的日志,直到现在还没有按月分组。
WebJobs.Logging needs to support log purge / retention policies
要删除旧的 WebJob 日志,我建议您创建一个时间触发的 WebJob 来删除您想要的日志。
Is there any AzureFunction code sample shows how to do the blob cleanup?
以下代码供您参考。
// 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();
}