diff options
author | Matthew Wild <mwild1@gmail.com> | 2023-04-01 11:56:38 +0100 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2023-04-01 11:56:38 +0100 |
commit | 5ce1fe2603abf0e49b396a34bfb3b11a9ccd2e27 (patch) | |
tree | 191c91c841e8ca2de123d6604ad8faef85dc0f64 /util/startup.lua | |
parent | 13084baa387df6f72aa5088e8f3b98aac869ff23 (diff) | |
download | prosody-5ce1fe2603abf0e49b396a34bfb3b11a9ccd2e27.tar.gz prosody-5ce1fe2603abf0e49b396a34bfb3b11a9ccd2e27.zip |
util.startup: Add prosody.started promise to easily execute code after startup
To avoid a race where server-started fires before the promise function body is
run (on next tick), I moved server-started to fire on the next tick, which
seems sensible anyway.
Errors are logged, I'm not sure if we ought to be doing something more here.
I'm sure we'll find out.
Diffstat (limited to 'util/startup.lua')
-rw-r--r-- | util/startup.lua | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/util/startup.lua b/util/startup.lua index c000bdb1..70e03a64 100644 --- a/util/startup.lua +++ b/util/startup.lua @@ -430,8 +430,16 @@ end function startup.prepare_to_start() log("info", "Prosody is using the %s backend for connection handling", server.get_backend()); -- Signal to modules that we are ready to start - prosody.events.fire_event("server-starting"); - prosody.start_time = os.time(); + prosody.started = require "util.promise".new(function (resolve) + prosody.events.add_handler("server-started", function () + resolve(); + end); + prosody.log("debug", "Firing server-starting event"); + prosody.events.fire_event("server-starting"); + prosody.start_time = os.time(); + end):catch(function (err) + prosody.log("error", "Prosody startup error: %s", err); + end); end function startup.init_global_protection() @@ -476,7 +484,10 @@ function startup.log_greeting() end function startup.notify_started() - prosody.events.fire_event("server-started"); + require "util.timer".add_task(0, function () + prosody.log("debug", "Firing server-started event"); + prosody.events.fire_event("server-started"); + end); end -- Override logging config (used by prosodyctl) |