Skip to content

Commit

Permalink
add jobGetState / jobList (#144)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Feb 9, 2024
1 parent dcfb782 commit 8b0e9ac
Show file tree
Hide file tree
Showing 12 changed files with 183 additions and 74 deletions.
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ export(isWorkbenchJob)
export(jobAdd)
export(jobAddOutput)
export(jobAddProgress)
export(jobGetState)
export(jobList)
export(jobRemove)
export(jobRunScript)
export(jobSetProgress)
Expand Down
88 changes: 44 additions & 44 deletions R/jobs.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

#' Add a Job
#'
#' Inform RStudio's Background Jobs pane that a job has been added.
Expand Down Expand Up @@ -32,11 +33,9 @@
#' \item{replay}{If there is an action named \code{replay}, then the job will
#' have a Replay button that displays when the job has finished running. Clicking
#' the button will invoke the \code{replay} action.}}
#' @seealso Other jobs: \code{\link{jobAddOutput}()},
#' \code{\link{jobAddProgress}()}, \code{\link{jobRemove}()},
#' \code{\link{jobRunScript}()}, \code{\link{jobSetProgress}()},
#' \code{\link{jobSetState}()}, \code{\link{jobSetStatus}()}
#' @export jobAdd
#'
#' @family jobs
#' @export
jobAdd <- function(name, status = "", progressUnits = 0L, actions = NULL, running = FALSE,
autoRemove = TRUE, show = TRUE) {
callFun("addJob", name = name,
Expand All @@ -54,13 +53,10 @@ jobAdd <- function(name, status = "", progressUnits = 0L, actions = NULL, runnin
#'
#' Remove a background job from RStudio's Background Jobs pane.
#'
#'
#' @param job The ID of the job to remove.
#' @seealso Other jobs: \code{\link{jobAddOutput}()},
#' \code{\link{jobAddProgress}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRunScript}()}, \code{\link{jobSetProgress}()},
#' \code{\link{jobSetState}()}, \code{\link{jobSetStatus}()}
#' @export jobRemove
#'
#' @family jobs
#' @export
jobRemove <- function(job) {
callFun("removeJob", job = job)
}
Expand All @@ -71,14 +67,11 @@ jobRemove <- function(job) {
#'
#' Updates the progress for a background job.
#'
#'
#' @param job The ID of the job to set progress for.
#' @param units The integer number of total units of work completed so far.
#' @seealso Other jobs: \code{\link{jobAddOutput}()},
#' \code{\link{jobAddProgress}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRemove}()}, \code{\link{jobRunScript}()},
#' \code{\link{jobSetState}()}, \code{\link{jobSetStatus}()}
#' @export jobSetProgress
#'
#' @family jobs
#' @export
jobSetProgress <- function(job, units) {
callFun("setJobProgress", job = job, units = units)
}
Expand All @@ -92,11 +85,9 @@ jobSetProgress <- function(job, units) {
#'
#' @param job The ID of the job to update progress for.
#' @param units The integer number of new progress units completed.
#' @seealso Other jobs: \code{\link{jobAddOutput}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRemove}()}, \code{\link{jobRunScript}()},
#' \code{\link{jobSetProgress}()}, \code{\link{jobSetState}()},
#' \code{\link{jobSetStatus}()}
#' @export jobAddProgress
#'
#' @family jobs
#' @export
jobAddProgress <- function(job, units) {
callFun("addJobProgress", job = job, units = units)
}
Expand All @@ -110,17 +101,22 @@ jobAddProgress <- function(job, units) {
#'
#' @param job The ID of the job to update.
#' @param status Text describing job's new status.
#' @seealso Other jobs: \code{\link{jobAddOutput}()},
#' \code{\link{jobAddProgress}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRemove}()}, \code{\link{jobRunScript}()},
#' \code{\link{jobSetProgress}()}, \code{\link{jobSetState}()}
#' @export jobSetStatus
#'
#' @family jobs
#' @export
jobSetStatus <- function(job, status) {
callFun("setJobStatus", job = job, status = status)
}



#' Get Background Job State
#'
#' @param job The ID of the job.
#'
#' @family jobs
#' @export
jobGetState <- function(job) {
callFun("getJobState", job = job)
}

#' Set Background Job State
#'
Expand All @@ -135,11 +131,9 @@ jobSetStatus <- function(job, status) {
#' waiting to run.} \item{running}{The job is actively running.}
#' \item{succeeded}{The job has finished successfully.} \item{cancelled}{The
#' job was cancelled.} \item{failed}{The job finished but did not succeed.} }
#' @seealso Other jobs: \code{\link{jobAddOutput}()},
#' \code{\link{jobAddProgress}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRemove}()}, \code{\link{jobRunScript}()},
#' \code{\link{jobSetProgress}()}, \code{\link{jobSetStatus}()}
#' @export jobSetState
#'
#' @family jobs
#' @export
jobSetState <- function(job, state = c("idle", "running", "succeeded", "cancelled", "failed")) {
callFun("setJobState", job = job, state = state)
}
Expand All @@ -155,11 +149,9 @@ jobSetState <- function(job, state = c("idle", "running", "succeeded", "cancelle
#' @param job The ID of the job that has emitted text.
#' @param output The text output emitted by the job.
#' @param error Whether the output represents an error.
#' @seealso Other jobs: \code{\link{jobAddProgress}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRemove}()}, \code{\link{jobRunScript}()},
#' \code{\link{jobSetProgress}()}, \code{\link{jobSetState}()},
#' \code{\link{jobSetStatus}()}
#' @export jobAddOutput
#'
#' @family jobs
#' @export
jobAddOutput <- function(job, output, error = FALSE) {
callFun("addJobOutput", job = job, output = output, error = error)
}
Expand All @@ -183,11 +175,9 @@ jobAddOutput <- function(job, output, error = FALSE) {
#' objects created by the job. Use \code{""} (the default) to skip export,
#' \code{"R_GlobalEnv"}` to export to the global environment, or the name of an
#' environment object to create an object with that name.
#' @seealso Other jobs: \code{\link{jobAddOutput}()},
#' \code{\link{jobAddProgress}()}, \code{\link{jobAdd}()},
#' \code{\link{jobRemove}()}, \code{\link{jobSetProgress}()},
#' \code{\link{jobSetState}()}, \code{\link{jobSetStatus}()}
#' @export jobRunScript
#'
#' @family jobs
#' @export
jobRunScript <- function(path, name = NULL, encoding = "unknown", workingDir = NULL,
importEnv = FALSE, exportEnv = "") {
path <- normalizePath(path, winslash = "/", mustWork = TRUE)
Expand All @@ -198,3 +188,13 @@ jobRunScript <- function(path, name = NULL, encoding = "unknown", workingDir = N
importEnv = importEnv,
exportEnv = exportEnv)
}

#' List Background Jobs
#'
#' List any registered background jobs.
#'
#' @family jobs
#' @export
jobList <- function() {
callFun("listJobs")
}
15 changes: 11 additions & 4 deletions man/jobAdd.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/jobAddOutput.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions man/jobAddProgress.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions man/jobGetState.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions man/jobList.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions man/jobRemove.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions man/jobRunScript.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions man/jobSetProgress.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions man/jobSetState.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 11 additions & 4 deletions man/jobSetStatus.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8b0e9ac

Please sign in to comment.