View Single Post
  #1459  
Old 15.07.2020, 11:10
mgpai mgpai is offline
Script Master
 
Join Date: Sep 2013
Posts: 1,003
Default

@psp: Have included an option to restart after 'x' hours (Disabled by default).

For GUI:
Code:
// Restart & Update when JD is idle, or after 'x' hours.
// Trigger: Interval (Recommended 600000 or more).

var hours = 0; // Update after 'x' hours, even if JD is not idle. (0 = Disabled)

if (callAPI("update", "isUpdateAvailable")) {

    var updateNow = false;

    if (hours > 0) {
        
        if (!getProperty("date", false)) {
            setProperty("date", new Date(Date.now() + hours * 60 * 60 * 1000), false);
        }

        if (Date.now() > getProperty("date", false)) {
            updateNow = true;
        }
    }

    if (!updateNow) {
        
        var idle = isDownloadControllerIdle() &&
            !callAPI("linkcrawler", "isCrawling") &&
            !callAPI("linkgrabberv2", "isCollecting") &&
            !callAPI("extraction", "getQueue").length > 0;

        if (idle) {
            updateNow = true;
        }
    }

    if (updateNow) {
        callAPI("update", "restartAndUpdate");
    }
}

For Headless:
Code:
[ {
  "eventTrigger" : "INTERVAL",
  "enabled" : true,
  "name" : "Auto-update JD",
  "script" : "// Restart & Update when JD is idle, or after 'x' hours.\n// Trigger: Interval (Recommended 600000 or more).\n\nvar hours = 0; // Update after 'x' hours, even if JD is not idle. (0 = Disabled)\n\nif (callAPI(\"update\", \"isUpdateAvailable\")) {\n\n    var updateNow = false;\n\n    if (hours > 0) {\n        \n        if (!getProperty(\"date\", false)) {\n            setProperty(\"date\", new Date(Date.now() + hours * 60 * 60 * 1000), false);\n        }\n\n        if (Date.now() > getProperty(\"date\", false)) {\n            updateNow = true;\n        }\n    }\n\n    if (!updateNow) {\n        \n        var idle = isDownloadControllerIdle() &&\n            !callAPI(\"linkcrawler\", \"isCrawling\") &&\n            !callAPI(\"linkgrabberv2\", \"isCollecting\") &&\n            !callAPI(\"extraction\", \"getQueue\").length > 0;\n\n        if (idle) {\n            updateNow = true;\n        }\n    }\n\n    if (updateNow) {\n        callAPI(\"update\", \"restartAndUpdate\");\n    }\n}",
  "eventTriggerSettings" : {
    "lastFire" : 1594799412187,
    "interval" : 600000,
    "isSynchronous" : false
  },
  "id" : 1594796988140
} ]

If I have something useful to add to the articles, will definitely share my thoughts.
Reply With Quote