iutils: ScriptHandler now stops after multiple successive failures in a short period of time

This commit is contained in:
illumineawake 2021-08-21 22:09:01 +10:00
parent 33c20069ca
commit 43470feb1e
4 changed files with 25 additions and 6 deletions

View File

@ -23,7 +23,7 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
version = "4.4.7"
version = "4.4.8"
project.extra["PluginName"] = "iUtils"
project.extra["PluginDescription"] = "Illumine - Utils required for plugins to function with added automation"

View File

@ -6,21 +6,40 @@ import net.runelite.client.plugins.iutils.util.Util;
@Slf4j
public class IScriptHandler implements Runnable {
private final iScript script;
private static final int FAILURE_RESET = 75000;
private static final int MAX_FAILURES = 10;
public IScriptHandler(iScript script) {
this.script = script;
}
public void run() {
var failures = 0;
var lastFailure = System.currentTimeMillis();
script.onStart();
while (!Thread.currentThread().isInterrupted()) {
try {
script.loop();
} catch (IllegalStateException | AssertionError | NullPointerException e) {
log.info("Caught error, restarting in 3 seconds");
e.printStackTrace();
log.info(e.getMessage());
Util.sleep(3000);
if (System.currentTimeMillis() - lastFailure > FAILURE_RESET) {
failures = 0;
}
lastFailure = System.currentTimeMillis();
if (failures <= MAX_FAILURES) {
failures++;
log.info("Caught failure #{}, restarting in 3 seconds", failures);
e.printStackTrace();
log.info(e.getMessage());
Util.sleep(3000);
} else {
log.info("Caught > 10 failures, stopping plugin");
script.onStop();
return;
}
}
}
}

File diff suppressed because one or more lines are too long