Add shutdown to async, rehabilitate http cmd
This commit is contained in:
parent
d49f866ca4
commit
b31d3b907a
@ -5,7 +5,9 @@ import (
|
|||||||
"flag"
|
"flag"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
"path"
|
"path"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"git.defalsify.org/vise.git/asm"
|
"git.defalsify.org/vise.git/asm"
|
||||||
"git.defalsify.org/vise.git/db"
|
"git.defalsify.org/vise.git/db"
|
||||||
@ -210,6 +212,19 @@ func main() {
|
|||||||
Writer: os.Stdout,
|
Writer: os.Stdout,
|
||||||
Config: cfg,
|
Config: cfg,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cint := make(chan os.Signal)
|
||||||
|
cterm := make(chan os.Signal)
|
||||||
|
signal.Notify(cint, os.Interrupt, syscall.SIGINT)
|
||||||
|
signal.Notify(cterm, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
select {
|
||||||
|
case _ = <-cint:
|
||||||
|
case _ = <-cterm:
|
||||||
|
}
|
||||||
|
sh.Shutdown()
|
||||||
|
}()
|
||||||
|
|
||||||
for true {
|
for true {
|
||||||
rqs, err = sh.Process(rqs)
|
rqs, err = sh.Process(rqs)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"git.defalsify.org/vise.git/logging"
|
"git.defalsify.org/vise.git/logging"
|
||||||
|
|
||||||
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
"git.grassecon.net/urdt/ussd/internal/handlers/ussd"
|
||||||
|
"git.grassecon.net/urdt/ussd/internal/handlers"
|
||||||
httpserver "git.grassecon.net/urdt/ussd/internal/http"
|
httpserver "git.grassecon.net/urdt/ussd/internal/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -191,7 +192,8 @@ func main() {
|
|||||||
|
|
||||||
rp := &httpserver.DefaultRequestParser{}
|
rp := &httpserver.DefaultRequestParser{}
|
||||||
//sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl.Init)
|
//sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl.Init)
|
||||||
sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||||
|
sh := httpserver.ToSessionHandler(bsh)
|
||||||
s := &http.Server{
|
s := &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
|
||||||
Handler: sh,
|
Handler: sh,
|
||||||
|
@ -38,6 +38,7 @@ type RequestSession struct {
|
|||||||
|
|
||||||
type engineMaker func(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine
|
type engineMaker func(cfg engine.Config, rs resource.Resource, pr *persist.Persister) engine.Engine
|
||||||
|
|
||||||
|
// TODO: seems like can remove this.
|
||||||
type RequestParser interface {
|
type RequestParser interface {
|
||||||
GetSessionId(rq any) (string, error)
|
GetSessionId(rq any) (string, error)
|
||||||
GetInput(rq any) ([]byte, error)
|
GetInput(rq any) ([]byte, error)
|
||||||
@ -50,5 +51,5 @@ type RequestHandler interface {
|
|||||||
Process(rs RequestSession) (RequestSession, error)
|
Process(rs RequestSession) (RequestSession, error)
|
||||||
Output(rs RequestSession) (RequestSession, error)
|
Output(rs RequestSession) (RequestSession, error)
|
||||||
Reset(rs RequestSession) (RequestSession, error)
|
Reset(rs RequestSession) (RequestSession, error)
|
||||||
ShutDown()
|
Shutdown()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user