Compare commits
1 commit
main
...
dev-signal
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f602b0fce |
12
lib/plankton/plankton.d.ts
vendored
12
lib/plankton/plankton.d.ts
vendored
|
|
@ -235,7 +235,7 @@ declare namespace lib_plankton.base {
|
|||
*/
|
||||
function object_merge(core: Record<string, any>, mantle: Record<string, any>): Record<string, any>;
|
||||
}
|
||||
declare module lib_plankton.pod {
|
||||
declare namespace lib_plankton.pod {
|
||||
/**
|
||||
* @author fenris
|
||||
*/
|
||||
|
|
@ -279,7 +279,7 @@ declare module lib_plankton.pod {
|
|||
show_value?: ((value: type_value) => string);
|
||||
}): string;
|
||||
}
|
||||
declare module lib_plankton.pod {
|
||||
declare namespace lib_plankton.pod {
|
||||
/**
|
||||
*/
|
||||
class class_pod<type_value> {
|
||||
|
|
@ -693,7 +693,13 @@ declare namespace lib_plankton.call {
|
|||
*
|
||||
* @author fenris
|
||||
*/
|
||||
function defer<type_result>(seconds: int, action: (() => type_result)): Promise<type_result>;
|
||||
function defer<type_result>(seconds: float, action: (() => type_result)): {
|
||||
id: int;
|
||||
result: Promise<type_result>;
|
||||
};
|
||||
/**
|
||||
*/
|
||||
function deferral_abort(id: int): void;
|
||||
/**
|
||||
* for rate_limit_check
|
||||
*
|
||||
|
|
|
|||
|
|
@ -1621,11 +1621,19 @@ var lib_plankton;
|
|||
* @author fenris
|
||||
*/
|
||||
function defer(seconds, action) {
|
||||
return (new Promise((resolve, reject) => {
|
||||
setTimeout(() => resolve(action()), seconds);
|
||||
}));
|
||||
let timeout_id;
|
||||
const result_promise = new Promise((resolve, reject) => {
|
||||
timeout_id = setTimeout(() => resolve(action()), Math.floor(seconds * 1000));
|
||||
});
|
||||
return { "id": timeout_id, "result": result_promise };
|
||||
}
|
||||
call.defer = defer;
|
||||
/**
|
||||
*/
|
||||
function deferral_abort(id) {
|
||||
clearTimeout(id);
|
||||
}
|
||||
call.deferral_abort = deferral_abort;
|
||||
/**
|
||||
* rate limiting algorithm, based on the idea of mana (magic power) in video games:
|
||||
* - an actor has a fixed mana capacity, i.e. the maximum amount of available power
|
||||
|
|
|
|||
|
|
@ -215,7 +215,7 @@ async function main(
|
|||
lib_plankton.log.enum_level.notice,
|
||||
lib_plankton.log.enum_level.warning,
|
||||
lib_plankton.log.enum_level.error,
|
||||
][Math.min(4, args["verbosity"])]
|
||||
][Math.min(4, /*args["verbosity"]*/0)]
|
||||
),
|
||||
]
|
||||
);
|
||||
|
|
@ -278,18 +278,70 @@ async function main(
|
|||
args["database_path"],
|
||||
args["order_path"],
|
||||
async () => {
|
||||
let ordered_to_quit : boolean = false;
|
||||
let deferral_id : (null | int) = null;
|
||||
const stop = function () {
|
||||
ordered_to_quit = true;
|
||||
if (deferral_id === null) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
lib_plankton.call.deferral_abort(deferral_id);
|
||||
}
|
||||
};
|
||||
process.on(
|
||||
"SIGINT",
|
||||
() => {
|
||||
lib_plankton.log.info("main_received_sigint", {});
|
||||
stop();
|
||||
}
|
||||
);
|
||||
process.on(
|
||||
"SIGTERM",
|
||||
() => {
|
||||
lib_plankton.log.info("main_received_sigterm", {});
|
||||
stop();
|
||||
}
|
||||
);
|
||||
while (! ordered_to_quit) {
|
||||
// cleanup
|
||||
{
|
||||
lib_plankton.log.debug("cleanup_starting", {});
|
||||
await _heimdall.master.clean(
|
||||
{
|
||||
"time_to_live": args["time_to_live"],
|
||||
"erase_state": args["erase_state"],
|
||||
}
|
||||
);
|
||||
lib_plankton.log.debug("cleanup_ended", {});
|
||||
}
|
||||
// run checks
|
||||
{
|
||||
lib_plankton.log.debug("checks_starting", {});
|
||||
await _heimdall.master.run(
|
||||
order,
|
||||
{
|
||||
"send_ok_notifications": args["send_ok_notifications"],
|
||||
}
|
||||
);
|
||||
lib_plankton.log.debug("checks_ended", {});
|
||||
}
|
||||
// pause
|
||||
{
|
||||
let {timeout_id, promise} = lib_plankton.call.timeout_start<void>(
|
||||
new Promise<void>(
|
||||
(resolve, reject) => {
|
||||
while (! ordered_to_quit) {
|
||||
// laze
|
||||
}
|
||||
resolve(undefined);
|
||||
}
|
||||
),
|
||||
5.0
|
||||
);
|
||||
await promise;
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
)
|
||||
|
|
|
|||
|
|
@ -114,6 +114,10 @@ namespace _heimdall.master
|
|||
options.time_to_live,
|
||||
options.erase_state
|
||||
);
|
||||
if (count <= 0) {
|
||||
// do nothing
|
||||
}
|
||||
else {
|
||||
lib_plankton.log.info(
|
||||
lib_plankton.translate.get(
|
||||
"misc.cleanup_info",
|
||||
|
|
@ -125,6 +129,7 @@ namespace _heimdall.master
|
|||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -189,9 +194,11 @@ namespace _heimdall.master
|
|||
return Promise.reject();
|
||||
}
|
||||
else {
|
||||
lib_plankton.log.info("mutex_setting", {});
|
||||
await lib_plankton.file.write(mutex_path, "");
|
||||
await procedure();
|
||||
await lib_plankton.file.delete_(mutex_path);
|
||||
lib_plankton.log.info("mutex_released", {});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -384,7 +384,7 @@ namespace _heimdall.order
|
|||
},
|
||||
),
|
||||
node
|
||||
);
|
||||
) as type_check;
|
||||
let check : type_check = {
|
||||
"name": node_.name,
|
||||
"title": node_.title,
|
||||
|
|
|
|||
Loading…
Reference in a new issue