Integrate tx enabled vise db

This commit is contained in:
lash 2025-01-19 09:46:37 +00:00
parent c719db8b92
commit be47c999ca
Signed by: lash
GPG Key ID: 21D2E7BB88C2A746
14 changed files with 46 additions and 30 deletions

View File

@ -101,7 +101,6 @@ func main() {
fmt.Fprintf(os.Stderr, "userdatadb: %v\n", err)
os.Exit(1)
}
defer userdataStore.Close()
dbResource, ok := rs.(*resource.DbResource)
if !ok {
@ -133,7 +132,6 @@ func main() {
fmt.Fprintf(os.Stderr, "getstatestore: %v\n", err)
os.Exit(1)
}
defer stateStore.Close()
rp := &at.ATRequestParser{}
bsh := request.NewBaseRequestHandler(cfg, rs, stateStore, userdataStore, rp, hl)
@ -146,7 +144,10 @@ func main() {
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
Handler: mux,
}
s.RegisterOnShutdown(sh.Shutdown)
shutdownFunc := func() {
sh.Shutdown(ctx)
}
s.RegisterOnShutdown(shutdownFunc)
cint := make(chan os.Signal)
cterm := make(chan os.Signal)

View File

@ -116,7 +116,7 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer userdataStore.Close()
//defer userdataStore.Close(ctx)
dbResource, ok := rs.(*resource.DbResource)
if !ok {
@ -139,7 +139,7 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer stateStore.Close()
//defer stateStore.Close(ctx)
rp := &asyncRequestParser{
sessionId: sessionId,
@ -161,7 +161,7 @@ func main() {
case _ = <-cint:
case _ = <-cterm:
}
sh.Shutdown()
sh.Shutdown(ctx)
}()
for true {
@ -177,7 +177,7 @@ func main() {
fmt.Errorf("error in output: %v", err)
os.Exit(1)
}
rqs, err = sh.Reset(rqs)
rqs, err = sh.Reset(ctx, rqs)
if err != nil {
logg.ErrorCtxf(ctx, "error in reset: %v", "err", err)
fmt.Errorf("error in reset: %v", err)

View File

@ -101,7 +101,6 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer userdataStore.Close()
dbResource, ok := rs.(*resource.DbResource)
if !ok {
@ -129,7 +128,6 @@ func main() {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)
}
defer stateStore.Close()
//accountService := services.New(ctx, menuStorageService, connData)
@ -140,7 +138,10 @@ func main() {
Addr: fmt.Sprintf("%s:%s", host, strconv.Itoa(int(port))),
Handler: sh,
}
s.RegisterOnShutdown(sh.Shutdown)
shutdownFunc := func() {
sh.Shutdown(ctx)
}
s.RegisterOnShutdown(shutdownFunc)
cint := make(chan os.Signal)
cterm := make(chan os.Signal)

View File

@ -5,7 +5,9 @@ import (
"flag"
"fmt"
"os"
"os/signal"
"path"
"syscall"
"git.defalsify.org/vise.git/engine"
"git.defalsify.org/vise.git/logging"
@ -135,6 +137,18 @@ func main() {
en = en.WithDebug(nil)
}
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:
}
menuStorageService.Close(ctx)
}()
err = engine.Loop(ctx, en, os.Stdin, os.Stdout, nil)
if err != nil {
fmt.Fprintf(os.Stderr, "loop exited with error: %v\n", err)

View File

@ -102,7 +102,7 @@ func main() {
}
defer func() {
logg.TraceCtxf(ctx, "shutdown auth key store reached")
err = authKeyStore.Close()
err = authKeyStore.Close(ctx)
if err != nil {
logg.ErrorCtxf(ctx, "keystore close error", "err", err)
}

View File

@ -34,7 +34,7 @@ func main() {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
defer store.Close()
defer store.Close(ctx)
err = store.AddFromFile(ctx, sshKeyFile, sessionId)
if err != nil {

View File

@ -93,7 +93,7 @@ func main() {
fmt.Printf(r)
}
err = store.Close()
err = store.Close(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, err.Error())
os.Exit(1)

6
go.mod
View File

@ -3,11 +3,11 @@ module git.grassecon.net/grassrootseconomics/sarafu-vise
go 1.23.4
require (
git.defalsify.org/vise.git v0.2.3-0.20250118155735-c1256156ed8b
git.defalsify.org/vise.git v0.2.3-0.20250119084238-8ad1d92d2127
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250119094010-c9b92191f3ad
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250119094241-c3a51127772d
github.com/alecthomas/assert/v2 v2.2.2
github.com/gofrs/uuid v4.4.0+incompatible
github.com/grassrootseconomics/ussd-data-service v1.2.0-beta

12
go.sum
View File

@ -1,13 +1,13 @@
git.defalsify.org/vise.git v0.2.3-0.20250118155735-c1256156ed8b h1:ac6OThj6nqQb3TUyXHqv/vQOQUQZ98XKpYTBHZFbxUI=
git.defalsify.org/vise.git v0.2.3-0.20250118155735-c1256156ed8b/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.defalsify.org/vise.git v0.2.3-0.20250119084238-8ad1d92d2127 h1:4AZoazfzGAHGNMn3kAWsXZQGO3Sme4PYLV8gvMjIZ0A=
git.defalsify.org/vise.git v0.2.3-0.20250119084238-8ad1d92d2127/go.mod h1:jyBMe1qTYUz3mmuoC9JQ/TvFeW0vTanCUcPu3H8p4Ck=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05 h1:BenzGx6aDHKDwE23/mWIFD2InYIXyzHroZWV3MF5WUk=
git.grassecon.net/grassrootseconomics/common v0.0.0-20250113174703-6afccefd1f05/go.mod h1:wgQJZGIS6QuNLHqDhcsvehsbn5PvgV7aziRebMnJi60=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f h1:FgccQi8vipX6dUt+GRiRDYHMR3UqC+plz73vw7y3fyU=
git.grassecon.net/grassrootseconomics/sarafu-api v0.0.0-20250115072214-bca7c5de969f/go.mod h1:tbA4whUGMUIDgQVdIW0sxWPuuXOvZRSny5zeku5hX4k=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63 h1:bX7klKZpX+ZZu1LKbtOXDAhV/KK0YwExehiIi0jusAM=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250115003256-c0534ede1b63/go.mod h1:Syw9TZyigPAM7t9FvicOm36iUnidt45f0SxzT2JniQ8=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d h1:q/NO1rEgK3pia32D/tCq5hXfEuJp84COZRwceFvy/MM=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250113103030-f0b2056fd87d/go.mod h1:AH15xABcvaJr1TCGlih3oGSuwWC0E5IdbHQwuu+E1KI=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250119094010-c9b92191f3ad h1:hZCsa0rHn2r0S1ToaPbPSN05W71dLSndyPYE9J/gv2Y=
git.grassecon.net/grassrootseconomics/visedriver v0.8.0-beta.10.0.20250119094010-c9b92191f3ad/go.mod h1:jukqi0wbhwsVKywcq8XUnjLnLak/iuxpkrUpAOoTJBE=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250119094241-c3a51127772d h1:ikmaRBGMG0KMxZpcO0yC4tyCJkgWrbXkpisl3m1lKoY=
git.grassecon.net/grassrootseconomics/visedriver-africastalking v0.0.0-20250119094241-c3a51127772d/go.mod h1:2EBjn9MKNe3DUep+NljRU/AczgKmRoUwEb6yIO+Atx0=
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=

View File

@ -54,7 +54,7 @@ func InitializeTestStore(t *testing.T) (context.Context, *store.UserDataStore) {
store := &store.UserDataStore{Db: db}
t.Cleanup(func() {
db.Close() // Ensure the DB is closed after each test
db.Close(ctx) // Ensure the DB is closed after each test
})
return ctx, store

View File

@ -63,6 +63,6 @@ func(s *SshKeyStore) Get(ctx context.Context, pubKey ssh.PublicKey) (string, err
return string(v), nil
}
func(s *SshKeyStore) Close() error {
return s.store.Close()
func(s *SshKeyStore) Close(ctx context.Context) error {
return s.store.Close(ctx)
}

View File

@ -194,7 +194,7 @@ func(s *SshRunner) GetEngine(sessionId string) (engine.Engine, func(), error) {
}
// TODO: this is getting very hacky!
closer := func() {
err := menuStorageService.Close()
err := menuStorageService.Close(ctx)
if err != nil {
logg.ErrorCtxf(ctx, "menu storage service cleanup fail", "err", err)
}
@ -268,7 +268,7 @@ func(s *SshRunner) Run(ctx context.Context, keyStore *SshKeyStore) {
return
}
defer func() {
err := en.Finish()
err := en.Finish(ctx)
if err != nil {
logg.ErrorCtxf(ctx, "engine won't stop", "err", err)
}

View File

@ -27,7 +27,7 @@ func InitializeTestDb(t *testing.T) (context.Context, *UserDataStore) {
store := &UserDataStore{Db: db}
t.Cleanup(func() {
db.Close() // Ensure the DB is closed after each test
db.Close(ctx) // Ensure the DB is closed after each test
})
return ctx, store

View File

@ -195,12 +195,12 @@ func TestEngine(sessionId string) (engine.Engine, func(), chan bool) {
en := lhs.GetEngine()
en = en.WithFirst(hl.Init)
cleanFn := func() {
err := en.Finish()
err := en.Finish(ctx)
if err != nil {
logg.Errorf(err.Error())
}
err = menuStorageService.Close()
err = menuStorageService.Close(ctx)
if err != nil {
logg.Errorf(err.Error())
}