Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitor failed job runs #165

Merged
merged 6 commits into from
Oct 16, 2024
Merged

Monitor failed job runs #165

merged 6 commits into from
Oct 16, 2024

Conversation

ljwoodley
Copy link
Contributor

@ljwoodley ljwoodley commented Sep 13, 2024

Possible solution to issue #100?

Note, this only sends an email alert with the attached log on job failure. I figured since successful runs are logged in the db we wouldn't need to create a log file for that.

@ljwoodley ljwoodley requested a review from pbchase September 13, 2024 22:09
@ljwoodley ljwoodley changed the title Monitor job runs Monitor failed job runs Sep 13, 2024
Copy link
Contributor

@pbchase pbchase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is super simple and it works. We could use it as-is, but I'd like to see two more features. Could you add these?

  1. Add the ability to pass optional arguments to an etl.
  2. implement the same functionality in the existing render_report.R and its copy in the study_template

etl/run_etl.R Outdated
set_script_run_time()

parser <- ArgumentParser()
parser$add_argument("script_name", nargs=1, help="Script to be run")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you allow for optional parameters? it's quite rare but we do pass an argument to one of out ETLs in the rcc.ctsit repo

etl/run_etl.R Outdated
}

tryCatch({
rscript(script_name, stderr = "log.txt")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

...and then use the arguments here?

@pbchase
Copy link
Contributor

pbchase commented Oct 14, 2024

Here's some example code I wrote to test a different way of specifying the optional arguments to the script called by run_etl.R

library(argparse)

parser <- ArgumentParser()

parser$add_argument("file", nargs = 1, help = "RScript to be run")
parser$add_argument("optional_args", nargs='+', help = "optional arguments to the script to be run")

args <- parser$parse_args()

paste0("The first argument, file, has a value of '", args$file, "'")
paste0("The optional arguments that follow are '", paste(args$optional_args, collapse = " "), "'")

Could you revise run_etl.R to use use this model for optional arguments?

@ljwoodley
Copy link
Contributor Author

Here's some example code I wrote to test a different way of specifying the optional arguments to the script called by run_etl.R

library(argparse)

parser <- ArgumentParser()

parser$add_argument("file", nargs = 1, help = "RScript to be run")
parser$add_argument("optional_args", nargs='+', help = "optional arguments to the script to be run")

args <- parser$parse_args()

paste0("The first argument, file, has a value of '", args$file, "'")
paste0("The optional arguments that follow are '", paste(args$optional_args, collapse = " "), "'")

Could you revise run_etl.R to use use this model for optional arguments?

I don't understand this change?

parser$add_argument("optional_args", nargs='+', help = "optional arguments to the script to be run") does not allow for an optional argumnet as it requires at least one value when the script runs due to nargs='+'.

Rscript etl/run_etl.R etl/test_failure_alert.R fails with this error

Screenshot 2024-10-14 at 5 16 06 PM

Also, Rscript etl/run_etl.R etl/test_failure_alert.R arg1 arg2 is not parsing the arguments properly.

Screenshot 2024-10-14 at 5 17 07 PM

@pbchase

Copy link
Contributor

@pbchase pbchase left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made some suggestions.

We'll make changes to render_report.R later after the rcc.grace PR is finished.

etl/run_etl.R Outdated
Comment on lines 10 to 19
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",
"--optional_args",
"test",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
"--optional_args",
"test",
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",

Comment on lines 1 to 2
# 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 --optional_args test "another test"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# 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 --optional_args test "another test"
# 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"

Comment on lines 10 to 18
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",
"--optional_args",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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",
"--optional_args",
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",

@pbchase pbchase merged commit 71bb032 into ctsit:develop Oct 16, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants