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

83
LINES

< > BotCompany Repo | #1028187 // Discord Audio Bots Watch Dog

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

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

1  
!7
2  
3  
sS iconID = #1101427;
4  
static double interval = 60.0, timeout = 30.0; // change for fast computers
5  
static int consecutiveFailsThreshold = 3; // TODO: change if loading
6  
sS osBotName = "Discord Bots OS";
7  
sS vmArgs = "--add-opens java.base/jdk.internal.loader=ALL-UNNAMED --add-opens java.base/jdk.internal.module=ALL-UNNAMED --add-opens java.base/jdk.internal.ref=ALL-UNNAMED --add-opens java.base/jdk.internal.reflect=ALL-UNNAMED --add-opens java.base/java.lang.module=ALL-UNNAMED --illegal-access=permit -Xmx1g";
8  
9  
sbool v6;
10  
static int consecutiveFails;
11  
static volatile S status;
12  
static TrayIcon trayIcon;
13  
14  
sS osProgramID;
15  
16  
p {
17  
  // TODO
18  
  osProgramID = or(get(args, 0), #1025342);
19  
20  
  // TODO: put "Restart OS Now" in consoleMemoryView()'s popup menu
21  
22  
  S myName = "Watch dog for " + osBotName;
23  
  bot(myName);
24  
  trayIcon = installTrayIcon(iconID, myName,
25  
    r showConsole,
26  
    "Restart " + osBotName + " Now", r restartOSNow,
27  
    "Show Watch Dog Window", r showConsole,
28  
    "Hide Watch Dog Window", r hideConsole,
29  
    "Exit Watch Dog", rThread cleanKill);
30  
  consoleIcon(iconID);
31  
  //printWithDateAndTimeInThisThread();
32  
  doEvery(interval, r {
33  
    bool ok = false;
34  
    pcall {
35  
      long time = sysNow();
36  
      S s = sendOptWithTimeout(timeout, osBotName, "live check");
37  
      if "i'm alive" {
38  
        hideConsole();
39  
        ok = true;
40  
        consecutiveFails = 0;
41  
        setStatus(osBotName + " OK");
42  
      } else
43  
        showConsole();
44  
      consoleStatus(ok ? "OK" : "FAIL");
45  
    }
46  
    
47  
    if (!ok) {
48  
      ++consecutiveFails;
49  
      printAndProgramLog(status = osBotName + " #" + consecutiveFails + " of " + consecutiveFailsThreshold);
50  
      /*S stackTraces = sendOptWithTimeout(timeout, osBotName, "stack traces");
51  
      if (nempty(stackTraces)) {
52  
        stackTraces = unquote(stackTraces);
53  
        print(stackTraces);
54  
        saveTextFile(newFile(stefansOS_watchDogStackTracesDir(), "discord-audio-stack-trace-" +  ymd_minus_hms() + ".txt"), stackTraces);
55  
      }*/
56  
      pcall { osFailActivity(); }
57  
    }
58  
  });
59  
  hideConsole();
60  
  
61  
  sleep();
62  
}
63  
64  
svoid osFailActivity {
65  
  if (consecutiveFails >= consecutiveFailsThreshold)
66  
    restartOSNow();
67  
}
68  
69  
svoid restartOSNow {
70  
  printAndProgramLog("RESTARTING " + osBotName + ".");
71  
  consecutiveFails = 0;
72  
  hardKillProgram(osProgramID, level := 9);
73  
  nohupJavax(osProgramID, vmArgs);
74  
}
75  
76  
answer {
77  
  if "status" ret status;
78  
}
79  
80  
svoid setStatus(S status) {
81  
  printAndProgramLog(main.status = status);
82  
  setTrayIconToolTip(trayIcon, status);
83  
}

Author comment

Began life as a copy of #1019683

download  show line numbers  debug dex  old transpilations   

Travelled to 9 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, whxojlpjdney, xrpafgyirdlv

No comments. add comment

Snippet ID: #1028187
Snippet name: Discord Audio Bots Watch Dog
Eternal ID of this version: #1028187/8
Text MD5: edcc3b3f697686088cf5a72c3bb4a10b
Transpilation MD5: f4044e64768b9872ccef218dcc5a7ac4
Author: stefan
Category: javax
Type: JavaX source code (desktop)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2020-11-10 12:44:40
Source code size: 2571 bytes / 83 lines
Pitched / IR pitched: No / No
Views / Downloads: 322 / 1136
Version history: 7 change(s)
Referenced in: [show references]