Mercurial > prosody-modules
comparison mod_audit_status/mod_audit_status.lua @ 5353:14b6397cd6de
mod_audit_status: Fix error on first start
Fixes 'attempt to index a nil value' the first time this module is
loaded, since there's no data yet.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Tue, 18 Apr 2023 21:48:31 +0200 |
| parents | 18fd615c2733 |
| children | 9944c6c3e914 |
comparison
equal
deleted
inserted
replaced
| 5352:f6577cdb1d91 | 5353:14b6397cd6de |
|---|---|
| 9 | 9 |
| 10 local store = module:open_store(nil, "keyval+"); | 10 local store = module:open_store(nil, "keyval+"); |
| 11 | 11 |
| 12 module:hook_global("server-started", function () | 12 module:hook_global("server-started", function () |
| 13 local recorded_status = store:get(); | 13 local recorded_status = store:get(); |
| 14 if recorded_status.status == "started" then | 14 if recorded_status and recorded_status.status == "started" then |
| 15 module:audit(nil, "server-crashed", { timestamp = recorded_status.heartbeat }); | 15 module:audit(nil, "server-crashed", { timestamp = recorded_status.heartbeat }); |
| 16 end | 16 end |
| 17 module:audit(nil, "server-started"); | 17 module:audit(nil, "server-started"); |
| 18 store:set_key(nil, "status", "started"); | 18 store:set_key(nil, "status", "started"); |
| 19 end); | 19 end); |
