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

53
LINES

< > BotCompany Repo | #1012699 // Watch Dog for Eleu (only run on server) [OLD]

JavaX source code (desktop) [tags: use-pretranspiled] - run with: x30.jar

Download Jar. Uses 5404K of libraries. Click here for Pure Java version (7275L/51K).

!7

sS url = "https://localhost/1010504/raw/number-of-threads";
static double timeout = 60.0, delay = 30.0;
static int consecutiveFailsThreshold = /*2*/ 6; // times delay
static int consecutiveFailsThresholdWhenLoading = 20; // not used currently

sbool loading;
static int consecutiveFails;
static volatile S status;

p {
  disableCertificateValidation();
  bot("Eleu Watch Dog.");
  printWithDateAndTimeInThisThread();
  repeat with sleep delay {
    bool ok = false;
    loading = false;
    pcall {
      long time = sysNow();
      S s = loadPageWithTimeout(url, timeout);
      if (startsWith(s, "LOADING")) loading = true; // TODO: loading is now code 500
      if (isInteger(s)) {
        ok = true;
        consecutiveFails = 0;
        print(status = "Server OK - " + n2(parseLong(s), "thread", "threads") + ", " + (sysNow()-time) + " ms");
      }
    }
    
    if (!ok) {
      ++consecutiveFails;
      print(status = "Server fail #" + consecutiveFails + " of " + actualThreshold() + (loading ? " (loading)" : ""));
      pcall { serverFailActivity(); }
    }
  }
}

static int actualThreshold() {
  ret loading ? consecutiveFailsThresholdWhenLoading : consecutiveFailsThreshold;
}

svoid serverFailActivity {
  if (consecutiveFails >= actualThreshold()) {
    print("RESTARTING ELEU.");
    consecutiveFails = 0;
    hardKillProgram(#1002017);
    run(#1002710);
  }
}

answer {
  if "status" ret status;
}

download  show line numbers  debug dex  old transpilations   

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

No comments. add comment

Snippet ID: #1012699
Snippet name: Watch Dog for Eleu (only run on server) [OLD]
Eternal ID of this version: #1012699/28
Text MD5: be5941d02194277e4f0035f634b7ed9c
Transpilation MD5: b6c0c4069d0ecae80a4e63892d15813b
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2019-07-26 12:45:55
Source code size: 1473 bytes / 53 lines
Pitched / IR pitched: No / No
Views / Downloads: 458 / 1342
Version history: 27 change(s)
Referenced in: [show references]