Deploy a job with manual trigger

šŸ‘

What you'll learn

  • Deploying our training code as a job via servicefoundry
  • Configure the job to not run immediately once it is deployed.

This is a guide to deploy training code as a job via servicefoundry and configure it to not run immediately once it is deployed.

After you complete the guide, you will have a successful deployed job. Your jobs deployment dashboard will look like this:

Project structure

To complete this guide, you are going to create the following files:

  • train.py : contains our training code
  • requirements.txt : contains our dependencies
  • deploy.py/deploy.yaml: contains our deployment code / deployment configuration. (Depending on whether you choose to use our python SDK or create a YAML file)

Your final file structure is going to look like this:

.
ā”œā”€ā”€ train.py
ā”œā”€ā”€ deploy.py / deploy.yaml
ā””ā”€ā”€ requirements.txt

As you can see, all the following files are created in the same folder/directory

Step 1: Implement the training code

The first step is to create a job that trains a scikit learn model on iris dataset

We start with a train.py containing our training code and requirements.txt with our dependencies.

.
ā”œā”€ā”€ train.py
ā””ā”€ā”€ requirements.txt

train.py

Click on the Open Recipe below to understand the app.py:

requirements.txt

pandas==1.4.4
numpy==1.22.4
scikit-learn==1.1.2

# for deploying our job deployments
servicefoundry>=0.1.97,<0.2.0

Step 2: Deploying as job

You can deploy services on TrueFoundry programmatically either using our Python SDK, or via a YAML file.

So now you can choose between either creating a deploy.py file, which will use our Python SDK.
Or you can choose to create a deploy.yaml configuration file and then use the servicefoundry deploy command

Via python SDK

File Structure

.
ā”œā”€ā”€ train.py
ā”œā”€ā”€ deploy.py
ā””ā”€ā”€ requirements.txt

Follow the recipe below to understand the deploy.py file :

To deploy the job using Python API use:

python deploy.py

Via YAML file

File Structure

.
ā”œā”€ā”€ train.py
ā”œā”€ā”€ deploy.yaml
ā””ā”€ā”€ requirements.txt

Follow the recipe below to understand the deploy.yaml file :-

To deploy the job using Python API use:

servicefoundry deploy --workspace-fqn YOUR_WORKSPACE_FQN --file deploy.yaml

Run the above command from the same directory containing the train.py and requirements.txt files.

šŸ“˜

.tfyignore files

If there are any files you don't want to be copied to the workspace, like a data file, or any redundant files. You can use .tfyignore files in that case.

End result

By default a job will run immediately after deployment. Here we configured the Job to not run immediately once it is deployed.

So now we need to manually trigger it.

Re-Running a Job manually

We can find the link to the Job Details from the Truefoundry dashboard on Deployments page.

26682668

Jobs list

We can re-trigger a job manually by Clicking the Trigger Job button from the Job Details UI.

26542654

Job details

We can now visit our Applications page to check Build status, Build Logs, Runs History and monitor progress of runs.
See Monitoring and Debugging guide for more details.

See Also