Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


shinybatch (version 0.3)

scheduler_init: Scheduler management of the launcher function

Description

Scheduler management of the launcher function

Usage

scheduler_init(
  dir_scheduler,
  dir_conf,
  max_runs = 1,
  ignore_status = c("running", "finished", "error"),
  delay_reruns = TRUE,
  filename = paste0("sb_", format(Sys.time(), format = "%Y%m%d"), ".R"),
  head_rows = NULL
)

scheduler_add( dir_scheduler, dir_conf, max_runs = 1, ignore_status = c("running", "finished", "error"), delay_reruns = TRUE, taskname = paste0("sb_", format(Sys.time(), format = "%Y%m%d")), filename = paste0(taskname, ".R"), create_file = TRUE, head_rows = NULL, ... )

scheduler_remove(taskname, ...)

scheduler_exist(taskname)

scheduler_ls(...)

Arguments

dir_scheduler

character. Where to create R scheduler script.

dir_conf

character. launcher arg : where to find the tasks directories.

max_runs

integer (1). launcher arg : maximum number of simultaneous running tasks.

ignore_status

character (c("running", "finished", "error")). launcher arg : status to be ignored when launching tasks.

delay_reruns

boolean (TRUE). When "running", "finished" or "error" are not in ignore_status, use the date of the last run instead of the date of creation of the task to compute the order of (re)run for these tasks. The priority still applies.

filename

character a character string with the name of the rscript file.

head_rows

character (NULL). Custom head rows to replace the default ones.

taskname

character a character string with the name of the task. (id in Linux cronR, taskname in windows taskscheduleR)

create_file

boolean (TRUE). Whether or not to also create the R scheduler script with scheduler_init ?

...

. Additional arguments passed to cronR::cron_add, cronR::cron_rm, cronR::cron_ls (Linux) or taskscheduleR::taskscheduler_create (Windows).

Value

NULL.

Details

Without any frequency argument, default is set to every minute

Examples

Run this code
# 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