crond: Task Scheduler

Description Usage Arguments Examples

View source: R/scheduler.R

Description

Run tasks in a schedule

Usage

1
2
crond(Schedules, TasksInfo, method = "callback",
  handler = "dummy_task_handler", ...)

Arguments

Schedules

An ordered vector with the schedules for each task in shorthand period:offset form

TasksInfo

Ordered Structure with extra information which will be passed to handler

method

Whether a function (callback) or a program should be called

handler

The name of the function which handles the task execution

...

Extra arguments to be passed to the handler

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# Define a handler
my_handler <- function(task_id, timestamp, tasks_info) {
  # Do something with this "task_id" using the information in "tasks_info"
  message("Running ", task_id, " at ", unclass(Sys.time()), " - scheduled: ",
          timestamp, " (", as.POSIXct(timestamp, origin = "1970-01-01") , ")")
}
# Define the tasks info structure
my_tasks  <- data.frame(schedules = c("2s", "1m:3s", "1h:5s"),
                        my_jobs    = c("job01", "job02",  "job03"),
                        other_info = c("...",   "...",     "..."),
                        stringsAsFactors = F)
# create the schedules vector
schedules <- my_tasks$schedules
# Start the scheduler
crond(schedules, my_tasks, "callback", "my_handler")

henfiber/cronr documentation built on May 17, 2019, 3:42 p.m.