To demonstrate jobs we will create a new project, populate it with a simple python script, and then start several jobs that run the script.
Let’s start by creating a new directory and initializing a cjr project inside
$ mkdir example-project
$ cd example-project
$ cjr init
Next, let’s set the default stack for the project. You can use the fedora-sc stack from the first tutorial, or if you skipped the first tutorial then you can also use the Docker Hub image fedora:latest.
$ cjr pconfig:set --stack=fedora-sc # to use the fedora-sc image
$ cjr pconfig:set --stack=fedora:latest # to use the fedora:latest
Advanced Users: Any other stack that has python installed will also work.
Create a python script named script.py inside the directory example-project. In this tutorial we will use a simple script that accepts one integer argument N, sleeps for N seconds, and then creates the output file “output-X.txt” where X represents the current unix time. To follow along, copy the following code into script.py.
import time, sys
sleep_sec = int(sys.argv[1])
print("sleeping for " + sys.argv[1] + " seconds.")
time.sleep(sleep_sec)
print("writing output file.")
f = open("output-" + str(int(time.time())) + ".txt", "w")
f.write("Hello World")
f.close()
print("exiting.")