Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

53
LINES

< > BotCompany Repo | #1010683 // autoRestart - auto-restart program on server change

JavaX fragment (include)

static double autoRestart_interval = 10;
static bool autoRestart_on, autoRestart_debug, autoRestart_simulate;
static java.util.Timer autoRestart_timer;

static void autoRestart(double interval) {
  autoRestart_interval = interval;
  autoRestart();
}

static void autoRestart() {
  if (!isMain() || autoRestart_on || vmHasResourceLoader()) ret;
  set autoRestart_on;
  autoRestart_schedule();
  preloadProgramTitle();
}

static void autoRestart_off() {
  if (!autoRestart_on) ret;
  stopTimer(autoRestart_timer);
  autoRestart_timer = null;
}

svoid autoRestart_schedule {
  autoRestart_timer = doLater_daemon(toMS(autoRestart_interval), r autoRestart_check);
}

svoid autoRestart_check {
  try {
    S newMD5;
    try {
      newMD5 = serverAutoRestartMD5(programID());
    } catch e {
      ret;
    }
    if (!isMD5(newMD5)) { if (autoRestart_debug) print("autoRestart: no server transpilation"); ret; }
    if (autoRestart_localMD5 == null)
      autoRestart_localMD5 = md5(loadCachedTranspilation(programID()));

    S localMD5 = autoRestart_localMD5();
    if (neq(localMD5, newMD5)) {
      if (autoRestart_simulate)
        print("Would upgrade now. " + localMD5 + " -> " + newMD5);
      else {
        infoBox("Upgrading " + programTitle());
        restartWithDelay(500);
        sleep();
      }
    }
  } finally {
    if (autoRestart_debug) print("autoRestart: Done");
    autoRestart_schedule();
  }
}

Author comment

Began life as a copy of #1010663

download  show line numbers  debug dex  old transpilations   

Travelled to 14 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt

No comments. add comment

Snippet ID: #1010683
Snippet name: autoRestart - auto-restart program on server change
Eternal ID of this version: #1010683/25
Text MD5: 02c38d3614fe1f1acceab6fbec9880a0
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2022-02-28 18:17:12
Source code size: 1467 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 463 / 561
Version history: 24 change(s)
Referenced in: [show references]