Documentation

Chaining together tasks with jobs

import qarnot

# Connect to Qarnot
conn = qarnot.connection.Connection(client_token="<<<MY_SECRET_TOKEN>>>")

# Create and submit a job
job = conn.create_job('Hello World - job', useDependencies=True)
job.submit()

# Create a write task associated to the job
# This task will write Hello World in a .txt file
write_task = conn.create_task('Hello World - Write', 'docker-batch', 1, job=job)
write_task.constants['DOCKER_CMD'] = 'sh -c "echo Hello World ! > output.txt"'

# Create an output bucket for the write task
write_task_output = conn.create_bucket('write-output')
write_task.results = write_task_output

# Create a read task associated to the job
# This task will read the contents of output.txt and print it
read_task = conn.create_task('Hello World - Read', 'docker-batch', 1, job=job)
read_task.constants['DOCKER_CMD'] = 'cat output.txt'

# Use the write task's output bucket as an input
read_task.resources.append(write_task_output)

# Submit the write task 
write_task.submit()

# Submit the read task as being dependant of the write task
read_task.set_task_dependencies_from_tasks([write_task])
read_task.submit()

Any feedback on this page ?

© Qarnot Computing