Skip to content

Commit

Permalink
improve worker log
Browse files Browse the repository at this point in the history
  • Loading branch information
Miachol committed Aug 16, 2018
1 parent a45b094 commit d04edd6
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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 = "[email protected]", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2349-208X"))
Maintainer: Jianfeng Li <[email protected]>
Description:
Expand Down
8 changes: 3 additions & 5 deletions inst/extdata/config/shiny/shiny.bioinstaller.parameters.toml
Original file line number Diff line number Diff line change
@@ -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"

Expand Down
4 changes: 1 addition & 3 deletions inst/extdata/config/shiny/shiny.conda.parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 4 additions & 2 deletions inst/extdata/config/shiny/shiny.pubmed.parameters.toml
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 2 additions & 0 deletions inst/extdata/shiny/global_var.R
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
19 changes: 14 additions & 5 deletions inst/extdata/shiny/worker.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -121,24 +129,25 @@ 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)})'
}

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)
Expand All @@ -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")
Expand Down

0 comments on commit d04edd6

Please sign in to comment.