-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from A2-ai/cancel_job
added ability to cancel a running job
- Loading branch information
Showing
10 changed files
with
126 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
Package: slurmtools | ||
Title: slurm tooling | ||
Version: 0.0.0.9001 | ||
Version: 0.0.0.9002 | ||
Authors@R: c(person("Devin", "Pastoor", , "[email protected]", role = c("aut", "cre")), | ||
person("Jenna", "Elwing", email = "[email protected]", role = "aut"), | ||
person("Matthew", "Smith", email = "[email protected]", role = "aut")) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#' Cancels a running job | ||
#' | ||
#' @param job_id job id to cancel | ||
#' @param user optional if not the current user. | ||
#' @importFrom rlang .data | ||
#' @importFrom rlang .env | ||
#' | ||
#' @export | ||
#' | ||
#' @examples \dontrun{ | ||
#' cancel_job(243) | ||
#' } | ||
cancel_job <- function(job_id, user = NULL) { | ||
|
||
current_user = Sys.getenv("USER") %||% Sys.info()['user'] | ||
|
||
if (!is.null(user) && user != current_user) { | ||
cat("The supplied user does not match the current user.\n") | ||
cat(paste0("\tsupplied user: ", user, "\n\tcurrent_user: ", current_user, "\n")) | ||
cat("You might be cancelling someone elses job.") | ||
continue <- readline("Are you sure you want to cancel this job? (Y/n)\n") | ||
if (continue == "Y") { | ||
current_user <- user | ||
} else if (tolower(continue) == "n") { | ||
stop(paste0("Not cancelling job: ", job_id)) | ||
} else { | ||
stop("Please enter Y or n") | ||
} | ||
} | ||
|
||
jobs <- get_slurm_jobs(user = current_user) | ||
|
||
if (!job_id %in% jobs$job_id) { | ||
stop("Please ensure the job id is correct.") | ||
} | ||
|
||
job_id_filtered <- jobs %>% dplyr::filter(.data$job_id == .env$job_id) | ||
print(job_id_filtered) | ||
if (job_id_filtered$job_state != "RUNNING") { | ||
stop(paste0("Job: ", job_id, " is not running")) | ||
} | ||
|
||
result <- processx::run("scancel", args = c(as.character(job_id))) | ||
if (result$status != 0) { | ||
print(paste0("Stdout: ", result$stdout)) | ||
print(paste0("Stderr: ", result$stderr)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters