Track your local R scheduled tasks with CommandCenter2000!!!
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
There are many ways to automate your scripts running, for example using RScript, or in-R itself (and now even as an add-in for RStudio) (check all here). But after a while, it can get a bit overwhelming to track tasks and ensure they are firing as planned. In order to address this, I have developed some futuristic advanced tech that lets us do that. I hereby present to you: the CommandCenter2000!!! Yes, it’s Y2K compliant! This is what it looks like:
It has the following features:
- It’ll tell you when the script ran last
- whether it was successful or not (green/red light)
- and will help you rerun failed scripts in 2 ways.
How to make your own:
(Follow the steps in the schematic above: red for setup, and yellow to run it. These are explained below)
- Setup the folders where there are running tasks. Concretely, inside the working folder for each script, you need a .bat file that will run that specific script. Within the bat file*, the code will look like this for example:
@echo off "C:Program FilesRR-3.2.2binx64R.exe" --vanilla --slave CMD BATCH "D:Project Xanalyzer.R"
- OK, now you need to schedule the task in Windows (I like scheduling it myself so that I can set some specific requirements… in particular, I want tasks to fire only if connected to certain wifi). Don’t know how to do this? Check this out (that’s how I learned)!
- OK, now tasks will be firing off! Now you need to get the command Center script from my github account. Go
it now!
- This contains:
- the CommandCenter R script
- a .bat file that will run the CommandCenter2000!!! itself. I recommend creating a shortcut to this bat file on your desktop or whatever. That way you can run it whenever
- the html file that reports the status of each task.
- ignore the rest of the stuff
- Ok, now you have a local CommandCenter2000!!!.
- Set up the WORKING DIRECTORY to wherever you installed the folder.
- Now, for each script you’d like to track in the CommandCenter2000!!!, add a reference to that script in the main CommandCenter2000!!! script. By “reference”, I mean:
- Copy the block of code that looks like it should be copied. (hint, there’s START and END comments). Within each:
- Give that script a human name (this is what will be displayed)
- Specify the path and name of the R file (remember the whole “/” vs “” debacle for windows paths)
- Specify the path and name of the .bat file
- That’s it! Rinse and repeat for every script that you would like on your CommandCenter2000!!!
- Copy the block of code that looks like it should be copied. (hint, there’s START and END comments). Within each:
- This contains:
- OK, setup is done. Now, whenever you want to check the status of scripts, you can just run your command center. Of course, you could run the CommandCenter2000!!! itself on a schedule… but putting something on a schedule to check whether other things are running on schedule correctly is a bit…… mind-bending. Careful you don’t break reality.
- Everytime you click it, you’ll get the html file coming up shown above. In detail:
- “thing“: is just the name of the analysis
- “lastRun“: is how long ago the analysis ran (in days… although obviously this is configurable).
- “status“: (this is the last column) has a red or green light to indicate whether the script ran successfully or not. If it didn’t, the red light will have a mouseover effect whereby you’ll be able to tell what the error was…. which looks like this: This mouseover effect will help you debug… using the following two options
- “SomethingWrong“: provides a link to the R file, in case the script failed because your R script is messed up. Don’t click the link, but right click and “copy link”, then open it from R (sorry for roundabout way, but unfortunately it’s very difficult to launch a local file from HTML for security)
- “runLink: provides a link to the bat file that will run the script (more on this later). Use this if the script failed but you think the R script is correct and just needs to rerun (for example if the network crapped out), just click, download the bat file and run it… everything will rerun automatically.
So clearly, this is a very rough first-pass attempt to keep track of scheduled tasks. If you’d like to collaborate, I’d love to evaluate some pull-requests.
*WARNING: This approach uses .bat files, which could damage your computer or corrupt your data. Be VERY CAREFUL, and don’t trust anybody else’s bat files without first examining them in a text editor.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.