bnosac / cronR

A simple R package for managing your cron jobs.
Other
288 stars 38 forks source link

Adding a cron job with frequency set to 'minutely' and defining the 'at' parameter causes the job to run only the first time and not repeat #39

Closed DWecke closed 3 years ago

DWecke commented 3 years ago

My stack overflow question on this issue can be found here https://stackoverflow.com/questions/68012286/cronr-runs-only-once-frequency-set-to-minutely-then-doesnt-run-anymore-after/68076777#68076777

I am currently using cronR version 0.4.2. The documentation when you do ?cron_add shows examples where the 'frequency' and the 'at' arguments are both given variables however I ran into this issue when I tried to do the same. After commenting out the 'at' argument, the script started running every minute as expected.

"Script_to_be_scheduled.R" - Create's and outputs a file:

library(data.table)
library(lubridate)

csv_table <- data.table(bla = sample(1:1000, size = 15) )

filepath <- "~/My-Local-Workspace"
filename <- paste0("automaticTable__", hour(Sys.time()), "_", minute(Sys.time()), "_", round(second(Sys.time())), ".csv")
filepath_full <-  paste0(normalizePath(filepath), "/", filename)

fwrite(csv_table, file = filepath_full  )

filepath_full
[1] "/home/redacted/redacted/My-Local-Workspace/Script_to_be_scheduled.R"

"Scheduler_test.R" - Create's and schedules the cron job to run every minute once a specified time is reached:

library("cronR")
filepath <- "~/My-Local-Workspace"
filename <- "Script_to_be_scheduled.R"
filepath_full <-  paste0(normalizePath(filepath), "/", filename)

commnd <- cron_rscript( filepath_full )

cron_add(command = commnd, 
         frequency = 'minutely', 
         id = 'This is the title', 
         at = '14:56', 
         description = 'My process 1', 
         tags = c('Algorithm_1'))
jwijffels commented 3 years ago

Yeah, it doesn't make sense to use at when frequency is 'minutely'. I probably should remove that from the documentation. If you want to see more in the logs, consider putting options(echo = TRUE)at the top of your Script_to_be_scheduled.R script. There is no such thing in cron which indicates 'once a specified time is reached'. The most relevant use of at is frequency 'dayly' at = '14:56' to run every day at 14h56

jwijffels commented 3 years ago

Where in the documentation you see the usage of frequency = 'minutely' together with the usage of at?

jwijffels commented 3 years ago

Closing as there is no such thing in the documentation