For schedule = "ONCE" wrong date gets selected
hannes101 opened this issue · 10 comments
Hi,
I was struggling to create tasks, which should run once on particular dates. I initially thought this is caused by different locale settings and wrong formatting of the the dates, I provide for the startdate option of taskscheduler_create
.
I think that this is caused by the fact, that in case of "ONCE" the startdate is never set and defaults to Sys.Date().
I think the code should be changed from
if (!schedule %in% c("ONCE", "ONLOGON", "ONIDLE")) {
cmd <- sprintf("%s /SD %s", cmd, shQuote(startdate))
}
to
if (schedule %in% c("ONCE", "ONLOGON", "ONIDLE")) {
cmd <- sprintf("%s /SD %s", cmd, shQuote(startdate))
}
Because otherwise the addition of the date is never added to the cmd, or?
> sessionInfo()
R version 4.0.2 (2020-06-22)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)
Matrix products: default
locale:
[1] LC_COLLATE=German_Germany.1252 LC_CTYPE=German_Germany.1252 LC_MONETARY=German_Germany.1252 LC_NUMERIC=C
[5] LC_TIME=German_Germany.1252
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] timeDate_3043.102 bizdays_1.0.6 utf8_1.2.2 vroom_1.3.2 forcats_0.5.0 purrr_0.3.4 readr_1.4.0 tidyr_1.1.4
[9] tibble_3.1.6 ggplot2_3.3.5 tidyverse_1.3.0 taskscheduleR_1.4 stringr_1.4.0 stringi_1.7.6 digest_0.6.29 odbc_1.3.3
[17] lubridate_1.8.0 ibmdbR_1.50.0 arules_1.6-6 Matrix_1.4-0 RODBC_1.3-17 dbplyr_1.4.4 dplyr_1.0.7 DBI_1.1.1
[25] data.table_1.14.0 bbkutils_1.0.2
loaded via a namespace (and not attached):
[1] Rcpp_1.0.8 rpart.plot_3.0.9 lattice_0.20-45 assertthat_0.2.1 R6_2.5.0 cellranger_1.1.0 backports_1.4.1 reprex_0.3.0 httr_1.4.2
[10] pillar_1.6.5 rlang_0.4.12 readxl_1.3.1 rstudioapi_0.13 blob_1.2.1 rpart_4.1-15 bit_4.0.4 munsell_0.5.0 broom_0.7.11
[19] compiler_4.0.2 modelr_0.1.8 pkgconfig_2.0.3 tidyselect_1.1.1 fansi_1.0.2 crayon_1.4.2 withr_2.4.2 MASS_7.3-55 grid_4.0.2
[28] jsonlite_1.8.0 gtable_0.3.0 lifecycle_1.0.1 magrittr_2.0.1 scales_1.1.1 writexl_1.3.1 zip_2.2.0 cli_3.1.1 fs_1.5.0
[37] xml2_1.3.3 ellipsis_0.3.2 generics_0.1.0 vctrs_0.3.8 openxlsx_4.2.4 tools_4.0.2 bit64_4.0.5 glue_1.6.0 hms_1.1.0
[46] parallel_4.0.2 colorspace_2.0-0 rvest_0.3.6 haven_2.4.1
You mean this part of the code? https://github.com/bnosac/taskscheduleR/blob/master/R/taskscheduleR.R#L163
Can you test if you replace
if(!schedule %in% c('ONCE', 'ONLOGON', 'ONIDLE')){
with
if(!schedule %in% c('ONLOGON', 'ONIDLE')){
if this works according to what you need.
Yes, that seems to work as expected. It's a bit tricky to keep track of all if-conditions :-)
how did you test this already
I just use a custom function based on taskscheduler_create
and thus I can quickly adapt the function, reload it and test the changes locally.
Can you test it on a real example as in schedule today, run tomorrow
That actually happened over night, I created a task and it was already executed with the changes to the function proposed by you.
I'm more in favor of adding something like this:
if(!schedule %in% c('ONLOGON', 'ONIDLE')){
if(missing(startdate)) then run immediately
else use the startdate
}
I don't really have a preference for any solution, but yours looks more safe. Thanks
I've made the changes, feel free to test out further.
Thanks a lot for the quick fix!