Trigger/Terminate Jobs
Trigger a Job
Once your Job has been successfully deployed, it remains in a Suspended
state until you explicitly trigger its execution.
Trigger a Job via User Interface
Once you trigger your job, you'll be directed to the Job Run
tab.
Your job will start getting executed and enter the Running state. At this point, the platform will create and launch the necessary pods to execute the job.
Upon successful completion of your job, the Job Run will transition to the Finished status. Simultaneously, the pods that were created to execute the job will be automatically released, along with the resources they utilized.
Trigger a Job Programmatically
You can also Trigger a Job programmatically either using servicefoundry CLI or Python SDK.
Prerequisites
To trigger Job programmatically, you will need the Application FQN which is the Fully Qualified Name (FQN) of the job you want to run. You can obtain this information from the Job-specific dashboard of the Job you are interested in.
![](https://files.readme.io/d9b35e6-Screenshot_2023-11-16_at_10.12.52_AM.png)
Now you can trigger the Job programmatically using either the Python SDK, or the servicefoundry CLI
from servicefoundry import trigger_job
# Trigger/Run a Job
trigger_job(
application_fqn="<application-fqn>",
command="<Optional Command to Trigger the Job With>" # Overrides command defined in Job Spec
)
sfy trigger job --application-fqn <application-fqn> --command "<Optional command to trigger job with>"
Alternatively, you can also schedule the Job to run at specific intervals using the following guide - Deploy a Cron Job.
View Job Runs
TrueFoundry provides two methods for viewing job runs: through the user interface (UI) or programmatically using either the Python SDK
or the servicefoundry CLI
.
Viewing Job Runs via User Interface
Viewing Job Runs Programmatically
TrueFoundry's Python SDK and servicefoundry (CLI) provide programmatic ways to retrieve job runs. You can use these to list all job runs or view the details of a specific job run.
Prerequisites
To view job runs programmatically, you will need the following information:
-
Application FQN: The Fully Qualified Name (FQN) of the job you want to view job runs for.
-
Job Run Name: The name of the specific job run you want to view.
You can obtain this information from the Job-specific dashboard of the Job you are interested in.
![](https://files.readme.io/9e52a3f-Screenshot_2023-11-15_at_3.10.37_PM.png)
Viewing List of Job Runs Programmatically
Given a Job, there are two ways of seeing its list of job runs programmatically: using the servicefoundry
CLI or the TrueFoundry Python SDK
.
Command-Line Interface (CLI)
servicefoundry list job-run --application-fqn <your-application-fqn>
Python SDK
from servicefoundry import list_job_runs
application_fqn = "<your-application-fqn>"
job_runs = list_job_runs(application_fqn=application_fqn)
print("Number of Job Runs:", len(job_runs))
for run in job_runs:
print(f"Job name: {run.name}, status: {run.status}, command: {run.command}\n")
Viewing a Specific Job Run Programmatically
Just like viewing a list of job runs, there are two ways of extracting a specific job run programmatically: using the servicefoundry
CLI or the TrueFoundry Python SDK
. Apart from the Application FQN
, the Job Run Name
will be used to extract a unique job run.
Command-Line Interface (CLI)
servicefoundry get job-run --application-fqn <your-application-fqn> --job-run-name <your-job-run-name>
Python SDK
from servicefoundry import get_job_run
application_fqn = "<your-application-fqn>"
job_run_name = "<your-job-run-name>"
job_run = get_job_run(application_fqn=application_fqn, job_run_name=job_run_name)
print(f"Job name: {job_run.name}, status: {job_run.status}, command: {job_run.command}")
Terminate Job Runs
TrueFoundry provides two methods for terminating job runs: through the user interface (UI) or programmatically using either the Python SDK
or the servicefoundry CLI
.
Terminate a Job via User Interface
Terminate a Job Programmatically
TrueFoundry's Python SDK and servicefoundry (CLI) provide programmatic ways to terminate job runs.
Prerequisites
To terminate a job run programmatically, you will need the following information:
-
Application FQN: The Fully Qualified Name (FQN) of the job you want to view job runs for.
-
Job Run Name: The name of the specific job run you want to view.
You can obtain this information from the Job-specific dashboard of the Job you are interested in.
![](https://files.readme.io/9e52a3f-Screenshot_2023-11-15_at_3.10.37_PM.png)
Now you can terminate the Job programmatically using either the Python SDK, or the servicefoundry CLI
from servicefoundry import terminate_job_run
terminated_job_run = terminate_job_run(
application_fqn="<your-application-fqn>",
job_run_name="<your-job-run-name>"
)
print(terminated_job_run)
servicefoundry terminate job --application-fqn <your-application-fqn> --job-run-name <your-job-run-name>
Updated 4 months ago