copyright | lastupdated | keywords | subcollection | ||
---|---|---|---|---|---|
|
2021-09-16 |
jobs in code engine, batch jobs in code engine, running jobs with code engine, creating jobs with code engine, images for jobs in code engine, jobs, job run, environment variables |
codeengine |
{:DomainName: data-hd-keyref="APPDomain"} {:DomainName: data-hd-keyref="DomainName"} {:android: data-hd-operatingsystem="android"} {:api: .ph data-hd-interface='api'} {:apikey: data-credential-placeholder='apikey'} {:app_key: data-hd-keyref="app_key"} {:app_name: data-hd-keyref="app_name"} {:app_secret: data-hd-keyref="app_secret"} {:app_url: data-hd-keyref="app_url"} {:audio: .audio} {:authenticated-content: .authenticated-content} {:beta: .beta} {:c#: .ph data-hd-programlang='c#'} {:c#: data-hd-programlang="c#"} {:cli: .ph data-hd-interface='cli'} {:codeblock: .codeblock} {:curl: #curl .ph data-hd-programlang='curl'} {:curl: .ph data-hd-programlang='curl'} {:deprecated: .deprecated} {:dotnet-standard: .ph data-hd-programlang='dotnet-standard'} {:download: .download} {:external: .external target="_blank"} {:external: target="_blank" .external} {:faq: data-hd-content-type='faq'} {:fuzzybunny: .ph data-hd-programlang='fuzzybunny'} {:generic: data-hd-operatingsystem="generic"} {:generic: data-hd-programlang="generic"} {:gif: data-image-type='gif'} {:go: .ph data-hd-programlang='go'} {:help: data-hd-content-type='help'} {:hide-dashboard: .hide-dashboard} {:hide-in-docs: .hide-in-docs} {:important: .important} {:ios: data-hd-operatingsystem="ios"} {:java: #java .ph data-hd-programlang='java'} {:java: .ph data-hd-programlang='java'} {:java: data-hd-programlang="java"} {:javascript: .ph data-hd-programlang='javascript'} {:javascript: data-hd-programlang="javascript"} {:middle: .ph data-hd-position='middle'} {:navgroup: .navgroup} {:new_window: target="_blank"} {:node: .ph data-hd-programlang='node'} {:note: .note} {:objectc: .ph data-hd-programlang='Objective C'} {:objectc: data-hd-programlang="objectc"} {:org_name: data-hd-keyref="org_name"} {:php: .ph data-hd-programlang='PHP'} {:php: data-hd-programlang="php"} {:pre: .pre} {:preview: .preview} {:python: .ph data-hd-programlang='python'} {:python: data-hd-programlang="python"} {:release-note: data-hd-content-type='release-note'} {:right: .ph data-hd-position='right'} {:route: data-hd-keyref="route"} {:row-headers: .row-headers} {:ruby: .ph data-hd-programlang='ruby'} {:ruby: data-hd-programlang="ruby"} {:runtime: architecture="runtime"} {:runtimeIcon: .runtimeIcon} {:runtimeIconList: .runtimeIconList} {:runtimeLink: .runtimeLink} {:runtimeTitle: .runtimeTitle} {:screen: .screen} {:script: data-hd-video='script'} {:service: architecture="service"} {:service_instance_name: data-hd-keyref="service_instance_name"} {:service_name: data-hd-keyref="service_name"} {:shortdesc: .shortdesc} {:space_name: data-hd-keyref="space_name"} {:step: data-tutorial-type='step'} {:step: data-tutorial-type='step'} {:subsection: outputclass="subsection"} {:support: data-reuse='support'} {:swift: #swift .ph data-hd-programlang='swift'} {:swift: .ph data-hd-programlang='swift'} {:swift: data-hd-programlang="swift"} {:table: .aria-labeledby="caption"} {:term: .term} {:terraform: .ph data-hd-interface='terraform'} {:tip: .tip} {:tooling-url: data-tooling-url-placeholder='tooling-url'} {:topicgroup: .topicgroup} {:troubleshoot: data-hd-content-type='troubleshoot'} {:tsCauses: .tsCauses} {:tsResolve: .tsResolve} {:tsSymptoms: .tsSymptoms} {:tutorial: data-hd-content-type='tutorial'} {:ui: .ph data-hd-interface='ui'} {:unity: .ph data-hd-programlang='unity'} {:url: data-credential-placeholder='url'} {:user_ID: data-hd-keyref="user_ID"} {:vbnet: .ph data-hd-programlang='vb.net'} {:video: .video}
{: #run-job}
After you create your job, you can run a job based on its definition, or you can run the job with overriding properties. Run your job from the console or with the CLI. {: shortdesc}
Job runs that are created by subscriptions are deleted after 10 minutes. For more information about subscriptions, see Getting started with subscriptions. {: note}
Each time your job runs, the most current version of your referenced container image is downloaded and run. Submitted batch jobs are run in parallel, if possible. If the number or size of the submitted jobs exceeds the configured quota limits, such as maximum number of running instances, then {{site.data.keyword.codeengineshort}} queues the jobs and delays running them until enough jobs finish. For more information about quotas and limits for jobs, including memory and CPU, see Limits and quotas for {{site.data.keyword.codeengineshort}}. {: note}
{: #run-job-ui}
When you create a job, you can run it immediately. However, you can submit and resubmit a job at any time. You can also submit or resubmit a job that you previously created.
- Open the {{site.data.keyword.codeengineshort}}{: external} console.
- Select Projects from the navigation menu.
- Select a project as the current context.
- From the Overview page, select Jobs from the Summary section or select Jobs from the navigation menu.
- Click the name of your job to open the configuration.
- Click Submit job to open the Submit job dialog. Review and optionally change default configuration values such as instances, CPU, memory, number of job retries, and job timeout. For more information about these options, see Options for creating and running a job.
- Click Submit job to run your job. The system displays the status of the instances of your job on the job details page.
- If any of the instances of your job failed to run, click Rerun failed indices to run the job again for indices that failed. From the Submit job pane, review and optionally change the configuration values. The Array indices field automatically lists the indices of the failed job run instances. After you review and and optionally change configuration values, click Submit job to run your job.
You can view job logs after you add logging capabilities. For more information, see viewing logs. {: tip}
The JOB_INDEX
environment variable is automatically injected into each instance of your job whenever the job is run. For more information about environment variables that are set by {{site.data.keyword.codeengineshort}}, see Inside {{site.data.keyword.codeengineshort}}: Automatically injecting environment variables.
{: note}
{: #run-job-cli}
Before you begin
- Set up your {{site.data.keyword.codeengineshort}} environment.
- Create a job.
To run a job with the CLI, use the jobrun submit
command. For a complete listing of options, see the ibmcloud ce jobrun submit
command.
With the CLI, you can run a job based on a job configuration or you can run a job without first creating a job configuration.
{: #run-job-cli-withjobconfig}
By creating a job configuration, you can more easily run your job multiple times.
For example, the following jobrun submit
command creates five new instances to run the container image that is specified in the defined myjob
job configuration. To reference a defined job configuration, use the --job
option. While the --name
option is not required if the --job
option is specified, the following example command specifies the --name
option to provide a name for this job run. For jobs, the default value for cpu
is 1
and the default value for memory
is 4G
. The resource limits and requests are applied per instance, so each instance gets 4 G memory and 1 vCPU. This job allocates 5 * 4 G = 20 G memory and 5 * 1 vCPU = 5 vCPUs.
ibmcloud ce jobrun submit --name testjobrun --job myjob --array-indices "1 - 5"
{: pre}
The following table summarizes the options that are used with the jobrun submit
command in this example. For more information about the command and its options, see the ibmcloud ce jobrun submit
command.
jobrun submit
command components
The JOB_INDEX
environment variable is automatically injected into each instance of your job whenever the job is run. For more information about environment variables that are set by {{site.data.keyword.codeengineshort}}, see Inside {{site.data.keyword.codeengineshort}}: Automatically injecting environment variables.
{: note}
{: #run-job-cli-withoutjobconfig}
With the CLI, you can submit a job run without first creating a job configuration. You can specify the same configuration options on the jobrun submit
and jobrun resubmit
commands that are available with the job create
command.
For example, the following ibmcloud ce jobrun submit
command submits a job run to reference the us.icr.io/mynamespace/myhello_bld
image by using the myregistry
access information. Because this job run is not referencing a defined job configuration, you must specify values for the --name
and image
options. Use --name
to specify the name of this job run and use --image
to provide the name of the image that is used for this job run. The --array-indices
option creates five new instances to run the container image. For job runs, the default value for cpu
is 1
and the default value for memory
is 4G
. The resource limits and requests are applied per instance, so each instance gets 4 G memory and 1 vCPU. This job run allocates 5 * 4 G = 20 G memory and 5 * 1 vCPU = 5 vCPUs.
ibmcloud ce jobrun submit --name myhellojob-jobruna --image us.icr.io/mynamespace/myhello_bld --registry-secret myregistry --array-indices "1 - 5"
{: pre}
Run the jobrun get -n myhellojob-jobruna
command to check the job run status.
Example output
[...]
Name: myhellojob-jobruna
ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f
Project Name: myproject
Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111
Age: 3m6s
Created: 2021-06-04T11:56:22-04:00
Image: us.icr.io/mynamespace/myhello_bld
Resource Allocation:
CPU: 1
Ephemeral Storage: 400M
Memory: 4G
Registry Secrets:
myregistry
Runtime:
Array Indices: 1 - 5
Max Execution Time: 7200
Retry Limit: 3
Status:
Completed: 9s
Instance Statuses:
Succeeded: 5
Conditions:
Type Status Last Probe Last Transition
Pending True 16s 16s
Running True 13s 13s
Complete True 9s 9s
Events:
Type Reason Age Source Messages
Normal Updated 11s (x8 over 18s) batch-job-controller Updated JobRun "myhellojob-jobruna"
Normal Completed 11s batch-job-controller JobRun completed successfully
Instances:
Name Running Status Restarts Age
myhellojob-jobruna-1-0 0/1 Succeeded 0 18s
myhellojob-jobruna-2-0 0/1 Succeeded 0 18s
myhellojob-jobruna-3-0 0/1 Succeeded 0 18s
myhellojob-jobruna-4-0 0/1 Succeeded 0 18s
myhellojob-jobruna-5-0 0/1 Succeeded 0 18s
{: screen}
Job runs that are submitted (or resubmitted) with the CLI that do not reference a defined job configuration are not viewable from the console. {: note}
{: #resubmit-job-cli}
If you want to resubmit a job run based the configuration of a previous job run, use the jobrun resubmit
command. This command requires the name of the previous job run and also allows other optional arguments. For a complete listing of options, see the ibmcloud ce jobrun resubmit
command.
{: shortdesc}
For example, the following jobrun resubmit
command resubmits the testjobrun
job run.
ibmcloud ce jobrun resubmit --jobrun testjobrun
{: pre}
Example output
Getting job run 'testjobrun'...
Getting job 'myjob'...
Rerunning job run 'myjob-jobrun-fji48'...
Run 'ibmcloud ce jobrun get -n myjob-jobrun-fji48' to check the job run status.
{: screen}
For example, the following jobrun resubmit
command resubmits the myhellojob-jobruna
job run, which was run without first creating the job configuration. Because the referenced job run does not have a related job configuration, you must specify the --name
option to specify a name this job run.
ibmcloud ce jobrun resubmit --jobrun myhellojob-jobruna --name myhellojob-jobrunb
{: pre}
Run the jobrun get -n myhellojob-jobrunb
command to check the job run status.
Example output
Getting jobrun 'myhellojob-jobrunb'...
[...]
Name: myhellojob-jobrunb
ID: abcdefgh-abcd-abcd-abcd-1a2b3c4d5e6f
Project Name: myproject
Project ID: 01234567-abcd-abcd-abcd-abcdabcd1111
Age: 3m6s
Created: 2021-06-04T11:56:22-04:00
Image: us.icr.io/mynamespace/myhello_bld
Resource Allocation:
CPU: 1
Ephemeral Storage: 400M
Memory: 4G
Registry Secrets:
myregistry
Runtime:
Array Indices: 1 - 5
Max Execution Time: 7200
Retry Limit: 3
Status:
Completed: 91s
Instance Statuses:
Succeeded: 5
Conditions:
Type Status Last Probe Last Transition
Pending True 96s 96s
Running True 92s 92s
Complete True 91s 91s
Events:
Type Reason Age Source Messages
Normal Updated 93s (x7 over 97s) batch-job-controller Updated JobRun "myhellojob-jobrunb"
Normal Completed 93s batch-job-controller JobRun completed successfully
Instances:
Name Running Status Restarts Age
myhellojob-jobrunb-1-0 0/1 Succeeded 0 97s
myhellojob-jobrunb-2-0 0/1 Succeeded 0 97s
myhellojob-jobrunb-3-0 0/1 Succeeded 0 97s
myhellojob-jobrunb-4-0 0/1 Succeeded 0 97s
myhellojob-jobrunb-5-0 0/1 Succeeded 0 97s
{: screen}
Job runs that are submitted (or resubmitted) with the CLI that do not reference a defined job configuration are not viewable from the console. {: note}