Lifetime control of webserver

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Lifetime control of webserver

joshchia
Hi,

My application is not a webserver but needs to run a webserver for part but not all of its lifetime. Particularly, there's a part that does some complex computation and I want a webserver to expose its internal state/progress through HTTP.

It seems that the typical and expected way to use a webserver is to designate the entire app itself as a webserver, so that functions like the following are basically infinite loops that serve HTTP:



Can I run a webserver with explicit control of its lifetime? Particularly, I want to be able to kill it without killing the app or explicitly serve one request at a time. I'm not restricted to scotty or warp.

Josh

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime control of webserver

Lyndon Maydwell
Not sure if I'm missing something, but is there any reason why you couldn't spin up the server in a thread then kill it when required?


 - Lyndon

On Fri, Jul 13, 2018 at 11:51 AM ☂Josh Chia (謝任中) <[hidden email]> wrote:
Hi,

My application is not a webserver but needs to run a webserver for part but not all of its lifetime. Particularly, there's a part that does some complex computation and I want a webserver to expose its internal state/progress through HTTP.

It seems that the typical and expected way to use a webserver is to designate the entire app itself as a webserver, so that functions like the following are basically infinite loops that serve HTTP:



Can I run a webserver with explicit control of its lifetime? Particularly, I want to be able to kill it without killing the app or explicitly serve one request at a time. I'm not restricted to scotty or warp.

Josh
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime control of webserver

joshchia
Do you mean something like calling the scotty function in a server thread and then killing the server thread when I want to stop serving? If proper cleanup happens when I kill the thread, this should work for me.

On Fri, Jul 13, 2018 at 10:01 AM Lyndon Maydwell <[hidden email]> wrote:
Not sure if I'm missing something, but is there any reason why you couldn't spin up the server in a thread then kill it when required?


 - Lyndon

On Fri, Jul 13, 2018 at 11:51 AM ☂Josh Chia (謝任中) <[hidden email]> wrote:
Hi,

My application is not a webserver but needs to run a webserver for part but not all of its lifetime. Particularly, there's a part that does some complex computation and I want a webserver to expose its internal state/progress through HTTP.

It seems that the typical and expected way to use a webserver is to designate the entire app itself as a webserver, so that functions like the following are basically infinite loops that serve HTTP:



Can I run a webserver with explicit control of its lifetime? Particularly, I want to be able to kill it without killing the app or explicitly serve one request at a time. I'm not restricted to scotty or warp.

Josh
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime control of webserver

Lyndon Maydwell
Yes that's what I had in mind.

You can do some fun things with Control.Concurrent.Chan as well if you need special sequencing, or limits on requests served or callbacks into the main thread etc.

 - Lyndon

On Fri, Jul 13, 2018 at 12:32 PM ☂Josh Chia (謝任中) <[hidden email]> wrote:
Do you mean something like calling the scotty function in a server thread and then killing the server thread when I want to stop serving? If proper cleanup happens when I kill the thread, this should work for me.

On Fri, Jul 13, 2018 at 10:01 AM Lyndon Maydwell <[hidden email]> wrote:
Not sure if I'm missing something, but is there any reason why you couldn't spin up the server in a thread then kill it when required?


 - Lyndon

On Fri, Jul 13, 2018 at 11:51 AM ☂Josh Chia (謝任中) <[hidden email]> wrote:
Hi,

My application is not a webserver but needs to run a webserver for part but not all of its lifetime. Particularly, there's a part that does some complex computation and I want a webserver to expose its internal state/progress through HTTP.

It seems that the typical and expected way to use a webserver is to designate the entire app itself as a webserver, so that functions like the following are basically infinite loops that serve HTTP:



Can I run a webserver with explicit control of its lifetime? Particularly, I want to be able to kill it without killing the app or explicitly serve one request at a time. I'm not restricted to scotty or warp.

Josh
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Lifetime control of webserver

Doug Burke-2

You could also look at ekg for "inspiration" (at least for the "expose data via a URL" part): http://hackage.haskell.org/package/ekg

Doug

On Thu, Jul 12, 2018 at 10:55 PM Lyndon Maydwell <[hidden email]> wrote:
Yes that's what I had in mind.

You can do some fun things with Control.Concurrent.Chan as well if you need special sequencing, or limits on requests served or callbacks into the main thread etc.


 - Lyndon

On Fri, Jul 13, 2018 at 12:32 PM ☂Josh Chia (謝任中) <[hidden email]> wrote:
Do you mean something like calling the scotty function in a server thread and then killing the server thread when I want to stop serving? If proper cleanup happens when I kill the thread, this should work for me.

On Fri, Jul 13, 2018 at 10:01 AM Lyndon Maydwell <[hidden email]> wrote:
Not sure if I'm missing something, but is there any reason why you couldn't spin up the server in a thread then kill it when required?


 - Lyndon

On Fri, Jul 13, 2018 at 11:51 AM ☂Josh Chia (謝任中) <[hidden email]> wrote:
Hi,

My application is not a webserver but needs to run a webserver for part but not all of its lifetime. Particularly, there's a part that does some complex computation and I want a webserver to expose its internal state/progress through HTTP.

It seems that the typical and expected way to use a webserver is to designate the entire app itself as a webserver, so that functions like the following are basically infinite loops that serve HTTP:



Can I run a webserver with explicit control of its lifetime? Particularly, I want to be able to kill it without killing the app or explicitly serve one request at a time. I'm not restricted to scotty or warp.

Josh
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.