Download Jar. Uses 5404K of libraries. Click here for Pure Java version (15617L/100K).
1 | !7 |
2 | |
3 | sbool smartBotToo = false; |
4 | sS url = "http://localhost:8080/1010504/raw/number-of-threads"; |
5 | sS mainURL = null; //"http://localhost:8080"; |
6 | sS smartBotURL = "http://localhost:4678/number-of-threads"; |
7 | static double timeout = 60.0, delay = 30.0; |
8 | static int consecutiveFailsThreshold = /*2*/ 10; // times delay |
9 | static int consecutiveFailsThresholdWhenLoading = 20; // not used |
10 | |
11 | static int consecutiveFails; |
12 | static volatile S status; |
13 | sbool playMode; |
14 | |
15 | p { |
16 | bot("New Eleu Watch Dog."); |
17 | |
18 | if (cic(args, "playMode")) set playMode; |
19 | |
20 | if (smartBotToo) thread "Smart Bot Loop" { smartBotLoop(); } |
21 | |
22 | printWithDateAndTimeInThisThread(); |
23 | repeat with sleep delay { |
24 | bool ok = false, loading = false; |
25 | pcall { |
26 | long time = sysNow(); |
27 | |
28 | /*S mainData = loadPageWithTimeout(mainURL, timeout/2); |
29 | if (!startsWith(mainData, "<") || swic(mainData, "ERROR")) { |
30 | print("Error! " + mainData); |
31 | } else {*/ |
32 | S s = loadPageWithTimeout(url, timeout); |
33 | if (startsWith(s, "LOADING")) loading = true; // TODO: loading is now code 500 |
34 | if (isInteger(s)) { |
35 | ok = true; |
36 | consecutiveFails = 0; |
37 | print(status = "Server OK - " + n2(parseLong(s), "thread", "threads") + ", " + (sysNow()-time) + " ms"); |
38 | } |
39 | //} |
40 | } |
41 | |
42 | if (!ok) { |
43 | ++consecutiveFails; |
44 | print(status = "Server fail #" + consecutiveFails + " of " + actualThreshold(loading) + (loading ? " (loading)" : "")); |
45 | pcall { serverFailActivity(loading); } |
46 | } |
47 | } |
48 | } |
49 | |
50 | static int actualThreshold(bool loading) { |
51 | ret loading ? consecutiveFailsThresholdWhenLoading : consecutiveFailsThreshold; |
52 | } |
53 | |
54 | svoid serverFailActivity(bool loading) { |
55 | if (consecutiveFails == actualThreshold(loading)) { |
56 | consecutiveFails = 0; |
57 | if (playMode) ret with print("WOULD RESTART ELEU."); |
58 | print("RESTARTING ELEU."); |
59 | hardKillProgram(#1013896); |
60 | S eleuOptions = loadTextFileTrim(javaxDataDir("eleu.options")); |
61 | directNohupJavax(joinNemptiesWithSpace(eleuOptions, str(psI(#1013896)))); |
62 | } |
63 | } |
64 | |
65 | answer { |
66 | if "status" ret status; |
67 | } |
68 | |
69 | svoid smartBotLoop { |
70 | int consecutiveFails = 0; |
71 | S status = ""; |
72 | printWithDateAndTimeInThisThread(); |
73 | repeat with sleep delay { |
74 | bool ok = false, loading = false; |
75 | pcall { |
76 | long time = sysNow(); |
77 | S s = loadPageWithTimeout(smartBotURL, timeout); |
78 | if (startsWith(s, "LOADING")) loading = true; |
79 | if (isInteger(s)) { |
80 | ok = true; |
81 | consecutiveFails = 0; |
82 | print(status = "Smart Bot OK - " + n2(parseLong(s), "thread", "threads") + ", " + (sysNow()-time) + " ms"); |
83 | } |
84 | } |
85 | |
86 | if (!ok) { |
87 | ++consecutiveFails; |
88 | print(status = "Smart Bot fail #" + consecutiveFails + " of " + actualThreshold(loading) + (loading ? " (loading)" : "")); |
89 | pcall { |
90 | if (smartBotFailActivity(consecutiveFails, loading)) |
91 | consecutiveFails = 0; |
92 | } |
93 | } |
94 | } |
95 | } |
96 | |
97 | sbool smartBotFailActivity(int consecutiveFails, bool loading) { |
98 | if (consecutiveFails >= actualThreshold(loading)) { |
99 | print("RESTARTING SMART BOT."); |
100 | hardKillProgram(#1010745); |
101 | nohupJavaxHeadless(#1010745); |
102 | true; |
103 | } |
104 | false; |
105 | } |
Began life as a copy of #1012699
download show line numbers debug dex old transpilations
Travelled to 20 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, djztyncnmsck, gwrvuhgaqvyk, hpgrupgrauku, irmadwmeruwu, ishqpsrjomds, iveijnkanddl, lpdgvwnxivlt, mqqgnosmbjvj, odhhsrjjbcgr, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, twycvekltchr, vouqrxazstgt
No comments. add comment
Snippet ID: | #1014075 |
Snippet name: | Watch Dog for New Eleu + Smart Bot (only run on server) [LIVE] |
Eternal ID of this version: | #1014075/30 |
Text MD5: | 7f9015694523229f818df3ae3243a610 |
Transpilation MD5: | 8bd01f6a40735567ff0c17f848c40397 |
Author: | stefan |
Category: | javax |
Type: | JavaX source code (desktop) |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2021-10-30 14:53:41 |
Source code size: | 3253 bytes / 105 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 557 / 2445 |
Version history: | 29 change(s) |
Referenced in: | [show references] |