
Last chance! 50% off unlimited learning
Sale ends in
# NOT RUN {
# }
# NOT RUN {
# create temporary directory for conf
dir_conf <- paste0(tempdir(), "/conf", round(runif(n = 1, max = 10000)))
dir.create(dir_conf, recursive = TRUE)
# create example of files to be called by the scheduler
# (this fun is called in scheduler_add)
scheduler_init(
dir_scheduler = tempdir(),
dir_conf = dir_conf,
filename = "cron_script.R",
head_rows = NULL
)
read.delim(paste0(tempdir(), "/cron_script.R"), header = FALSE)
scheduler_init(dir_scheduler = tempdir(),
dir_conf = dir_conf,
filename = "cron_script.R",
head_rows = c("My_head_row_1", "My_head_row_2"))
read.delim(paste0(tempdir(), "/cron_script.R"), header = FALSE)
# start a cron
# create confs to check that it works on it
# ex fun
fun_path = system.file("ex_fun/sb_fun_ex.R", package = "shinybatch")
fun_name = "sb_fun_ex"
# create 2 confs
conf_1 <- configure_task(dir_path = dir_conf,
conf_descr = list(
title_1 = "my_title_1",
description_1 = "my_descr_1"
),
fun_path = fun_path,
fun_name = fun_name,
fun_args = list(
x = 0,
y = 0:4,
z = iris
),
priority = 1)
conf_2 <- configure_task(dir_path = dir_conf,
conf_descr = list(
title_2 = "my_title_2",
description_2 = "my_descr_2"
),
fun_path = fun_path,
fun_name = fun_name,
fun_args = list(
x = 1,
y = 0:4,
z = iris
),
priority = 2)
# on LINUX -> Needs cronR package
# on Windows -> Needs taskscheduleR package
scheduler_add(dir_scheduler = tempdir(),
dir_conf,
max_runs = 1,
ignore_status = c("running", "finished", "error"),
delay_reruns = TRUE,
create_file = TRUE,
head_rows = NULL,
taskname = "cron_script_ex")
scheduler_ls() # display existing crons
# wait up to 1 min for conf_2 and up to 2 mins for conf_1
yaml::read_yaml(paste0(conf_1$dir, "/conf.yml"))$run_info$status
yaml::read_yaml(paste0(conf_2$dir, "/conf.yml"))$run_info$status
# check if cron existed
scheduler_exist(taskname = "cron_script_ex")
# kill selected cron
scheduler_remove(taskname = "cron_script_ex")
scheduler_exist(taskname = "cron_script_ex")
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab