workaround quirks from Node.js (#5631)

This commit is contained in:
Alex Lam S.L
2022-08-25 23:25:44 +01:00
committed by GitHub
parent 41a7000745
commit 965e9767e5
2 changed files with 8 additions and 10 deletions

View File

@@ -2,12 +2,14 @@ var get = require("https").get;
var parse = require("url").parse; var parse = require("url").parse;
var base, token, run_number; var base, token, run_number;
var expires = Date.now() + (5 * 60 + 55) * 60 * 1000;
exports.init = function(url, auth, num) { exports.init = function(url, auth, num) {
base = url; base = url;
token = auth; token = auth;
run_number = num; run_number = num;
}; };
exports.should_stop = function(callback) { exports.should_stop = function(callback) {
if (Date.now() > expires) return callback();
read(base + "/actions/runs?per_page=100", function(reply) { read(base + "/actions/runs?per_page=100", function(reply) {
var runs = verify(reply, "workflow_runs").sort(function(a, b) { var runs = verify(reply, "workflow_runs").sort(function(a, b) {
return b.run_number - a.run_number; return b.run_number - a.run_number;

View File

@@ -20,9 +20,13 @@ switch (process.argv.length) {
var tasks = [ run(), run() ]; var tasks = [ run(), run() ];
if (iterations) return; if (iterations) return;
var alive = setInterval(function() { var alive = setInterval(function() {
actions.should_stop(stop); actions.should_stop(function() {
clearInterval(alive);
tasks.forEach(function(kill) {
kill();
});
});
}, 8 * 60 * 1000); }, 8 * 60 * 1000);
var deadline = setTimeout(stop, (5 * 60 + 55) * 60 * 1000);
function run() { function run() {
var child, stdout, stderr, log; var child, stdout, stderr, log;
@@ -72,11 +76,3 @@ function run() {
} }
} }
} }
function stop() {
clearInterval(alive);
clearInterval(deadline);
tasks.forEach(function(kill) {
kill();
});
}