bnosac / taskscheduleR

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

Unable to create "DAILY" or "WEEKLY" tasks #84

Closed WindexChugger closed 3 years ago

WindexChugger commented 3 years ago

Hello,

I've been trying to setup a task to run Monday through Friday at a specific time, but have not been successful. I have tried using both the add-in as well as R code (see below). With the add-in UI, I am able to run the script "ONCE", but when I switch to "DAILY" with the "days = ..." argument, the script doesn't run. To confirm: I am deleting the "ONCE" task before attempting to create the "DAILY" task, and I am ensuring that the date format matches my region. I have also confirmed that "file.exists(rscript)" returns TRUE.

I do not get any errors when running this script and am told that the task was scheduled; it just doesn't run.

Thanks!

taskname <- 'testscript.R'
rscript <- 'C:/Users/User1/Documents/R/_Projects/testscript.R'
schedule = 'DAILY'
days = c('MON','TUE','WED','THU','FRI')
starttime = format(Sys.time()+62,"%H:%M")
startdate = format(Sys.Date(),"%m/%d/%Y")

taskscheduler_delete(taskname=taskname)

taskscheduler_create(taskname=taskname,
                     rscript=rscript,
                     schedule=schedule,
                     starttime=starttime,
                     startdate=startdate,
                     days=days)
jwijffels commented 3 years ago

Have you tried scheduling without the days argument?

WindexChugger commented 3 years ago

Thanks for the reply.

I haven't tried scheduling a "DAILY" task without the days argument but I have tested as a "ONCE" task without the days argument (which ran successfully). I'm confident it's something about the 'DAILY'/'WEEKLY' + days arguments, but I've double check syntax and can't see what I'm doing wrong.

Edit: I guess a workaround would be to setup as a "DAILY" without days arguments, and have the script check days of the week internally.

jwijffels commented 3 years ago

Try first without the days argument.

WindexChugger commented 3 years ago

That still didn't work.

I did some digging, and found in the task list my tasks and the Power Management setting was set to "Stop On Battery Mode, No Start On Batteries". I was trying to run these tests on an unplugged laptop!

Based on 30 minutes of searching, it appears as though power management settings cannot be modified when creating a scheduled task via the command line (must use the schtasks.exe GUI, apparently).

My original code (with "WEEKLY" and the 'days' arguments) works fine when the laptop is plugged in.

If you know of any way to modify that setting via a "schtasks_extra" argument, please let me know. Otherwise, we can considered this issue resolved.

Cheers!

jwijffels commented 3 years ago

Closing as you indicate your computer was not plugged in which is indicated in the readme