-
Notifications
You must be signed in to change notification settings - Fork 8
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 #165 from ljwoodley/monitor_job_runs
Monitor failed job runs
- Loading branch information
Showing
7 changed files
with
122 additions
and
3 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
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,47 @@ | ||
library(redcapcustodian) | ||
library(dotenv) | ||
library(callr) | ||
library(argparse) | ||
|
||
set_script_run_time() | ||
|
||
parser <- ArgumentParser() | ||
parser$add_argument("script_name", help="Script to be run") | ||
parser$add_argument("optional_args", nargs='*', help="Zero or more optional arguments of any type") | ||
|
||
if (!interactive()) { | ||
args <- parser$parse_args() | ||
} else { | ||
args <- parser$parse_args( | ||
c( | ||
"study_template/etl/test_failure_alert.R", | ||
"test", | ||
"another test" | ||
) | ||
) | ||
} | ||
|
||
script_name <- args$script_name | ||
optional_args <- args$optional_args | ||
|
||
if(!fs::file_exists(script_name)) { | ||
stop(sprintf("Specified file, %s, does not exist", script_name)) | ||
} | ||
|
||
tryCatch({ | ||
if (length(optional_args) == 0) { | ||
rscript(script = script_name, stderr = "log.txt") | ||
} else { | ||
rscript(script = script_name, cmdargs = optional_args, stderr = "log.txt") | ||
} | ||
}, error = function(e) { | ||
email_body <- "See the attached log for error details." | ||
script_path <- paste(basename(getwd()), script_name, sep = "/") | ||
email_subject <- paste0("Failed | ", script_path, " | ", format(get_script_run_time(), "%Y-%m-%d")) | ||
file_name = "log.txt" | ||
|
||
send_email(email_body = email_body, email_subject = email_subject, file_name = file_name) | ||
}) | ||
|
||
|
||
|
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,11 @@ | ||
print("Hello, example host!") | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
# Test that the command line args are read | ||
print(paste0("This is a ", args[1])) | ||
print(paste0("This is ", args[2])) | ||
|
||
# This will fail as test.csv does not exist. | ||
read.csv("test.csv") | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# Test email alert on script failure | ||
0 0 1 * * root /usr/bin/docker run --rm --env-file /rcc/study_template/.env rcc.site Rscript etl/run_etl.R etl/test_failure_alert.R test "another test" | ||
|
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,47 @@ | ||
library(redcapcustodian) | ||
library(dotenv) | ||
library(callr) | ||
library(argparse) | ||
|
||
set_script_run_time() | ||
|
||
parser <- ArgumentParser() | ||
parser$add_argument("script_name", help="Script to be run") | ||
parser$add_argument("optional_args", nargs='*', help="Zero or more optional arguments of any type") | ||
|
||
if (!interactive()) { | ||
args <- parser$parse_args() | ||
} else { | ||
args <- parser$parse_args( | ||
c( | ||
"study_template/etl/test_failure_alert.R", | ||
"test", | ||
"another test" | ||
) | ||
) | ||
} | ||
|
||
script_name <- args$script_name | ||
optional_args <- args$optional_args | ||
|
||
if(!fs::file_exists(script_name)) { | ||
stop(sprintf("Specified file, %s, does not exist", script_name)) | ||
} | ||
|
||
tryCatch({ | ||
if (length(optional_args) == 0) { | ||
rscript(script = script_name, stderr = "log.txt") | ||
} else { | ||
rscript(script = script_name, cmdargs = optional_args, stderr = "log.txt") | ||
} | ||
}, error = function(e) { | ||
email_body <- "See the attached log for error details." | ||
script_path <- paste(basename(getwd()), script_name, sep = "/") | ||
email_subject <- paste0("Failed | ", script_path, " | ", format(get_script_run_time(), "%Y-%m-%d")) | ||
file_name = "log.txt" | ||
|
||
send_email(email_body = email_body, email_subject = email_subject, file_name = file_name) | ||
}) | ||
|
||
|
||
|
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,11 @@ | ||
print("Hello, example host!") | ||
|
||
args <- commandArgs(trailingOnly = TRUE) | ||
|
||
# Test that the command line args are read | ||
print(paste0("This is a ", args[1])) | ||
print(paste0("This is ", args[2])) | ||
|
||
# This will fail as test.csv does not exist. | ||
read.csv("test.csv") | ||
|