Temporary solution for make sure storage object gets put back in all cases of execution
This commit is contained in:
parent
9c751aff30
commit
9b4a4eeaf4
@ -191,7 +191,6 @@ func main() {
|
||||
defer stateStore.Close()
|
||||
|
||||
rp := &httpserver.DefaultRequestParser{}
|
||||
//sh := httpserver.NewSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl.Init)
|
||||
bsh := handlers.NewBaseSessionHandler(cfg, rs, stateStore, userdataStore, rp, hl)
|
||||
sh := httpserver.ToSessionHandler(bsh)
|
||||
s := &http.Server{
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module git.grassecon.net/urdt/ussd
|
||||
go 1.22.6
|
||||
|
||||
require (
|
||||
git.defalsify.org/vise.git 0d23e0dbb57fe63b6626527fddc86649cfc20f8f
|
||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f
|
||||
github.com/alecthomas/assert/v2 v2.2.2
|
||||
gopkg.in/leonelquinteros/gotext.v1 v1.3.1
|
||||
)
|
||||
|
4
go.sum
4
go.sum
@ -1,5 +1,5 @@
|
||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911162138-1f2af8672dc7 h1:embPZDx0Sgpq6jp9vcZ1GVI0eum3PsPCmAfxAa/1KLI=
|
||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911162138-1f2af8672dc7/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M=
|
||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f h1:CuJvG3NyMoRtHUim4aZdrfjjJBg2AId7z0yp7Q97bRM=
|
||||
git.defalsify.org/vise.git v0.1.0-rc.3.0.20240911231817-0d23e0dbb57f/go.mod h1:JDguWmcoWBdsnpw7PUjVZAEpdC/ubBmjdUBy3tjP63M=
|
||||
github.com/alecthomas/assert/v2 v2.2.2 h1:Z/iVC0xZfWTaFNE6bA3z07T86hd45Xe2eLt6WVy2bbk=
|
||||
github.com/alecthomas/assert/v2 v2.2.2/go.mod h1:pXcQ2Asjp247dahGEmsZ6ru0UVwnkhktn7S0bBDLxvQ=
|
||||
github.com/alecthomas/participle/v2 v2.0.0 h1:Fgrq+MbuSsJwIkw3fEj9h75vDP0Er5JzepJ0/HNHv0g=
|
||||
|
@ -50,7 +50,7 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
||||
|
||||
rqs.Storage, err = f.provider.Get(rqs.Config.SessionId)
|
||||
if err != nil {
|
||||
logg.ErrorCtxf(rqs.Ctx, "", "storage error", "err", err)
|
||||
logg.ErrorCtxf(rqs.Ctx, "", "storage get error", err)
|
||||
return rqs, ErrStorage
|
||||
}
|
||||
|
||||
@ -58,6 +58,11 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
||||
eni := f.GetEngine(rqs.Config, f.rs, rqs.Storage.Persister)
|
||||
en, ok := eni.(*engine.DefaultEngine)
|
||||
if !ok {
|
||||
perr := f.provider.Put(rqs.Config.SessionId, rqs.Storage)
|
||||
rqs.Storage = nil
|
||||
if perr != nil {
|
||||
logg.ErrorCtxf(rqs.Ctx, "", "storage put error", perr)
|
||||
}
|
||||
return rqs, ErrEngineType
|
||||
}
|
||||
en = en.WithFirst(f.hn.Init)
|
||||
@ -68,6 +73,11 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
||||
|
||||
r, err = rqs.Engine.Init(rqs.Ctx)
|
||||
if err != nil {
|
||||
perr := f.provider.Put(rqs.Config.SessionId, rqs.Storage)
|
||||
rqs.Storage = nil
|
||||
if perr != nil {
|
||||
logg.ErrorCtxf(rqs.Ctx, "", "storage put error", perr)
|
||||
}
|
||||
return rqs, err
|
||||
}
|
||||
|
||||
@ -75,6 +85,11 @@ func(f *BaseSessionHandler) Process(rqs RequestSession) (RequestSession, error)
|
||||
r, err = rqs.Engine.Exec(rqs.Ctx, rqs.Input)
|
||||
}
|
||||
if err != nil {
|
||||
perr := f.provider.Put(rqs.Config.SessionId, rqs.Storage)
|
||||
rqs.Storage = nil
|
||||
if perr != nil {
|
||||
logg.ErrorCtxf(rqs.Ctx, "", "storage put error", perr)
|
||||
}
|
||||
return rqs, err
|
||||
}
|
||||
|
||||
|
@ -32,7 +32,7 @@ type RequestSession struct {
|
||||
Config engine.Config
|
||||
Engine engine.Engine
|
||||
Input []byte
|
||||
Storage storage.Storage
|
||||
Storage *storage.Storage
|
||||
Writer io.Writer
|
||||
}
|
||||
|
||||
|
@ -68,6 +68,7 @@ func(f *SessionHandler) writeError(w http.ResponseWriter, code int, err error) {
|
||||
func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
var code int
|
||||
var err error
|
||||
var perr error
|
||||
|
||||
rqs := handlers.RequestSession{
|
||||
Ctx: req.Context(),
|
||||
@ -109,14 +110,13 @@ func(f *SessionHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) {
|
||||
w.WriteHeader(200)
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
rqs, err = f.Output(rqs)
|
||||
rqs, perr = f.Reset(rqs)
|
||||
if err != nil {
|
||||
f.writeError(w, 500, err)
|
||||
return
|
||||
}
|
||||
|
||||
rqs, err = f.Reset(rqs)
|
||||
if err != nil {
|
||||
f.writeError(w, 500, err)
|
||||
if perr != nil {
|
||||
f.writeError(w, 500, perr)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
@ -11,31 +11,31 @@ type Storage struct {
|
||||
}
|
||||
|
||||
type StorageProvider interface {
|
||||
Get(sessionId string) (Storage, error)
|
||||
Put(sessionId string, storage Storage) error
|
||||
Get(sessionId string) (*Storage, error)
|
||||
Put(sessionId string, storage *Storage) error
|
||||
Close() error
|
||||
}
|
||||
|
||||
type SimpleStorageProvider struct {
|
||||
Storage
|
||||
*Storage
|
||||
}
|
||||
|
||||
func NewSimpleStorageProvider(stateStore db.Db, userdataStore db.Db) StorageProvider {
|
||||
pe := persist.NewPersister(stateStore)
|
||||
pe = pe.WithFlush()
|
||||
return &SimpleStorageProvider{
|
||||
Storage: Storage{
|
||||
Storage: &Storage{
|
||||
Persister: pe,
|
||||
UserdataDb: userdataStore,
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (p *SimpleStorageProvider) Get(sessionId string) (Storage, error) {
|
||||
func (p *SimpleStorageProvider) Get(sessionId string) (*Storage, error) {
|
||||
return p.Storage, nil
|
||||
}
|
||||
|
||||
func (p *SimpleStorageProvider) Put(sessionId string, storage Storage) error {
|
||||
func (p *SimpleStorageProvider) Put(sessionId string, storage *Storage) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user