bnosac / taskscheduleR

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

Feature Request: Set Task Priority Upon/After Creation #82

Open nigeljmckernan opened 3 years ago

nigeljmckernan commented 3 years ago

I have loved using the package so far, really saves tedious steps creating new tasks in Windows.

The one feature I think would really be great is to set the task Priority so that certain tasks could be (potentially) completed faster than others.

When creating a new task in Task Scheduler, Windows by default sets the task priority to 7 (0 is highest priority, 10 is lowest, for reference). When normally (interactively) running a process/script/program/etc. in Windows the priority for that task is set to 4. This usually means the task when automated to run in Task Scheduler completes much slower.

A personal example: I have an R script that's set to run Monday mornings for my work. If I run it manually (even through Rscript.exe) it usually only takes half an hour to run. Meanwhile, when Task Scheduler runs it, it nearly takes 4 hours to complete.

Could there be an additional argument in taskscheduler_create() to set the priority of the task when creating it?

The manual solution for this so far has been to export the task after being created in Task Scheduler, delete the task, edit the exported XML file, and change the priority from 7 to something lower, like 4, and then import it back in to Task Scheduler.

I realize this isn't a major request or anything, but it would be pretty cool!

Regardless if this gets implemented, thanks for the package!

jwijffels commented 3 years ago

Yes that would be nice but would require a complete rewrite of the package. The package uses schtasks.exe to pass on parameters to schedule a script (docs at https://docs.microsoft.com/en-us/windows/win32/taskschd/schtasks), there is an option to set the XML file. So that means you can use taskscheduler_create to pass on the xml file if you have it. But currently the R package does not generate or create that xml file itself and I have not idea where the documentation or structure of that xml file is defined.

nigeljmckernan commented 3 years ago

Damn, seemed like a simpler problem before I made the request.

It's not a huge loss, the manual way of setting priority is less convenient but at least it's an option.

Thanks for your time!