Skip to content

Commit a78451e

Browse files
committed
add watchdog to dynamic file handlers
1 parent 2ea59b2 commit a78451e

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "rtjscomp",
3-
"version": "0.9.16",
3+
"version": "0.9.17",
44
"description": "php-like server but with javascript",
55
"repository": {
66
"type": "git",

rtjscomp.js

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ const service_update = async service_object => {
334334
}
335335
const {path} = service_object;
336336
if (log_verbose) log(path + ': prepare for (re)start');
337-
let start_interval = 0;
337+
let watchdog_interval = 0;
338338
try {
339339
// if service is running, stop it
340340
if (
@@ -451,8 +451,9 @@ const service_update = async service_object => {
451451

452452
log('start service: ' + path);
453453
service_object.status = SERVICE_STATUS_STARTING;
454-
start_interval = setInterval(() => {
455-
log(`[warning] ${path}: still starting`);
454+
let watchdog_counter = 0;
455+
watchdog_interval = setInterval(() => {
456+
log(`[warning] ${path}: starting over ${++watchdog_counter * 5} seconds`);
456457
}, 5e3);
457458
const content_object = service_object.content = {};
458459
const result = await service_object.file_function.call(
@@ -498,7 +499,7 @@ const service_update = async service_object => {
498499
return;
499500
}
500501
finally {
501-
clearInterval(start_interval);
502+
clearInterval(watchdog_interval);
502503
service_object.promise_deps =
503504
service_object.promise_deps_resolve = null;
504505
if (service_object.status !== SERVICE_STATUS_ACTIVE) {
@@ -572,8 +573,9 @@ const service_stop_inner = async service_object => {
572573
} = service_object;
573574
if (handler_stop) {
574575
service_object.handler_stop = null;
575-
const stop_interval = setInterval(() => {
576-
log(`[warning] ${path}: still stopping`);
576+
let watchdog_counter = 0;
577+
const watchdog_interval = setInterval(() => {
578+
log(`[warning] ${path}: stopping over ${++watchdog_counter} seconds`);
577579
}, 1e3);
578580
try {
579581
await handler_stop();
@@ -588,7 +590,7 @@ const service_stop_inner = async service_object => {
588590
}`);
589591
service_object.status = SERVICE_STATUS_FAILED;
590592
}
591-
clearInterval(stop_interval);
593+
clearInterval(watchdog_interval);
592594
}
593595
service_object.promise_stopped_resolve();
594596
}
@@ -1432,6 +1434,10 @@ const request_handle = async (request, response, https) => {
14321434
await services_loaded_promise;
14331435

14341436
let returned;
1437+
let watchdog_counter = 0;
1438+
const watchdog_interval = setInterval(() => {
1439+
log(`[warning] ${path}: running over ${++watchdog_counter * 5} seconds`);
1440+
}, 5e3);
14351441
try {
14361442
returned = await file_function(
14371443
file_function_input,
@@ -1462,6 +1468,7 @@ const request_handle = async (request, response, https) => {
14621468
returned = 500;
14631469
}
14641470
}
1471+
clearInterval(watchdog_interval);
14651472
if (request_method_head) {
14661473
delete file_function_output.write;
14671474
delete file_function_output.end;

0 commit comments

Comments
 (0)