---
title: "Workbench Job Submission"
output: rmarkdown::html_vignette
vignette: >
  %\VignetteIndexEntry{Workbench Job Submission}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r, include = FALSE}
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
```

```{r setup}
library(abba)
```

In support for Workbench, **abba** has several local submission functions to manage interface with local Workbench cluster. At a high level, these functions break down into three different categories:

-   Submit a job
-   Get job status
-   Retrieve the log of the job

Functions specifically for interfacing with Workbench follow the naming convention `abba_rslauncher_*_local`.

## Submit a Job

Job submission is handled by the function `abba_rslauncher_submit_job_local()`. This is the function used to submit a job for a regular execution. To submit program for execution via logrx, `abba_rslauncher_submit_logrx_job_local` can be used.

```{r submit_job, eval=FALSE}
abba_rslauncher_submit_job_local(
  "/home/mike.stackhouse/repos/abba/test_programs/test_program.R",
  log_path = "/home/mike.stackhouse/test_logs"
  )
# [1] "TG9jYWw6bU9YcFMzeEZacVFaa1lLc2pRak1LZz09"
abba_rslauncher_submit_logrx_job_local(
  "/home/mike.stackhouse/repos/abba/test_programs/test_program.R",
  log_path = "/home/mike.stackhouse/test_logs"
  )
# [1] "TG9jYWw6VG5leWVvWFFseEN5M0JRVFptVjVIUT09"
```

Note that this returns a vector with job id and name being path of the program. The Job ID is the identifier used downstream to interact with Workbench.

`log_path` is required and specifies the directory where the program's log file will be written. abba does not fall back to a default location in the user's filespace.

## Get Job Status

Once the job is running in Workbench, **abba** can poll its status. This can be done using the function `abba_rslauncher_get_job_status_local()`

```{r get_status, eval=FALSE}
abba_rslauncher_get_job_status_local("TG9jYWw6bU9YcFMzeEZacVFaa1lLc2pRak1LZz09")
# TG9jYWw6bU9YcFMzeEZacVFaa1lLc2pRak1LZz09 
#                             "Finished" 
```

The job statuses can be "Running", and "Finished"(clarification needed).

# Get the Log Content

In this context, the "log" refers to the stdout/stderr of the program itself. This returns into a list object with the Job ID and the individual lines written out by the program. The content will contain all of the console output from the program itself.

```{r watch_job, eval=FALSE}
abba_rslauncher_get_job_log_local("TG9jYWw6bU9YcFMzeEZacVFaa1lLc2pRak1LZz09")
# [[1]]
# [1] "[1] 4"                   "Warning message:"        "This is a test warning " "La-di-da"                       
```

Alternatively, when using `abba_rslauncher_submit_logrx_job_local()`, the log file will contain the [**logrx**](https://pharmaverse.github.io/logrx/) log output.


```{r get_logrx_log, eval=FALSE}
abba_rslauncher_get_job_log_local("TG9jYWw6VG5leWVvWFFseEN5M0JRVFptVjVIUT09")
# [[1]]
#   [1] "--------------------------------------------------------------------------------"
#   [2] "-                                logrx Metadata                                -"
#   [3] "--------------------------------------------------------------------------------"
#   [4] "This log was generated using logrx 0.3.0"
#   [5] "logrx package version: 0.3.0"
#   [6] "logrx build: RSPM (R 4.2.0)"
#   [7] "logrx link to repository: https://github.com/pharmaverse/logrx"
#   [8] "--------------------------------------------------------------------------------"
#   [9] "-                          User and File Information                           -"
#  [10] "--------------------------------------------------------------------------------"
#  [11] "User: mike.stackhouse"
#  [12] "File Name: test_program.R"
#  [13] "File Path: /home/mike.stackhouse/repos/abba/test_programs"
#  [14] "File HashSum: 1ba9a7fc3cf91e3cce43d38a5bf1d800900f1c92"
#  [15] "--------------------------------------------------------------------------------"
#  [16] "-                             Session Information                              -"
#  [17] "--------------------------------------------------------------------------------"
#  [18] "- Session info ---------------------------------------------------------------"
#  [19] " setting  value"
#  [20] " version  R version 4.2.1 (2022-06-23)"
#  [21] " os       Ubuntu 20.04.6 LTS"
#  [22] " system   x86_64, linux-gnu"
#  [23] " ui       X11"
#  [24] " language (EN)"
#  [25] " collate  C"
#  [26] " ctype    C"
#  [27] " tz       Etc/UTC"
#  [28] " date     2024-03-29"
#  [29] " pandoc   2.5 @ /usr/bin/pandoc"
#  [30] ""
#  [31] "- Packages -------------------------------------------------------------------"
#  [32] " package     * version date (UTC) lib source"
#  [33] " cli           3.6.2   2023-12-11 [1] RSPM (R 4.2.0)"
#  [34] " digest        0.6.34  2024-01-11 [1] RSPM (R 4.2.0)"
#  [35] " dplyr         1.1.4   2023-11-17 [1] RSPM (R 4.2.0)"
#  [36] " ellipsis      0.3.2   2021-04-29 [1] RSPM (R 4.2.0)"
#  [37] " fansi         1.0.6   2023-12-08 [1] RSPM (R 4.2.0)"
#  [38] " fastmap       1.1.1   2023-02-24 [1] RSPM (R 4.2.0)"
#  [39] " generics      0.1.3   2022-07-05 [1] RSPM (R 4.2.0)"
#  [40] " glue          1.7.0   2024-01-09 [1] RSPM (R 4.2.0)"
#  [41] " htmltools     0.5.7   2023-11-03 [1] RSPM (R 4.2.0)"
#  [42] " httpuv        1.6.14  2024-01-26 [1] RSPM (R 4.2.0)"
#  [43] " later         1.3.2   2023-12-06 [1] RSPM (R 4.2.0)"
#  [44] " lifecycle     1.0.4   2023-11-07 [1] RSPM (R 4.2.0)"
#  [45] " logrx       * 0.3.0   2023-10-17 [1] RSPM (R 4.2.0)"
#  [46] " magrittr      2.0.3   2022-03-30 [1] RSPM (R 4.2.0)"
#  [47] " mime          0.12    2021-09-28 [1] RSPM (R 4.2.0)"
#  [48] " miniUI        0.1.1.1 2018-05-18 [1] RSPM (R 4.2.0)"
#  [49] " pillar        1.9.0   2023-03-22 [1] RSPM (R 4.2.0)"
#  [50] " pkgconfig     2.0.3   2019-09-22 [1] RSPM (R 4.2.0)"
#  [51] " promises      1.2.1   2023-08-10 [1] RSPM (R 4.2.0)"
#  [52] " purrr         1.0.2   2023-08-10 [1] RSPM (R 4.2.0)"
#  [53] " R6            2.5.1   2021-08-19 [1] RSPM (R 4.2.0)"
#  [54] " Rcpp          1.0.12  2024-01-09 [1] RSPM (R 4.2.0)"
#  [55] " rlang         1.1.3   2024-01-10 [1] RSPM (R 4.2.0)"
#  [56] " rstudioapi    0.15.0  2023-07-07 [1] RSPM (R 4.2.0)"
#  [57] " sessioninfo   1.2.2   2021-12-06 [1] RSPM (R 4.2.0)"
#  [58] " shiny         1.8.0   2023-11-17 [1] RSPM (R 4.2.0)"
#  [59] " stringi       1.8.3   2023-12-11 [1] RSPM (R 4.2.0)"
#  [60] " stringr       1.5.1   2023-11-14 [1] RSPM (R 4.2.0)"
#  [61] " tibble        3.2.1   2023-03-20 [1] RSPM (R 4.2.0)"
#  [62] " tidyr         1.3.1   2024-01-24 [1] RSPM (R 4.2.0)"
#  [63] " tidyselect    1.2.0   2022-10-10 [1] RSPM (R 4.2.0)"
#  [64] " utf8          1.2.4   2023-10-22 [1] RSPM (R 4.2.0)"
#  [65] " vctrs         0.6.5   2023-12-01 [1] RSPM (R 4.2.0)"
#  [66] " waiter        0.2.5   2022-01-03 [1] RSPM (R 4.2.0)"
#  [67] " xtable        1.8-4   2019-04-21 [1] RSPM (R 4.2.0)"
#  [68] ""
#  [69] " [1] /home/mike.stackhouse/R/x86_64-pc-linux-gnu-library/4.2"
#  [70] " [2] /opt/R/4.2.1/lib/R/library"
#  [71] ""
#  [72] "- External software ----------------------------------------------------------"
#  [73] " setting        value"
#  [74] " cairo          1.16.0"
#  [75] " cairoFT"
#  [76] " pango          1.44.7"
#  [77] " png            1.6.37"
#  [78] " jpeg           8.0"
#  [79] " tiff           LIBTIFF, Version 4.1.0"
#  [80] " tcl            8.6.10"
#  [81] " curl           7.68.0"
#  [82] " zlib           1.2.11"
#  [83] " bzlib          1.0.8, 13-Jul-2019"
#  [84] " xz             5.2.4"
#  [85] " PCRE           10.34 2019-11-21"
#  [86] " ICU            66.1"
#  [87] " TRE            TRE 0.8.0 R_fixes (BSD)"
#  [88] " iconv          glibc 2.31"
#  [89] " readline       8.0"
#  [90] " BLAS           /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0"
#  [91] " lapack         /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0"
#  [92] " lapack_version 3.9.0"
#  [93] ""
#  [94] "- Python configuration -------------------------------------------------------"
#  [95] " Python is not available"
#  [96] ""
#  [97] "------------------------------------------------------------------------------"
#  [98] "--------------------------------------------------------------------------------"
#  [99] "-                               Masked Functions                               -"
# [100] "--------------------------------------------------------------------------------"
# [101] "function `args` from {package:base} by .GlobalEnv"
# [102] "function `plot` from {package:base} by package:graphics"
# [103] "function `body<-` from {package:base} by package:methods"
# [104] "function `kronecker` from {package:base} by package:methods"
# [105] "--------------------------------------------------------------------------------"
# [106] "-                          Used Package and Functions                          -"
# [107] "--------------------------------------------------------------------------------"
# [108] "{package:base} print"
# [109] "{package:base} warning"
# [110] "{package:base} message"
# [111] "--------------------------------------------------------------------------------"
# [112] "-                         Program Run Time Information                         -"
# [113] "--------------------------------------------------------------------------------"
# [114] "Start time: 2024-03-29 18:34:59 UTC"
# [115] "End time: 2024-03-29 18:34:59 UTC"
# [116] "Run time: 0 seconds"
# [117] "--------------------------------------------------------------------------------"
# [118] "-                             Errors and Warnings                              -"
# [119] "--------------------------------------------------------------------------------"
# [120] "Errors:"
# [121] "\t"
# [122] ""
# [123] "Warnings:"
# [124] "\tThis is a test warning"
# [125] "--------------------------------------------------------------------------------"
# [126] "-                         Messages, Output, and Result                         -"
# [127] "--------------------------------------------------------------------------------"
# [128] "Messages:"
# [129] "\tLa-di-da"
# [130] "Output:"
# [131] "\t[1] 4"
# [132] ""
# [133] "Result:"
# [134] "\tNULL"
# [135] "--------------------------------------------------------------------------------"
# [136] "-                               Log Output File                                -"
# [137] "--------------------------------------------------------------------------------"
# [138] "Log name: test_program.log"
# [139] "Log path: /home/mike.stackhouse/repos/abba/test_programs"
```
