diff options
author | Alex Lam S.L <alexlamsl@gmail.com> | 2020-09-26 00:56:00 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-26 07:56:00 +0800 |
commit | 40f36b9e0111ce76487f6f12e240545a0ea70003 (patch) | |
tree | cb5a2b1e987caf9ddc1ce1b725df488d61ba6ba9 /test/ufuzz/actions.js | |
parent | 6e105c5ca6c95f6159d91f74df92020f33ae2f99 (diff) | |
download | tracifyjs-40f36b9e0111ce76487f6f12e240545a0ea70003.tar.gz tracifyjs-40f36b9e0111ce76487f6f12e240545a0ea70003.zip |
improve `ufuzz` duty cycle heuristic (#4153)
Diffstat (limited to 'test/ufuzz/actions.js')
-rw-r--r-- | test/ufuzz/actions.js | 64 |
1 files changed, 35 insertions, 29 deletions
diff --git a/test/ufuzz/actions.js b/test/ufuzz/actions.js index a5cd0eb2..b4d8c86b 100644 --- a/test/ufuzz/actions.js +++ b/test/ufuzz/actions.js @@ -1,32 +1,42 @@ -require("../../tools/exit"); - var get = require("https").get; var parse = require("url").parse; -var base = process.argv[2]; -var token = process.argv[3]; -var queued = 0, total = 0, earliest, now = Date.now(); -process.on("beforeExit", function() { - if (queued > 3) { - process.stdout.write("0"); - } else { - var average = total > 2 && (now - earliest) / (total - 1); - process.stdout.write(Math.min(Math.max(20 * average, 2700000), 18000000).toFixed(0)); - } -}); -read(base + "/actions/workflows/ufuzz.yml/runs?event=schedule", function(reply) { - check(reply, "workflow_runs").filter(function(workflow) { - return /^(in_progress|queued|)$/.test(workflow.status); - }).forEach(function(workflow) { - read(workflow.jobs_url, function(reply) { - check(reply, "jobs").forEach(function(job) { - if (job.status == "queued") queued++; - total++; - var start = Date.parse(job.started_at); - if (!(earliest < start)) earliest = start; - }); + +var base, token, run_number, eldest = true; +exports.init = function(url, auth, num) { + base = url; + token = auth; + run_number = num; +}; +exports.should_stop = function(callback) { + read(base + "/actions/runs?per_page=100", function(reply) { + if (!reply || !Array.isArray(reply.workflow_runs)) return; + var runs = reply.workflow_runs.filter(function(workflow) { + return workflow.status != "completed"; + }).sort(function(a, b) { + return b.run_number - a.run_number; }); + if (runs.length < 10) return; + var found = false, remaining = 20; + (function next() { + if (!runs.length) return; + var workflow = runs.pop(); + if (workflow.run_number == run_number) found = true; + read(workflow.jobs_url, function(reply) { + if (!reply || !Array.isArray(reply.jobs)) return; + if (!reply.jobs.every(function(job) { + if (job.status == "completed") return true; + remaining--; + return found; + })) return; + if (remaining >= 0) { + next(); + } else { + callback(); + } + }); + })(); }); -}); +}; function read(url, callback) { var options = parse(url); @@ -44,7 +54,3 @@ function read(url, callback) { }); }); } - -function check(reply, field) { - return reply && Array.isArray(reply[field]) ? reply[field] : []; -} |