diff options
| author | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-24 17:40:27 +0100 |
|---|---|---|
| committer | Alex Pooley (@zuedev) <zuedev@gmail.com> | 2026-07-24 17:40:27 +0100 |
| commit | f0207bab0218ba3222b277a908dbf42303f5b09c (patch) | |
| tree | bc249920fbc2ef444e7248d0cfb88804510bad29 /174bg/database/volumes/pocketbase/pb_hooks | |
| parent | 4cccbdda3496aad74bdb3b4b2ad746f4367b13d9 (diff) | |
| download | unnamed-group-f0207bab0218ba3222b277a908dbf42303f5b09c.tar unnamed-group-f0207bab0218ba3222b277a908dbf42303f5b09c.tar.gz unnamed-group-f0207bab0218ba3222b277a908dbf42303f5b09c.tar.bz2 unnamed-group-f0207bab0218ba3222b277a908dbf42303f5b09c.tar.xz unnamed-group-f0207bab0218ba3222b277a908dbf42303f5b09c.zip | |
add database stuff to repo
Diffstat (limited to '174bg/database/volumes/pocketbase/pb_hooks')
| -rw-r--r-- | 174bg/database/volumes/pocketbase/pb_hooks/main.pb.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/174bg/database/volumes/pocketbase/pb_hooks/main.pb.js b/174bg/database/volumes/pocketbase/pb_hooks/main.pb.js new file mode 100644 index 0000000..b7d385d --- /dev/null +++ b/174bg/database/volumes/pocketbase/pb_hooks/main.pb.js @@ -0,0 +1,29 @@ +routerAdd("GET", "/heartbeat", (e) => { + try { + const result = new DynamicModel({ + "value": nullString(), + }) + + let dateNow = Date.now(); + + try { + $app.db() + .newQuery(`SELECT value FROM key_value_store WHERE key = "heartbeat"`) + .one(result); + } catch (error) { + return e.json(404, { "error": "Heartbeat not found" }); + } + + let heartbeatValue = parseInt(result.value); + let timeDifference = dateNow - heartbeatValue; + let withinThreshold = timeDifference <= 60000; // 60 seconds threshold + + return e.json(200, { "timeDifference": timeDifference, "withinThreshold": withinThreshold }); + } catch (error) { + return e.json(500, { "error": "Internal Server Error", "details": error.message }); + } +}); + +cronAdd("heartbeat", "* * * * *", () => { + $app.db().newQuery(`UPDATE key_value_store SET value = ${Date.now()} WHERE key = "heartbeat"`).execute() +})
\ No newline at end of file |
