Track your local R scheduled tasks with CommandCenter2000!!!

本文介绍了一款名为CommandCenter2000的工具,用于自动化脚本运行监控与错误处理。它能追踪任务运行状态,提供成功或失败的指示,并帮助重新运行失败的脚本。通过设置任务调度、使用特定脚本命令和配置CommandCenter2000脚本来监控多个任务。实时监控分析状态包括最后运行时间、状态(绿色或红色灯)和错误详情,以便快速定位和解决问题。

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值