Merge branch '8784-dir-listings'
[arvados.git] / doc / api / crunch-scripts.html.textile.liquid
1 ---
2 layout: default
3 navsection: api
4 navmenu: Concepts
5 title: Crunch scripts
6
7 ...
8 {% comment %}
9 Copyright (C) The Arvados Authors. All rights reserved.
10
11 SPDX-License-Identifier: CC-BY-SA-3.0
12 {% endcomment %}
13
14 h2. Crunch scripts
15
16 A crunch script is responsible for completing a single JobTask. In doing so, it will:
17
18 * (optionally) read some input from Keep
19 * (optionally) store some output in Keep
20 * (optionally) create some new JobTasks and add them to the current Job
21 * (optionally) update the current JobTask record with the "output" attribute set to a Keep locator or a fragment of a manifest
22 * update the current JobTask record with the "success" attribute set to True
23
24 A task's context is provided in environment variables.
25
26 table(table table-bordered table-condensed).
27 |Environment variable|Description|
28 |@JOB_UUID@|UUID of the current "Job":methods/jobs.html|
29 |@TASK_UUID@|UUID of the current "JobTask":methods/job_tasks.html|
30 |@ARVADOS_API_HOST@|Hostname and port number of API server|
31 |@ARVADOS_API_TOKEN@|Authentication token to use with API calls made by the current task|
32
33 The crunch script typically uses the Python SDK (or another suitable client library / SDK) to connect to the Arvados service and retrieve the rest of the details about the current job and task.
34
35 The Python SDK has some shortcuts for common operations.
36
37 In general, a crunch script can access information about the current job and task like this:
38
39 <pre>
40 import arvados
41 import os
42
43 job = arvados.api().jobs().get(uuid=os.environ['JOB_UUID']).execute()
44 $sys.stderr.write("script_parameters['foo'] == %s"
45                   % job['script_parameters']['foo'])
46
47 task = arvados.api().job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
48 $sys.stderr.write("current task sequence number is %d"
49                   % task['sequence'])
50 </pre>