bnosac / taskscheduleR

Schedule R scripts/processes with the Windows task scheduler.
331 stars 72 forks source link

Scheduling daily jobs #12

Closed martinkmetko closed 8 years ago

martinkmetko commented 8 years ago

I want to schedule daily jobs, but with code:

taskscheduler_create(taskname = "import_digitale_to_bigquery",
                     rscript = "C:/R/TaskScheduler/digitale_bigquery_import.R",
                     schedule = "DAILY",
                     starttime = format(Sys.time() + 120, "%H:%M"),
                     startdate = format(Sys.Date(), "%d/%m/%Y"))

I get error:

Warning message:
running command 'schtasks /Create /TN "import_digitale_to_bigquery" /TR "cmd /c C:/PROGRA~1/R/R-33~1.1/bin/Rscript.exe C:/R/TaskScheduler/digitale_bigquery_import.R  >> C:/R/TaskScheduler/digitale_bigquery_import.log 2>&1" /SC DAILY /ST 16:57 /SD "30/06/2016" ' had status 16389 

How should I alter the code or settings to get the job done? One-time jobs work fine

Thanks

jwijffels commented 8 years ago

what are your system settings (language e.g.), did you already create a job with that same taskname, in which case, you might need to remove it first with taskscheduler_delete('import_digitale_to_bigquery') ? what does taskscheduler_ls give you?

martinkmetko commented 8 years ago

taskscheduler_ls gives ~ 100 tasks, mostly created by Microsoft. None of them in folder where taskscheduleR files are stored. System locale according to R is: "LC_COLLATE=Slovak_Slovakia.1250;LC_CTYPE=Slovak_Slovakia.1250;LC_MONETARY=Slovak_Slovakia.1250;LC_NUMERIC=C;LC_TIME=Slovak_Slovakia.1250"

jwijffels commented 8 years ago

Can you report what this gives and also if you tried using the rstudio add-in and select daily

x <- taskscheduler_ls()
str(x)
grep("bigquery", x$TaskName, value=TRUE)

It might also be that you have to use different formatting of the date instead of %d/%m/%Y screenshot

This is at my computer

taskscheduler_create(rscript = "C:/Users/Jan/Desktop/helloworld.R", schedule = "DAILY", days = "*", starttime = "11:30", startdate = format(Sys.Date(), "%d/%m/%Y"), debug = TRUE)
Creating task schedule: schtasks /Create /TN "helloworld.R" /TR "cmd /c C:/PROGRA~1/R/R-33~1.0/bin/Rscript.exe C:/Users/Jan/Desktop/helloworld.R  >> C:/Users/Jan/Desktop/helloworld.log 2>&1" /SC DAILY /ST 11:30 /SD "01/07/2016" 
[1] "SUCCESS: The scheduled task \"helloworld.R\" has successfully been created."

subset(taskscheduler_ls(), TaskName == "helloworld.R")
  HostName     TaskName     Next Run Time Status       Logon Mode     Last Run Time Last Result Author
4   BNOSAC helloworld.R 2-7-2016 11:30:00  Ready Interactive only 1-7-2016 11:30:00           1    Jan
                                                                                                                   Task To Run
4 cmd /c C:/PROGRA~1/R/R-33~1.0/bin/Rscript.exe C:/Users/Jan/Desktop/helloworld.R  >> C:/Users/Jan/Desktop/helloworld.log 2>&1
  Start In Comment Scheduled Task State Idle Time                            Power Management Run As User
4      N/A     N/A              Enabled  Disabled Stop On Battery Mode, No Start On Batteries BNOSAC\\Jan
  Delete Task If Not Rescheduled Stop Task If Runs X Hours and X Mins                                         Schedule Schedule Type
4                       Disabled                             72:00:00 Scheduling data is not available in this format.        Daily 
  Start Time Start Date End Date           Days Months Repeat: Every Repeat: Until: Time Repeat: Until: Duration
4   11:30:00   1-7-2016      N/A Every 1 day(s)    N/A      Disabled            Disabled                Disabled
  Repeat: Stop If Still Running
4                      Disabled
jstabach commented 8 years ago

When I try to run a daily command, I get an error stating: [1] "ERROR: Incorrect Start Date." attr(,"status") [1] 16389

For instance:

library(taskscheduleR) myscript <- system.file("extdata", "helloworld.R", package = "taskscheduleR")

run script every day at 09:10. Change the format of startdate to your locale if needed (e.g. US: %m/%d/%Y)

taskscheduler_create(taskname = "myfancyscriptdaily", rscript = myscript,

  • schedule = "DAILY", starttime = "09:10", startdate = format(Sys.Date(), "%d/%m/%Y")) [1] "ERROR: Incorrect Start Date." attr(,"status") [1] 16389

My system is Windows 7, 64-bit.

Scheduling it once (schedule = “ONCE”, starttime = format(Sys.time() + 62, “%H:%M”)) works without a problem. Any help greatly appreciated.

Thanks.

jwijffels commented 8 years ago

Can you try with other startdate formats, like

"%d/%m/%Y" "%m/%d/%Y" "%Y/%m/%d" "%Y/%d/%m"

"%d-%m-%Y" "%m-%d-%Y" "%Y-%m-%d" "%Y-%d-%m"

jstabach commented 8 years ago

Took some playing around, but this worked:

library(taskscheduleR) myscript <- system.file("extdata", "helloworld.R", package = "taskscheduleR") taskscheduler_create(taskname = "Tester", rscript = myscript, schedule="DAILY", startdate = format(as.Date("2016-08-20"), "%m/%d/%Y"),starttime = "23:59")

[1] "SUCCESS: The scheduled task \"Tester\" has successfully been created."

Without as.Date, I continued to receive the invalid 'trim' argument.

Thanks for your help!

tatosilvestre96 commented 4 years ago

I need to schedule a daily jobs with the following characteristics, must run every 1 hour between 8 am and 6 pm, only on Monday, Tuesday, Wednesday, Thursday and Friday.

How should the code be?

THANKS