

本文属于机器翻译版本。若本译文内容与英语原文存在差异，则一律以英文原文为准。

# 从作业中获取输出文件
<a name="getting-output-files-from-a-job"></a>

此示例说明了 Deadline Cloud 如何识别您的任务生成的输出文件，决定是否将这些文件上传到 Amazon S3，以及如何在工作站上获取这些输出文件。

 在本示例中，使用`job_attachments_devguide_output`任务捆绑包而不是`job_attachments_devguide`任务捆绑包。首先，从 Deadline Cloud 示例 GitHub存储库的克隆版本中在 AWS CloudShell 环境中制作该包的副本：

```
cp -r deadline-cloud-samples/job_bundles/job_attachments_devguide_output ~/
```

 此任务包和任务捆绑包之间的重要区别在于在作业模板中添加了新的作业参数：`job_attachments_devguide`

```
...
parameterDefinitions:
...
- name: OutputDir
  type: PATH
  objectType: DIRECTORY
  dataFlow: OUT
  default: ./output_dir
  description: This directory contains the output for all steps.
...
```

 参数的`dataFlow`属性具有值`OUT`。Deadline Cloud 使用值为`OUT`或`INOUT`作为`dataFlow`任务输出的任务参数的值。如果将作为值传递给此类任务参数的文件系统位置重新映射到运行任务的工作器上的本地文件系统位置，则 Deadline Cloud 将在该位置查找新文件并将这些文件作为任务输出上传到 Amazon S3。

 要了解此过程的工作原理，请先在 AWS CloudShell 选项卡中启动 Deadline Cloud 工作器代理。让任何先前提交的任务完成运行。然后从日志目录中删除作业日志：

```
rm -rf ~/demoenv-logs/queue-*
```

 接下来，使用此任务包提交作业。工作程序运行 CloudShell完毕后，查看日志：

```
# Change the value of FARM_ID to your farm's identifier
FARM_ID=farm-{{00112233445566778899aabbccddeeff}}
# Change the value of QUEUE1_ID to queue Q1's identifier
QUEUE1_ID=queue-{{00112233445566778899aabbccddeeff}}
# Change the value of WSALL_ID to the identifier of the WSAll storage profile
WSALL_ID=sp-{{00112233445566778899aabbccddeeff}}

deadline config set settings.storage_profile_id $WSALL_ID

deadline bundle submit --farm-id $FARM_ID --queue-id $QUEUE1_ID ./job_attachments_devguide_output
```

 该日志显示文件被检测为输出并上传到 Amazon S3：

```
2024-07-17 02:13:10,873 INFO ----------------------------------------------
2024-07-17 02:13:10,873 INFO Uploading output files to Job Attachments
2024-07-17 02:13:10,873 INFO ----------------------------------------------
2024-07-17 02:13:10,873 INFO Started syncing outputs using Job Attachments
2024-07-17 02:13:10,955 INFO Found 1 file totaling 117.0 B in output directory: /sessions/session-7efa/assetroot-{{3751a}}/output_dir
2024-07-17 02:13:10,956 INFO Uploading output manifest to DeadlineCloud/Manifests/farm-0011/queue-2233/job-4455/step-6677/task-6677-0/2024-07-17T02:13:10.835545Z_sessionaction-8899-1/c6808439dfc59f86763aff5b07b9a76c_output
2024-07-17 02:13:10,988 INFO Uploading 1 output file to S3: {{s3BucketName}}/DeadlineCloud/Data
2024-07-17 02:13:11,011 INFO Uploaded 117.0 B / 117.0 B of 1 file (Transfer rate: 0.0 B/s)
2024-07-17 02:13:11,011 INFO Summary Statistics for file uploads:
Processed 1 file totaling 117.0 B.
Skipped re-processing 0 files totaling 0.0 B.
Total processing time of 0.02281 seconds at 5.13 KB/s.
```

 该日志还显示，Deadline Cloud 在 Amazon S3 存储桶中创建了一个新的清单对象，该对象已配置为供队列中的任务附件使用`Q1`。清单对象的名称源自生成输出的任务的农场、队列、作业、步骤、任务、时间戳和`sessionaction`标识符。下载此清单文件，查看 Deadline Cloud 将此任务的输出文件放置在何处：

```
# The name of queue `Q1`'s job attachments S3 bucket
Q1_S3_BUCKET=$(
  aws deadline get-queue --farm-id $FARM_ID --queue-id $QUEUE1_ID \
    --query 'jobAttachmentSettings.s3BucketName' | tr -d '"'
)

# Fill this in with the object name from your log
OBJECT_KEY="{{DeadlineCloud/Manifests/...}}"

aws s3 cp --quiet s3://$Q1_S3_BUCKET/$OBJECT_KEY /dev/stdout | jq .
```

 清单看起来像：

```
{
  "hashAlg": "xxh128",
  "manifestVersion": "2023-03-03",
  "paths": [
    {
      "hash": "34178940e1ef9956db8ea7f7c97ed842",
      "mtime": 1721182390859777,
      "path": "output_dir/output.txt",
      "size": 117
    }
  ],
  "totalSize": 117
}
```

 这表明输出文件内容保存到 Amazon S3 的方法与保存任务输入文件的方法相同。与输入文件类似，输出文件存储在 S3 中，其对象名称包含文件的哈希值和前缀`DeadlineCloud/Data`。

```
$ aws s3 ls --recursive s3://$Q1_S3_BUCKET | grep 34178940e1ef9956db8ea7f7c97ed842
2024-07-17 02:13:11        117 DeadlineCloud/Data/34178940e1ef9956db8ea7f7c97ed842.xxh128
```

 您可以使用 Deadline Cloud 监视器或 Deadline Cloud CLI 将作业的输出下载到您的工作站：

```
deadline job download-output --farm-id $FARM_ID --queue-id $QUEUE1_ID --job-id $JOB_ID
```

 提交的`OutputDir`作业中作业参数的值为`./output_dir`，因此输出将下载到作业包目录`output_dir`中名为的目录中。如果您将绝对路径或其他相对位置指定为的值`OutputDir`，则输出文件将改为下载到该位置。

```
$ deadline job download-output --farm-id $FARM_ID --queue-id $QUEUE1_ID --job-id $JOB_ID
Downloading output from Job 'Job Attachments Explorer: Output'

Summary of files to download:
    /home/cloudshell-user/job_attachments_devguide_output/output_dir/output.txt (1 file)

You are about to download files which may come from multiple root directories. Here are a list of the current root directories:
[0] /home/cloudshell-user/job_attachments_devguide_output
> Please enter the index of root directory to edit, y to proceed without changes, or n to cancel the download (0, y, n) [y]: 

Downloading Outputs  [####################################]  100%
Download Summary:
    Downloaded 1 files totaling 117.0 B.
    Total download time of 0.14189 seconds at 824.0 B/s.
    Download locations (total file counts):
        /home/cloudshell-user/job_attachments_devguide_output (1 file)
```