Add redbean OnServerHeartbeat hook

This commit is contained in:
Paul Kulchenko 2022-08-02 16:07:40 -07:00
parent 634fdf0a3f
commit 7ec2196f0b
2 changed files with 11 additions and 1 deletions

View file

@ -554,6 +554,12 @@ HOOKS
each time redbean reaps a child connection process using wait4().
This won't be called in uniprocess mode.
OnServerHeartbeat()
If this function is defined it'll be called from the main process
on each server heartbeat. The heartbeat interval is configurable
with ProgramHeartbeatInterval. If this hook is defined, then
`/.heartbeat.lua` is not called.
OnServerListen(socketdescriptor:int,serverip:int,serverport:int) → bool
If this function is defined it'll be called from the main process
before redbean starts listening on a port. This hook can be used

View file

@ -5745,7 +5745,11 @@ static void HandleHeartbeat(void) {
Reindex();
getrusage(RUSAGE_SELF, &shared->server);
#ifndef STATIC
LuaRunAsset("/.heartbeat.lua", false);
if (IsHookDefined("OnServerHeartbeat")) {
CallSimpleHook("OnServerHeartbeat");
} else {
LuaRunAsset("/.heartbeat.lua", false);
}
CollectGarbage();
#endif
for (i = 1; i < servers.n; ++i) {