From d04edd63e62fdf4ca263dee187b821965c17e184 Mon Sep 17 00:00:00 2001 From: Jianfeng Date: Thu, 16 Aug 2018 17:56:56 +0800 Subject: [PATCH] improve worker log --- DESCRIPTION | 2 +- .../shiny/shiny.bioinstaller.parameters.toml | 8 +++----- .../config/shiny/shiny.conda.parameters.toml | 4 +--- .../config/shiny/shiny.pubmed.parameters.toml | 6 ++++-- inst/extdata/shiny/global_var.R | 2 ++ inst/extdata/shiny/worker.R | 19 ++++++++++++++----- 6 files changed, 25 insertions(+), 16 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 73a30eb..e6a51e8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: BioInstaller Title: Integrator of Bioinformatics Resources -Version: 0.3.5.5000 +Version: 0.3.5.6000 Authors@R: person("Jianfeng", "Li", email = "lee_jianfeng@sjtu.edu.cn", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2349-208X")) Maintainer: Jianfeng Li Description: diff --git a/inst/extdata/config/shiny/shiny.bioinstaller.parameters.toml b/inst/extdata/config/shiny/shiny.bioinstaller.parameters.toml index 6f991ea..3f8d7c4 100644 --- a/inst/extdata/config/shiny/shiny.bioinstaller.parameters.toml +++ b/inst/extdata/config/shiny/shiny.bioinstaller.parameters.toml @@ -1,16 +1,14 @@ [bioinstaller.ui.sections] order = ["bioinstaller_input_box", "bioinstaller_output_table", "bioinstaller_output_text"] [bioinstaller.ui.sections.ui_basic] -bioinstaller_input_box = "title = 'Input', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" -bioinstaller_output_text = "title = 'Output of bioinstaller', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" +bioinstaller_input_box = "title = 'BioInstaller query', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" +bioinstaller_output_text = "title = 'Output of bioinstaller (Text)', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" bioinstaller_output_table = "title = 'Output of bioinstaller (Table)', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" [bioinstaller.paramters.bioinstaller_input_box] # For reading annovarR shiny APP bioinstaller tool input files section_type = "input" -rcmd_last = """ - -""" +rcmd_last = "" progressbar_message = "Running BioInstaller functions." render_id = "bioinstaller_input_box" diff --git a/inst/extdata/config/shiny/shiny.conda.parameters.toml b/inst/extdata/config/shiny/shiny.conda.parameters.toml index 91e78c3..fbcf2a3 100644 --- a/inst/extdata/config/shiny/shiny.conda.parameters.toml +++ b/inst/extdata/config/shiny/shiny.conda.parameters.toml @@ -8,9 +8,7 @@ conda_output_box_table = "title = 'Output of conda (Table)', status = 'primary', [conda.paramters.conda_input_box] # For reading annovarR shiny APP conda tool input files section_type = "input" -rcmd_last = """ - -""" +rcmd_last = "" progressbar_message = "Running conda functions." render_id = "conda_input_box" diff --git a/inst/extdata/config/shiny/shiny.pubmed.parameters.toml b/inst/extdata/config/shiny/shiny.pubmed.parameters.toml index 95aba17..2dafcdf 100644 --- a/inst/extdata/config/shiny/shiny.pubmed.parameters.toml +++ b/inst/extdata/config/shiny/shiny.pubmed.parameters.toml @@ -1,7 +1,7 @@ [pubmed.ui.sections] order = ["pubmed_input_box", "pubmed_output_table"] [pubmed.ui.sections.ui_basic] -pubmed_input_box = "title = 'Input', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" +pubmed_input_box = "title = 'Input (Pubmed)', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" pubmed_output_table = "title = 'Output of pubmed (Table)', status = 'primary', width = 12, collapsed = FALSE, collapsible = TRUE" [pubmed.paramters.pubmed_input_box] @@ -80,7 +80,9 @@ if (!is.null(objs) && (max_n_items >= 500)){ title.tmp <- unlist(title.tmp) pmid.tmp <- unlist(pmid.tmp) res <- suppressWarnings(rentrez::parse_pubmed_xml(fetch.pubmed.tmp)) - doi.tmp <- unlist(lapply(res, function(x) {if (length(x$doi) == 0) return(NA); x$doi})) + if (length(res[[1]]) == 1 && length(res$doi) == 0) {doi.tmp <- NA} + else if (length(res[[1]]) == 1 && length(res$doi) != 0) {doi.tmp <- res$doi} + else { doi.tmp <- unlist(lapply(res, function(x) {if (length(x$doi) == 0) return(NA); x$doi})) } result <- cbind(pmid.tmp, doi.tmp, title.tmp, abstracts.tmp, publish.year.tmp, journal.name.tmp, book.name.tmp) } colnames(result) <- c("PMID", "DOI", "Title", "Abstract", "PublishDate", "JournalName", "BookName") diff --git a/inst/extdata/shiny/global_var.R b/inst/extdata/shiny/global_var.R index 5c77e3f..8b2f219 100644 --- a/inst/extdata/shiny/global_var.R +++ b/inst/extdata/shiny/global_var.R @@ -436,6 +436,8 @@ get_tabItem_ui <- function(tabitem = "instant") { get_bioinstaller_installed <- function() { items_db <- Sys.getenv('BIO_SOFTWARES_DB_ACTIVE') + if (!file.exists(items_db) || file.size (items_db) == 0 || + configr::get.config.type (items_db) == FALSE) return(data.frame()) x <- configr::read.config(items_db) if (is.list(x)) {item_name <- names(x);x <- data.table::rbindlist(x)} else {return(data.frame())} return(cbind(item_name, x)) diff --git a/inst/extdata/shiny/worker.R b/inst/extdata/shiny/worker.R index c4c5ca1..6125077 100644 --- a/inst/extdata/shiny/worker.R +++ b/inst/extdata/shiny/worker.R @@ -97,6 +97,14 @@ while (TRUE) { params[[item]] <- NULL } log_file <- sprintf("%s/%s.log", log_dir, qqkey) + log_con <- file(log_file) + sink(log_con, append = TRUE) + sink(log_con, append = TRUE, type = "message") + cat(sprintf("@@Task start at:@@ %s\n", format(Sys.time(), "%Y-%m-%d %H:%M:%S"))) + cat(sprintf("@@Worker nodename:@@ %s\n", Sys.info()[["nodename"]])) + cat(sprintf("@@Worker user:@@ %s\n", Sys.getenv("USER"))) + cat(sprintf("@@Worker locale:@@ %s\n", Sys.getlocale())) + cat(sprintf("@@Worker PID:@@ %s\n", Sys.getpid())) con <- DBI::dbConnect(RSQLite::SQLite(), db_path) need.initial <- nrow(DBI::dbGetQuery(con, sprintf("SELECT * FROM %s WHERE key = \"%s\"", task_table, qqkey))) == 0 @@ -121,9 +129,6 @@ while (TRUE) { if (tolower(qqcommand_type) == "r") { cat(sprintf("%s Running R command for key %s ", format(Sys.time(), "%Y %m-%d %X"), qqkey)) - log_con <- file(log_file) - sink(log_con, append = TRUE) - sink(log_con, append = TRUE, type = "message") worker_do_env <- new.env() if (is.null(req_pkgs) | req_pkgs == "") {cmd <- ""} else { cmd <- 'sapply(req_pkgs, function(x){require(x, character.only = TRUE)})' @@ -131,14 +136,18 @@ while (TRUE) { if (qqcommand != "") { status <- tryCatch({ + cat(sprintf("@@CMD:@@ %s\n", cmd)) eval(parse(text = cmd), envir = worker_do_env) + cat(sprintf("@@CMD:@@ %s\n", qqcommand)) + cat("@@Params:@@\n") + print(params) do.call(eval(parse(text = qqcommand), envir = worker_do_env), params, envir = worker_do_env)}, error = function(e) { message(e$message) FALSE }) - cat(status) + if (is.character(status) || is.numeric(status)) {cat(status)} else {print(status)} } else { status <- tryCatch({ eval(parse(text = cmd), envir = worker_do_env) @@ -152,7 +161,7 @@ while (TRUE) { eval(parse(text = last_cmd[[x]]), envir = worker_do_env) }) }, error = function(e) {message(e$message)}) - cat(status) + if (is.character(status) || is.numeric(status)) {cat(status)} else {print(status)} } sink() sink(type = "message")