caddyserver / caddy

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS
https://caddyserver.com
Apache License 2.0
57.34k stars 4k forks source link

Where do you perform time-taking one-time setups #6375

Closed hariom-qure closed 3 months ago

hariom-qure commented 3 months ago

I want to run some time taking code before caddy starts serving requests (a one time setup essentially for the module, if its configured) What is the correct method to do it in? At first I thought it would be in Provision but its explicitly written that we should not do time taking operations there ref: https://caddyserver.com/docs/extending-caddy#provisioning

Thanks!

mholt commented 3 months ago

Is the slow function required for the module/server to operate correctly?

If so, I don't know if there's a way around that. Do it in Provision...

If it's not required (then why even do it?), then maybe start a goroutine and do some basic synchronization for when it's done... does that make sense?

We either block the loading of the server or we don't -- ideally, avoid slow tasks at config load.

hariom-qure commented 3 months ago

great, thanks a lot for the quick reply, I do want to block the server before the extension is done, so should be fine

mholt commented 3 months ago

Yeah, sounds good. Just note your experience as a sysadmin will be degraded with slow config loads.