8784: Fix test for latest firefox.
[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
9 h2. Crunch scripts
10
11 A crunch script is responsible for completing a single JobTask. In doing so, it will:
12
13 * (optionally) read some input from Keep
14 * (optionally) store some output in Keep
15 * (optionally) create some new JobTasks and add them to the current Job
16 * (optionally) update the current JobTask record with the "output" attribute set to a Keep locator or a fragment of a manifest
17 * update the current JobTask record with the "success" attribute set to True
18
19 A task's context is provided in environment variables.
20
21 table(table table-bordered table-condensed).
22 |Environment variable|Description|
23 |@JOB_UUID@|UUID of the current "Job":methods/jobs.html|
24 |@TASK_UUID@|UUID of the current "JobTask":methods/job_tasks.html|
25 |@ARVADOS_API_HOST@|Hostname and port number of API server|
26 |@ARVADOS_API_TOKEN@|Authentication token to use with API calls made by the current task|
27
28 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.
29
30 The Python SDK has some shortcuts for common operations.
31
32 In general, a crunch script can access information about the current job and task like this:
33
34 <pre>
35 import arvados
36 import os
37
38 job = arvados.api().jobs().get(uuid=os.environ['JOB_UUID']).execute()
39 $sys.stderr.write("script_parameters['foo'] == %s"
40                   % job['script_parameters']['foo'])
41
42 task = arvados.api().job_tasks().get(uuid=os.environ['TASK_UUID']).execute()
43 $sys.stderr.write("current task sequence number is %d"
44                   % task['sequence'])
45 </pre>