Viewing Jobs for Content

Problem

You want to find jobs for a content item, for instance, if you need to use the job key in another recipe.

Solution

Use the content GUID to look up jobs for the content item. Get the GUID from the Dashboard’s Info tab, or by following Viewing Content Information.

from posit import connect

GUID = "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"

client = connect.Client()
response = client.get(f"v1/content/{GUID}/jobs/")
result = response.json()
>>> import polars as pl
>>> pl.DataFrame(result)
shape: (1, 20)
┌──────────┬────────┬────────┬──────────────────┬───┬───────────┬─────────┬───────┬─────────────────┐
id       ┆ ppid   ┆ pid    ┆ key              ┆ … ┆ hostname  ┆ cluster ┆ image ┆ run_as          │
------------              ┆   ┆ ------------
strstrstrstr              ┆   ┆ str       ┆ null    ┆ null  ┆ str
╞══════════╪════════╪════════╪══════════════════╪═══╪═══════════╪═════════╪═══════╪═════════════════╡
32587071900506900522 ┆ zcc5ysQm5fSzTEan ┆ … ┆ example   ┆ null    ┆ null  ┆ posit-connect
└──────────┴────────┴────────┴──────────────────┴───┴───────────┴─────────┴───────┴─────────────────┘
library(connectapi)
library(dplyr)
client <- connect()

GUID <- "154bd2af-e8fa-4aa4-aab8-dcef701f4af9"
item <- content_item(client, GUID)

# The `jobs` API call returns all jobs for a content item, including jobs that
# have finished. We can filter only for currently-running jobs by filtering
# for `finalized == FALSE`.
jobs <- get_jobs(item)
current_jobs <- jobs |>
  filter(finalized == FALSE)
> current_jobs
# A tibble: 2 × 14
        id     pid key              app_id app_guid                             variant_id bundle_id start_time          end_time tag     exit_code finalized hostname  variant_key
     <int>   <int> <chr>             <int> <chr>                                     <int>     <int> <dttm>              <dttm>   <chr>       <int> <lgl>     <chr>     <chr>
1 32593289 1179184 wiSznovdN3IxIliY  21537 154bd2af-e8fa-4aa4-aab8-dcef701f4af9          0    102197 2024-06-20 21:51:33 NA       run_app        NA FALSE     connect01 NA
2 32586170  863024 DZnNuuVtA6apt2Ew  21537 154bd2af-e8fa-4aa4-aab8-dcef701f4af9          0    102197 2024-06-20 14:22:53 NA       run_app        NA FALSE     connect01 NA