关闭

Track your local R scheduled tasks with CommandCenter2000!!!

213人阅读 评论(0) 收藏 举报
分类:

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:

 

Capture

 

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:

diagram

(Follow the steps in the schematic above: red for setup, and yellow to run it. These are explained below)

    1. 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"

    2. 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)!
    3. OK, now tasks will be firing off! Now you need to get the command Center script from my github account. Go


      it now!

      1. This contains:
        1. the CommandCenter R script
        2. 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
        3. the html file that reports the status of each task.
        4. ignore the rest of the stuff
      2. Ok, now you have a local CommandCenter2000!!!.
        1. Set up the WORKING DIRECTORY to wherever you installed the folder.
        2. 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:
          1. Copy the block of code that looks like it should be copied. (hint, there’s START and END comments). Within each:
            1. Give that script a human name (this is what will be displayed)
            2. Specify the path and name of the R file (remember the whole “/” vs “” debacle for windows paths)
            3. Specify the path and name of  the .bat file
          2. That’s it! Rinse and repeat for every script that you would like on your CommandCenter2000!!!
    4. 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.
    5. Everytime you click it, you’ll get the html file coming up shown above. In detail:
      1. thing“: is just the name of the analysis
      2. lastRun“: is how long ago the analysis ran (in days… although obviously this is configurable).
      3. 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: ddThis mouseover effect will help you debug… using the following two options
      4. 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)
      5. 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.

0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:372454次
    • 积分:5059
    • 等级:
    • 排名:第5753名
    • 原创:37篇
    • 转载:614篇
    • 译文:1篇
    • 评论:12条
    最新评论