繁体   English   中英

Azure 在 Azure 存储中批量创建容器文件夹

[英]Azure Batch and Creating Containers Folder in Azure Storage

我有一个 c# 控制台应用程序,它在 Azure 批处理的池中的一个节点上运行。 控制台应用程序写入节点上的 stdout.txt 并在链接到池的批处理帐户的 Azure 存储帐户中创建此文件的副本,这一切正常。

为了实现这一点,我遵循了网页: https://docs.microsoft.com/en-us/azure/batch/batch-task-output-file-conventions

如果我创建并运行一个名为“jobid001”的池作业和一个名为“Task001”的链接任务(该任务运行控制台应用程序),则会创建一个名为“job-jobid001”的容器,看起来像一个名为“Task001”的子文件夹' - 这都是在链接到池批处理帐户的存储帐户下正确创建的,如下所示...

天蓝色批处理作业

下面的 c# 代码在 Az 存储帐户中创建作业容器,并设置要写入(异步)到 Az 存储帐户上匹配文件上的文件的批处理节点上的 stdout.txt 的内容 - 这一切都有效美好的。

   // Parse the connection string and return a reference to the storage account.

                    CloudStorageAccount storageAccount = CloudStorageAccount.Parse(account_url);

                    // Create a folder in Azure for the standard ouput log files to be copied to
                    string containerName = "job-" + _jobId;
                    containerName = containerName.ToLower();

                    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
                    CloudBlobContainer container = blobClient.GetContainerReference(containerName);
                    container.CreateIfNotExists();

                    TaskOutputStorage taskOutputStorage = new TaskOutputStorage(storageAccount, _jobId, _taskId);

                    TimeSpan stdoutFlushDelay = TimeSpan.FromSeconds(3);

                    // The primary task logic is wrapped in a using statement that sends updates to
                    // the stdout.txt blob in Storage every 15 seconds while the task code runs.
                    using (ITrackedSaveOperation stdout =
                            await taskOutputStorage.SaveTrackedAsync(
                            TaskOutputKind.TaskLog,
                            logFilePath,
                            "stdout.txt",
                            TimeSpan.FromSeconds(15)))
                    {

                        // MAIN C# CONSOLE CODE THAT DOES WORK HAS BEEN REMOVED 

                        // We are tracking the disk file to save our standard output, but the
                        // node agent may take up to 3 seconds to flush the stdout stream to
                        // disk. So give the file a moment to catch up.
                        await Task.Delay(stdoutFlushDelay);
                    }

我想要实现的是在根容器“MyAppLogFiles”下模拟 Az 存储帐户中的文件夹结构。 根容器将具有模拟的子文件夹结构:年、月、日,然后是 jobid - 我如何通过增强上面的 c# 代码来实现这一点? (年、月、日等是作业的运行日期时间)

AZ-容器

-> MyAppLogFiles
           ->2020
             ->05
              ->31
                ->job-jobid001
                  ->Task001
                    stdout.txt 

我只是浏览了Microsoft.Azure.Batch.Conventions.Files的源代码(但没有尝试),您可以尝试以下步骤:

1.在您的代码中,将容器名称设置为MyAppLogFiles

2.在这行代码中: TaskOutputStorage taskOutputStorage = new TaskOutputStorage(storageAccount, _jobId, _taskId); ,您可以将这个变量“2020/05/31/job-jobid001/Task001”传递给_taskId。 参考的源代码在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM