

本文為英文版的機器翻譯版本，如內容有任何歧義或不一致之處，概以英文版為準。

# 從任務取得輸出檔案
<a name="getting-output-files-from-a-job"></a>

此範例顯示 Deadline Cloud 如何識別任務產生的輸出檔案、決定是否將這些檔案上傳至 Amazon S3，以及如何在工作站上取得這些輸出檔案。

 此範例使用 `job_attachments_devguide_output` 任務套件，而非 `job_attachments_devguide`任務套件。首先，從您複製的截止日期雲端範例 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`或 `dataFlow`的任務參數值`INOUT`做為任務的輸出。如果傳遞為此類任務參數值的檔案系統位置重新映射至執行任務的工作者上的本機檔案系統位置，則 Deadline Cloud 會在該位置尋找新檔案，並將這些檔案上傳到 Amazon S3 做為任務輸出。

 若要查看此程序的運作方式，請先在 AWS CloudShell 索引標籤中啟動截止日期雲端工作者代理程式。讓任何先前提交的任務完成執行。然後從日誌目錄中刪除任務日誌：

```
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`識別符。下載此資訊清單檔案，以查看截止日期雲端放置此任務輸出檔案的位置：

```
# 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
```

 您可以使用截止日期雲端監視器或截止日期雲端 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)
```