Skip to content

stop task creation if task is too long or if debug is TRUE - introduces breaking changes #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

monkeywithacupcake
Copy link

This PR expands documentation but more drastically changes behavior of taskscheduler_create:

  • will stop with error if nchar(task) > 260
  • will not attempt to actually schedule the task if debug = TRUE

Both of these changes were inspired by #106

However, they are breaking changes. Users in the habit of running with debug = TRUE to simply 'see the call' might expect it to still run. Not sure if this is desired.

Also, I could not replicate the behavior identified in #106. Using an rscript of length 102 and 115, I do not see the task being clipped. However, The user did say that the debug print value is not what is actually passed to the TR in the Windows task scheduler. I am on a Mac, so it would be good to see this actually happening. The code that warns the user about long file names has been in place (based on blame) for years, so the OG poster should have been warned.

Here is an example. I'm running it after my edits, so you see an error about it failing because of TR length which is not in the original package (current behavior is just a warning)

devtools::load_all()
#> ℹ Loading taskscheduleR
# a very long rscript path
myscript <- path.expand("~/this_is_a_long_fake_folder_name/this_is_a_nested_fake_folder/long_folder_eesh/script_with_a_long_name.R")
nchar(myscript)
#> [1] 115
taskscheduler_create(taskname = "myfancyscript_sun", 
                     rscript = myscript, 
                     schedule = "WEEKLY", 
                     starttime = "09:10", 
                     days = 'SUN',
                     debug = TRUE)
#> Warning in taskscheduler_create(taskname = "myfancyscript_sun", rscript =
#> myscript, : Passing on this to the TR argument of schtasks.exe: cmd /c
#> /Library/Frameworks/R.framework/Resources/bin/Rscript.exe
#> '/Users/jess/this_is_a_long_fake_folder_name/this_is_a_nested_fake_folder/long_folder_eesh/script_with_a_long_name.R'
#> >>
#> '/Users/jess/this_is_a_long_fake_folder_name/this_is_a_nested_fake_folder/long_folder_eesh/script_with_a_long_name.log'
#> 2>&1, this is too long. Consider putting your scripts into another folder
#> Error in taskscheduler_create(taskname = "myfancyscript_sun", rscript = myscript, : "Will Fail, try a shorter path" is not TRUE
# rscript path that is between 100 and 103 
myscript <- path.expand("~/this_is_a_long_fake_folder_name/this_is_a_nested_fake_folder/long_folder_eesh/scriptname.R")
nchar(myscript)
#> [1] 102
taskscheduler_create(taskname = "myfancyscript_sun", 
                     rscript = myscript, 
                     schedule = "WEEKLY", 
                     starttime = "09:10", 
                     days = 'SUN',
                     debug = TRUE)
#> Warning in taskscheduler_create(taskname = "myfancyscript_sun", rscript =
#> myscript, : Passing on this to the TR argument of schtasks.exe: cmd /c
#> /Library/Frameworks/R.framework/Resources/bin/Rscript.exe
#> '/Users/jess/this_is_a_long_fake_folder_name/this_is_a_nested_fake_folder/long_folder_eesh/scriptname.R'
#> >>
#> '/Users/jess/this_is_a_long_fake_folder_name/this_is_a_nested_fake_folder/long_folder_eesh/scriptname.log'
#> 2>&1, this is too long. Consider putting your scripts into another folder
#> Error in taskscheduler_create(taskname = "myfancyscript_sun", rscript = myscript, : "Will Fail, try a shorter path" is not TRUE
# and a short rscript path
myscript <- path.expand("~/this_is_a_long_fake_folder_name/scriptname.R")
nchar(myscript)
#> [1] 56
taskscheduler_create(taskname = "myfancyscript_sun", 
                     rscript = myscript, 
                     schedule = "WEEKLY", 
                     starttime = "09:10", 
                     days = 'SUN',
                     debug = TRUE)
#> Creating task schedule: schtasks /Create /TN "myfancyscript_sun" /TR "cmd /c /Library/Frameworks/R.framework/Resources/bin/Rscript.exe  '/Users/jess/this_is_a_long_fake_folder_name/scriptname.R'  >> '/Users/jess/this_is_a_long_fake_folder_name/scriptname.log' 2>&1" /SC WEEKLY /ST 09:10 /SD '18/04/2025' /D SUN

Created on 2025-04-18 with reprex v2.1.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant