Terminating a Job
Problem
You want to terminate a Job associated with your Content.
Solution
This action requires owner, collaborator, or administrator privileges.
Requires posit-sdk>=0.6.0
First, obtain the content object. In this example, we get the content using it’s GUID. Then obtain the job using it’s key. Call the destroy method to request a job termination event. This event is asynchronous and will take a few moments to process.
from posit import connect
CONTENT_GUID = '154bd2af-e8fa-4aa4-aab8-dcef701f4af9'
JOB_KEY = 'CwCoI9tizMRRcvLw'
client = connect.Client()
content = client.content.get(CONTENT_GUID)
job = content.jobs.find(JOB_KEY)
job.destroy()Use the terminate_jobs() function from connectapi to terminate jobs associated with the content item. You will need its GUID. By default, terminate_jobs() terminates all active jobs for a content item. You can optionally pass in one or more job keys to target specific jobs.
- Get content GUID from the Dashboard’s Info tab, or by following Viewing Content Information.
- To find the job key, see Viewing Jobs for Content.
library(connectapi)
CONTENT_ITEM_GUID <- "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
client <- connect()
item <- content_item(client, CONTENT_ITEM_GUID)
results <- terminate_jobs(item)The function returns a data frame with the results of the request.
> results
# A tibble: 2 × 7
app_id app_guid job_key job_id result code error
<int> <chr> <chr> <chr> <chr> <int> <chr>
1 52389 154bd2af-e8fa-4aa4-aab8-dcef701f4af9 WVL7uO4mCwe6g7ZA 40870303 Order to kill job registered NA NA
2 52389 154bd2af-e8fa-4aa4-aab8-dcef701f4af9 OXrb8U6uu1psVGgm 40870302 Order to kill job registered NA NAAlternatively, to terminate only one of the jobs, provide its job key.
jobs <- get_jobs(item)
current_jobs <- jobs |>
filter(status == 0)
target_key <- current_jobs$key[1]
result <- terminate_jobs(item, target_key)> result
# A tibble: 1 × 7
app_id app_guid job_key job_id result code error
<int> <chr> <chr> <chr> <chr> <int> <chr>
1 52389 154bd2af-e8fa-4aa4-aab8-dcef701f4af9 WVL7uO4mCwe6g7ZA 40870303 Order to kill job registered NA NA