work in progress: matrix.connect()
This commit is contained in:
parent
e21499234b
commit
fbff96dcc0
5 changed files with 20 additions and 12 deletions
|
@ -40,7 +40,9 @@ func Select(ctx lib.Context, msg lib.Message) []lib.Action {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// if len(acts) == 0 { logging.Warn().... }
|
if len(acts) == 0 {
|
||||||
|
logging.WarnM(ctx, msg).Msg("action.Select: no match")
|
||||||
|
}
|
||||||
return acts
|
return acts
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,7 +34,7 @@ func Step(ctx lib.Context) (loop bool) {
|
||||||
|
|
||||||
func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) {
|
func HandleMessage(ctx lib.Context, msg lib.Message) (loop bool) {
|
||||||
loop = true
|
loop = true
|
||||||
logging.Debug(ctx).Str("msg.action", msg.Action()).Msg("core.HandleMessage")
|
logging.DebugM(ctx, msg).Msg("core.HandleMessage")
|
||||||
for _, act := range action.Select(ctx, msg) {
|
for _, act := range action.Select(ctx, msg) {
|
||||||
loop = act.Handle()
|
loop = act.Handle()
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@ func WithMessage(ctx lib.Context, msg lib.Message, e *Evt) *Evt {
|
||||||
if e == nil {
|
if e == nil {
|
||||||
return e
|
return e
|
||||||
}
|
}
|
||||||
return WithContext(ctx, e).Str("action", msg.Action())
|
return WithContext(ctx, e).Str("msg", msg.String())
|
||||||
}
|
}
|
||||||
|
|
||||||
func DebugM(ctx lib.Context, msg lib.Message) *Evt {
|
func DebugM(ctx lib.Context, msg lib.Message) *Evt {
|
||||||
|
|
|
@ -4,7 +4,6 @@ import (
|
||||||
lib "git.sr.ht/~cco/go-scopes"
|
lib "git.sr.ht/~cco/go-scopes"
|
||||||
"git.sr.ht/~cco/go-scopes/config"
|
"git.sr.ht/~cco/go-scopes/config"
|
||||||
"git.sr.ht/~cco/go-scopes/core/action"
|
"git.sr.ht/~cco/go-scopes/core/action"
|
||||||
"git.sr.ht/~cco/go-scopes/core/message"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func DefaultConfig(name string) lib.Config {
|
func DefaultConfig(name string) lib.Config {
|
||||||
|
@ -14,11 +13,14 @@ func DefaultConfig(name string) lib.Config {
|
||||||
}
|
}
|
||||||
|
|
||||||
func create(act lib.Action) bool {
|
func create(act lib.Action) bool {
|
||||||
|
ctx := act.Context()
|
||||||
|
spec := act.Spec()
|
||||||
msg := act.Message()
|
msg := act.Message()
|
||||||
//spec := act.ActionSpec()
|
cctx := createCell(ctx)
|
||||||
cctx := createCell(act.Context())
|
//nmsg := message.New("matrix", "connect").WithSender(cctx)
|
||||||
nmsg := message.New("matrix", "connect").WithSender(cctx)
|
//msg.Sender().Cell().Send(nmsg)
|
||||||
msg.Sender().Cell().Send(nmsg)
|
connect(ctx, cctx, spec, msg)
|
||||||
|
connect(cctx, msg.Sender().Cell(), spec, msg)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,3 +30,6 @@ func createCell(ctx lib.Context) lib.Context {
|
||||||
cfg.Starter()(cctx)
|
cfg.Starter()(cctx)
|
||||||
return cctx
|
return cctx
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func connect(src, tgt lib.Context, spec lib.ActionSpec, msg lib.Message) {
|
||||||
|
}
|
||||||
|
|
|
@ -16,15 +16,16 @@ func TestMatrixApp(tb *tbase.T) {
|
||||||
t := testing.SetUpApp(tb, etc.ConfigMx())
|
t := testing.SetUpApp(tb, etc.ConfigMx())
|
||||||
t.Run("app-matrix", MxTest)
|
t.Run("app-matrix", MxTest)
|
||||||
t.TearDownApp("matrix")
|
t.TearDownApp("matrix")
|
||||||
t.AssertEqual(t.LogCheck(logfile, true), 8)
|
t.AssertEqual(t.LogCheck(logfile, true), 7)
|
||||||
}
|
}
|
||||||
|
|
||||||
func MxTest(t *testing.T) {
|
func MxTest(t *testing.T) {
|
||||||
ctx := t.Ctx
|
ctx := t.Ctx
|
||||||
t.AssertEqual(len(ctx.Services()), 3)
|
t.AssertEqual(len(ctx.Services()), 3)
|
||||||
rcvr := ctx.Services()["cell-0"]
|
c0 := ctx.Services()["cell-0"]
|
||||||
msg := message.SimpleMessage("create").WithSender(rcvr)
|
rcvr := ctx.Services()["test-receiver"]
|
||||||
rcvr.Send(msg)
|
msg := message.New("matrix", "create").WithSender(rcvr)
|
||||||
|
c0.Send(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// action handlers
|
// action handlers
|
||||||
|
|
Loading…
Add table
Reference in a new issue