Skip to content

Create a Job

You create a job via a manifest that defines the job’s behavior. You can add an askanna.yml file to your project code. In the askanna.yml file you can specify a job. After specifying the job, you can push/upload your code to AskAnna and AskAnna will create the job.

Job definition

An example of a job definition:

name of the job:
  job:
    - pip install -r requirements.txt
    - python train_your_model.py --input_file {{ PAYLOAD_PATH }}
  output:
    result: models/model_summary.json
    artifact:
      - models/

name of the job (required)
The job definition starts with the name of the job. You cannot use the following names as a job name:

  • push-target
  • environment
  • cluster
  • image
  • worker
  • variables

job (required)
Here you list the commands that you want to execute in the run. In the above example, the first command executed is installing the requirements. If that command finished successful, we will also run a second command that triggers a Python script.

output
In the output you can define which files you want to store. There are two options:

  1. result
  2. artifact

In result you can refer to a single file that contains the result of the run. For example, a JSON file with the summary of a train job or predictions.

In artifact you can list directories or files that you want to save as artifact of the run.

Use variables

In the job run definition, you can also use variables. In the job example above the {{ PAYLOAD_PATH }} is a variable. A variable can be used as a parameter in the job run manifest and is also available as environment variables in the run environment. Variables are created on different levels:

Note

Currently, the behavior of using variables as parameters in the job run definition is not consequent. In most cases you can refer to a variable via {{ VARIABLE_NAME }} and sometimes you need to use ${VARIABLE_NAME}. In case the first doesn’t work, please try the second variant. In the future we will uniform the solution.

AskAnna variables

AskAnna variables are always available in every job. The list of AskAnna variables:

Name Description
AA_TOKEN Token used to trigger the job
JOBRUN_SUUID The unique identifier for the job run
JOBRUN_JOBNAME The name of the job
PROJECT_SUUID The unique identifier for the project
PACKAGE_SUUID The unique identifier for the code package used
PAYLOAD_SUUID The unique identifier for the payload file
PAYLOAD_PATH The path of the payload file

PAYLOAD_PATH

When you run a job, it’s possible to send a JSON data body. This JSON file is made available in the job run environment. The location of the payload file is available via the variable PAYLOAD_PATH. This variable is also set as an environment variable for the run environment.

Project variables

Project variables are variables defined on project level. On the project page you can find the section variables. Here you can manage variables. The project variables are available via the name you defined and for both the job definition, as also as environment variables in the run environment.

For more information check the variables documentation.

Payload variables

There are two use cases for adding a JSON body to a request. The first is adding data that can be used in the run. For example, a JSON body with the most recent sales data. Another use case is that the JSON body contains variables that can be used in the job run.

AskAnna scans the first 10,000 characters of the JSON body. Every key will become a variable name, and every value the value of that variable. In case the Payload variable and Project variable has the same name, AskAnna will use the value of the Payload variable.

Example of a JSON body:

{
  "FROM_DATE": "2020-09-07",
  "UNTIL_DATE": "2020-09-11",
  "TRAINED_MODEL_ID": "k68o-Mi2L-mYte-7E54"
}

In the job run definition you can use these JSON keys as variables:

name of the job:
  job:
    - askanna artifact get --id {{ TRAINED_MODEL_ID }} --output "models/"
    - pip install -r requirements.txt
    - python your_model.py --from_date {{ FROM_DATE }} --until_date {{ UNTIL_DATE }}

In the above example, we use Payload variables to define which trained model and period we want to use to run the model. With this setup you can easily switch between models and periods.