improve `ufuzz` duty cycle heuristic (#4045)
authorAlex Lam S.L <alexlamsl@gmail.com>
Sat, 8 Aug 2020 19:10:19 +0000 (20:10 +0100)
committerGitHub <noreply@github.com>
Sat, 8 Aug 2020 19:10:19 +0000 (03:10 +0800)
.github/workflows/ufuzz.yml
test/ufuzz/actions.js

index 4dd9de2..4a55eb4 100644 (file)
@@ -38,10 +38,10 @@ jobs:
           while !(npm install); do echo "'npm install' failed - retrying..."; done
           PERIOD=1800000
           if [[ $CAUSE == "schedule" ]]; then
-            PERIOD=$(( 3600 * `node test/ufuzz/actions $BASE_URL $TOKEN` ))
+            PERIOD=`node test/ufuzz/actions $BASE_URL $TOKEN`
           fi
           if (( $PERIOD == 0 )); then
-            echo "too many jobs in queue - exiting..."
+            echo "too many jobs in queue - skipping..."
           else
             node test/ufuzz/job $PERIOD
           fi
index c4438d8..53754a7 100644 (file)
@@ -22,28 +22,28 @@ function read(url, callback) {
     });
 }
 
-var in_progress = 0, queued = 0;
+var queued = 0, total = 0;
+var earliest, latest;
 process.on("beforeExit", function() {
     if (queued > 3) {
         process.stdout.write("0");
+    } else if (total < 2) {
+        process.stdout.write("3600000");
     } else {
-        process.stdout.write(Math.min(1000 * 20 / in_progress, 1500).toFixed(0));
+        process.stdout.write(Math.min(20 * (latest - earliest) / (total - 1), 5400000).toFixed(0));
     }
 });
-read(base + "/actions/workflows/ufuzz.yml/runs", function(reply) {
+read(base + "/actions/workflows/ufuzz.yml/runs?event=schedule", function(reply) {
     reply.workflow_runs.filter(function(workflow) {
         return /^(in_progress|queued|)$/.test(workflow.status);
     }).forEach(function(workflow) {
         read(workflow.jobs_url, function(reply) {
             reply.jobs.forEach(function(job) {
-                switch (job.status) {
-                  case "in_progress":
-                    in_progress++;
-                    break;
-                  case "queued":
-                    queued++;
-                    break;
-                }
+                if (job.status == "queued") queued++;
+                total++;
+                var start = new Date(job.started_at);
+                if (!(earliest < start)) earliest = start;
+                if (!(latest > start)) latest = start;
             });
         });
     });