@@ -111,7 +111,7 @@ Content <- R6::R6Class(
111111 x
112112 })
113113 }
114- parsed
114+ purrr :: map( parsed , ~ purrr :: list_modify( .x , app_guid = self $ content $ guid ))
115115 },
116116 # ' @description Return a single job for this content.
117117 # ' @param key The job key.
@@ -619,17 +619,34 @@ content_ensure <- function(
619619# ' Note that Connect versions below 2022.10.0 use a legacy endpoint, and will
620620# ' not return the complete set of information provided by newer versions.
621621# '
622+ # ' `get_jobs()` returns job data as a data frame, whereas `get_jobs_list()`
623+ # ' returns job data in a list.
624+ # '
625+ # ' You might get job data as a data frame if you want to perform some
626+ # ' calculations about job data (e.g. counting server processes over time), or if
627+ # ' you want to filter jobs to find a specific key.
628+ # '
629+ # ' The objects in list returned by `get_jobs_list()` are useful if you want to
630+ # ' take an action on a job, such as getting its process log with
631+ # ' `get_log()`.
632+ # '
622633# ' @param content A Content object, as returned by `content_item()`
623634# '
624- # ' @return A data frame with a row for each job, with the following columns:
635+ # ' @return
636+ # '
637+ # ' - `get_jobs()`: A data frame with a row representing each job.
638+ # ' - `get_job_list()`: A list with each element representing a job.
639+ # '
640+ # ' Jobs contain the following fields:
625641# '
626642# ' - `id`: The job identifier.
627643# ' - `ppid`: The job's parent process identifier (see Note 1).
628644# ' - `pid`: The job's process identifier.
629645# ' - `key`: The job's unique key identifier.
630646# ' - `remote_id`: The job's identifier for off-host execution configurations
631647# ' (see Note 1).
632- # ' - `app_id`: The job's parent content identifier
648+ # ' - `app_id`: The job's parent content identifier.
649+ # ' - `app_guid`: The job's parent content GUID.
633650# ' - `variant_id`: The identifier of the variant owning this job.
634651# ' - `bundle_id`: The identifier of a content bundle linked to this job.
635652# ' - `start_time`: The timestamp (RFC3339) indicating when this job started.
@@ -658,10 +675,19 @@ content_ensure <- function(
658675# ' - `run_as`: The UNIX user that executed this job.
659676# '
660677# ' @note
661- # ' 1. On Connect instances earlier than 2022.10.0, these columns will contain `NA` values.
678+ # ' 1. On Connect instances earlier than 2022.10.0, these fields will contain `NA` values.
679+ # '
680+ # ' @examples
681+ # ' \dontrun{
682+ # ' client <- connect()
683+ # ' item <- content_item(client, "951bf3ad-82d0-4bca-bba8-9b27e35c49fa")
684+ # ' jobs <- get_jobs(item)
685+ # ' job_list <- get_job_list(item)
686+ # ' }
662687# '
663688# ' @family job functions
664689# ' @family content functions
690+ # ' @rdname get_jobs
665691# ' @export
666692get_jobs <- function (content ) {
667693 validate_R6_class(content , " Content" )
@@ -682,7 +708,7 @@ get_jobs <- function(content) {
682708# ' @family content functions
683709# ' @export
684710get_job <- function (content , key ) {
685- warn_experimental( " get_job" )
711+ lifecycle :: deprecate_warn( " 0.6 " , " get_job() " , " get_log() " )
686712 scoped_experimental_silence()
687713 validate_R6_class(content , " Content" )
688714
@@ -704,7 +730,7 @@ get_job <- function(content, key) {
704730# ' @param keys Optional. One or more job keys, which can be obtained using
705731# ' `get_jobs(content)`. If no keys are provided, will terminate all active
706732# ' jobs for the provided content item.
707-
733+ # '
708734# ' @return A data frame with the status of each termination request.
709735# '
710736# ' - `app_id`: The content item's identifier.
@@ -718,6 +744,13 @@ get_job <- function(content, key) {
718744# ' Note that `app_id`, `app_guid`, `job_id`, and `result` are `NA` if the
719745# ' request returns an error.
720746# '
747+ # ' @examples
748+ # ' \dontrun{
749+ # ' client <- connect()
750+ # ' item <- content_item(client, "951bf3ad-82d0-4bca-bba8-9b27e35c49fa")
751+ # ' result <- terminate_jobs(item)
752+ # ' }
753+ # '
721754# ' @family job functions
722755# ' @family content functions
723756# ' @export
@@ -747,6 +780,54 @@ terminate_jobs <- function(content, keys = NULL) {
747780 res_df
748781}
749782
783+ # ' @rdname get_jobs
784+ get_job_list <- function (content ) {
785+ validate_R6_class(content , " Content" )
786+
787+ purrr :: map(content $ jobs(), ~ purrr :: list_modify(.x , client = content $ connect ))
788+ }
789+
790+ # ' Get Job Log
791+ # '
792+ # ' Get the log output for a job. Requires Connect 2022.10.0 or newer.
793+ # '
794+ # ' Note: The output of `get_jobs()` cannot be used with `get_log()`.
795+ # ' Please use an object from the list returned by `get_job_list()`.
796+ # '
797+ # ' @param job A job, represented by an element from the list returned by `get_job_list()`.
798+ # ' @param max_log_lines Optional. An integer indicating the maximum number of
799+ # ' log lines to return. If `NULL` (default), Connect returns a maximum of 5000
800+ # ' lines.
801+ # '
802+ # ' @return A data frame with the requested log. Each row represents an entry.
803+ # '
804+ # ' - `source`: `stdout` or `stderr`
805+ # ' - `timestamp`: The time of the entry.
806+ # ' - `data`: The logged text.
807+ # '
808+ # ' @examples
809+ # ' \dontrun{
810+ # ' client <- connect()
811+ # ' item <- content_item(client, "951bf3ad-82d0-4bca-bba8-9b27e35c49fa")
812+ # ' jobs <- get_job_list(item)
813+ # ' log <- get_log(jobs[[1]])
814+ # ' }
815+ # '
816+ # '
817+ # ' @family job functions
818+ # ' @family content functions
819+ # ' @export
820+ get_log <- function (job , max_log_lines = NULL ) {
821+ error_if_less_than(job $ client $ version , " 2022.10.0" )
822+
823+ query <- list (maxLogLines = max_log_lines )
824+ res <- job $ client $ GET(
825+ v1_url(" content" , job $ app_guid , " jobs" , job $ key , " log" ),
826+ query = query
827+ )
828+ parse_connectapi_typed(res $ entries , connectapi_ptypes $ job_log )
829+ }
830+
750831# ' Set RunAs User
751832# '
752833# ' Set the `RunAs` user for a piece of content.
0 commit comments