Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add handling of startup #22

Open
Anniepoo opened this issue Jul 6, 2017 · 0 comments
Open

add handling of startup #22

Anniepoo opened this issue Jul 6, 2017 · 0 comments

Comments

@Anniepoo
Copy link
Owner

Anniepoo commented Jul 6, 2017

I have a web app which takes over a minute to initialise, reporting
various interesting stats and warnings; if successful, I call
http_daemon, using the output(File) option, but this is too late to
redirect msgs from init.

What is best practice here? If I start the daemon first, might requests
be (mis)handled before the app is ready?

Normally I'd not use --output=file, but use the logging facility of the
daemon manager (e.g., systemd). One way to deal with slow-starting
apps is to setup a temporary handler while you initialize the application.
That is what ClioPatria is doing while restoring the RDF database:

setup_call_cleanup(
    http_handler(root(.), busy_loading,
        [ priority(1000),
          hide_children(true),
          id(busy_loading),
          prefix
        ]),
    rdf_attach_store(QOptions, AfterLoad),
    http_delete_handler(id(busy_loading))).

Here, rdf_attach_store/2 is the slow call. The handler does:

busy_loading(_Request) :-
rdf_statistics(triples(Triples)),
( loading_done(Nth, Total)
-> Extra = [ '; ~D of ~D graphs.'-[Nth, Total] ]
; Extra = [ '.' ]
),
HTML = p([ 'This service is currently restoring its ',
'persistent database.', br([]),
'Loaded ~D triples'-[Triples]
| Extra
]),
throw(http_reply(unavailable(HTML))).

Cheers --- Jan
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant