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).

1  
!7
2  
3  
sS url = "https://localhost/1010504/raw/number-of-threads";
4  
static double timeout = 60.0, delay = 30.0;
5  
static int consecutiveFailsThreshold = /*2*/ 6; // times delay
6  
static int consecutiveFailsThresholdWhenLoading = 20; // not used currently
7  
8  
sbool loading;
9  
static int consecutiveFails;
10  
static volatile S status;
11  
12  
p {
13  
  disableCertificateValidation();
14  
  bot("Eleu Watch Dog.");
15  
  printWithDateAndTimeInThisThread();
16  
  repeat with sleep delay {
17  
    bool ok = false;
18  
    loading = false;
19  
    pcall {
20  
      long time = sysNow();
21  
      S s = loadPageWithTimeout(url, timeout);
22  
      if (startsWith(s, "LOADING")) loading = true; // TODO: loading is now code 500
23  
      if (isInteger(s)) {
24  
        ok = true;
25  
        consecutiveFails = 0;
26  
        print(status = "Server OK - " + n2(parseLong(s), "thread", "threads") + ", " + (sysNow()-time) + " ms");
27  
      }
28  
    }
29  
    
30  
    if (!ok) {
31  
      ++consecutiveFails;
32  
      print(status = "Server fail #" + consecutiveFails + " of " + actualThreshold() + (loading ? " (loading)" : ""));
33  
      pcall { serverFailActivity(); }
34  
    }
35  
  }
36  
}
37  
38  
static int actualThreshold() {
39  
  ret loading ? consecutiveFailsThresholdWhenLoading : consecutiveFailsThreshold;
40  
}
41  
42  
svoid serverFailActivity {
43  
  if (consecutiveFails >= actualThreshold()) {
44  
    print("RESTARTING ELEU.");
45  
    consecutiveFails = 0;
46  
    hardKillProgram(#1002017);
47  
    run(#1002710);
48  
  }
49  
}
50  
51  
answer {
52  
  if "status" ret status;
53  
}

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: 612 / 1690
Version history: 27 change(s)
Referenced in: [show references]