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
= '154bd2af-e8fa-4aa4-aab8-dcef701f4af9'
CONTENT_GUID = 'CwCoI9tizMRRcvLw'
JOB_KEY
= connect.Client()
client = client.content.get(CONTENT_GUID)
content = content.jobs.find(JOB_KEY)
job 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)
<- "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
CONTENT_ITEM_GUID
<- connect()
client <- content_item(client, CONTENT_ITEM_GUID)
item <- terminate_jobs(item) results
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 NA
Alternatively, to terminate only one of the jobs, provide its job key.
<- get_jobs(item)
jobs <- jobs |>
current_jobs filter(status == 0)
<- current_jobs$key[1]
target_key <- terminate_jobs(item, target_key) result
> 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