简体   繁体   English

Azure 批处理任务依赖:从以前复制文件

[英]Azure batch task dependencies: copy files from previous

I have a Azure Batch scenario where I have a chain of Tasks which are run after each other.我有一个 Azure 批处理场景,其中我有一个任务链,它们依次运行。 Dependencies are set correctly so they run nicely after each other.依赖关系设置正确,因此它们彼此运行良好。

However I need to copy all files from the previous Task's folder to the new Task's folder before execution.但是,我需要在执行之前将所有文件从以前的任务文件夹复制到新任务的文件夹中。 I do not know in advance how many and what files there will be so I just want to copy everything.我事先不知道会有多少文件和什么文件,所以我只想复制所有内容。 I could not find a way to accomplish this with the Batch client library ( https://docs.microsoft.com/en-us/dotnet/api/overview/azure/batch?view=azure-dotnet ).我找不到使用 Batch 客户端库 ( https://docs.microsoft.com/en-us/dotnet/api/overview/azure/batch?view=azure-dotnet ) 完成此任务的方法。

As a workaround I tried adding a simple copy task to the.bat file which is executed with commandline but for some reason it only copies some of the files.作为一种解决方法,我尝试向使用commandline执行的 .bat 文件添加一个简单的复制任务,但由于某种原因,它只复制了一些文件。 In one task there are a few hundred files to copy and it varies a few % how big portion it copies before it stops copying (with no errors).在一项任务中,有几百个文件要复制,并且在停止复制之前它复制了多少部分(没有错误)会有所不同。 This is my copy command: $"cmd /c xcopy /E /F /Y %AZ_BATCH_TASK_WORKING_DIR%\\..\\..\\{previousTaskId}\\wd %AZ_BATCH_TASK_WORKING_DIR%" .这是我的复制命令: $"cmd /c xcopy /E /F /Y %AZ_BATCH_TASK_WORKING_DIR%\\..\\..\\{previousTaskId}\\wd %AZ_BATCH_TASK_WORKING_DIR%" Everything works correctly if performed directly from the VM.如果直接从 VM 执行,一切都会正常工作。

Tested hypothesis:检验假设:

  • Copying overwrites the.bat file which executes the actual processing.复制会覆盖执行实际处理的 .bat 文件。 This in turn breaks the copying.这反过来又破坏了复制。 I've now ruled out this problem (each task has a differently named.bat file)我现在已经排除了这个问题(每个任务都有一个不同的named.bat文件)
  • Copying is done for some reason in parallel.由于某种原因,复制是并行完成的。 I added timestamp echos to the bats and there is no parallelism so this can't be the reason.我向蝙蝠添加了时间戳回声,并且没有并行性,所以这不是原因。 Also tried adding sleep 10 before the xcopy but didn't make any difference.还尝试在 xcopy 之前添加sleep 10 ,但没有任何区别。
  • xcopy wouldn't see all the files for some reason. xcopy 出于某种原因看不到所有文件。 Added a dir command to see what files there are and it sees only the same files which xcopy copies.添加了一个dir命令来查看有哪些文件,它只看到 xcopy 复制的相同文件。
  • user access issues.用户访问问题。 Doesn't make sense as some files are copied succesfully and there are no errors.没有意义,因为某些文件已成功复制并且没有错误。

Any ideas?有任何想法吗? This sounds like a trivial scenario but I just couldn't figure out how to do this.这听起来像一个微不足道的场景,但我就是不知道如何做到这一点。

What do you have configured as your retentionTime for your tasks?您为任务配置了哪些retentionTime时间?

I'm wondering if Batch is cleaning up the previous task (removing all the files) at the same time as your downstream task is trying to copy them.我想知道 Batch 是否在您的下游任务试图复制它们的同时清理上一个任务(删除所有文件)。

An untested suggestion...一个未经测试的建议...

... assuming you have tasks A & B that run in that order (enforced using Task Dependencies). ...假设您有按该顺序运行的任务 A 和 B(使用任务依赖项强制执行)。

... configure outputFile on task A to copy all of the files generated by A into your storage account. ...在任务 A 上配置outputFile以将A生成的所有文件复制到您的存储帐户中。 Use wildcards so that all the files are copied into the same container.使用通配符,以便将所有文件复制到同一个容器中。

... configure resourceFile on task B to copy all the files from your storage account into the task working directory. ...在任务 B 上配置resourceFile以将存储帐户中的所有文件复制到任务工作目录中。

This has the advantage of preserving your intermediate working files off the compute node - allowing you to pick up where you left off if/when something interrupts your workload.这具有将您的中间工作文件保留在计算节点之外的优势 - 如果/当某些事情中断您的工作负载时,您可以从中断的地方继续。

It turned out that the problem was in the previous Task: it launched a process which started generating the files in the background and returned control immediately.原来问题出在上一个任务中:它启动了一个进程,该进程开始在后台生成文件并立即返回控制权。 Therefore the Batch engine thought the Task had finished and continued to the next Task which was first copying the files generated by the previous Task.因此批处理引擎认为任务已经完成并继续下一个任务,该任务首先复制前一个任务生成的文件。

My hypothesis about parallelism was therefore partially true although it wasn't visible with echoing timestamps (first Task said it finished before second Task said it started).因此,我关于并行性的假设部分正确,尽管它在回显时间戳中不可见(第一个任务说它在第二个任务说它开始之前完成)。 The experiment with sleep would've revealed the problem but I either used too short sleep delay or somehow read the results wrong. sleep实验会发现问题,但我要么使用了太短的睡眠延迟,要么以某种方式读错了结果。

Because I can't control how the first Task launches the process I now added some Windows Batch script to poll tasklist about when the process ends and it solved the problem.因为我无法控制第一个任务如何启动进程,所以我现在添加了一些tasklist批处理脚本来轮询任务列表,了解进程何时结束并解决了问题。

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

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