Simplified changes

gql_cataclysm
noah metz 2023-10-07 23:08:18 -06:00
parent 302f0f42fe
commit 7234b11643
3 changed files with 27 additions and 53 deletions

@ -1331,7 +1331,7 @@ func (ext *GQLExt) Process(ctx *Context, node *Node, source NodeID, signal Signa
case *StartSignal: case *StartSignal:
ctx.Log.Logf("gql", "starting gql server %s", node.ID) ctx.Log.Logf("gql", "starting gql server %s", node.ID)
err := ext.StartGQLServer(ctx, node) err := ext.StartGQLServer(ctx, node)
changes = changes.AddDetail(GQLExtType, "", "server_started") changes = changes.Add("server_started")
if err == nil { if err == nil {
node.QueueSignal(time.Now(), NewStatusSignal(node.ID, "server_started")) node.QueueSignal(time.Now(), NewStatusSignal(node.ID, "server_started"))
} else { } else {

@ -72,7 +72,7 @@ func (ext *LockableExt) HandleErrorSignal(ctx *Context, node *Node, source NodeI
var changes Changes = nil var changes Changes = nil
switch str { switch str {
case "not_unlocked": case "not_unlocked":
changes = changes.Add(LockableExtType, "requirements") changes = changes.Add("requirements")
if ext.State == Locking { if ext.State == Locking {
ext.State = AbortingLock ext.State = AbortingLock
req_info := ext.Requirements[source] req_info := ext.Requirements[source]
@ -117,7 +117,7 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID
Unlocked, Unlocked,
uuid.UUID{}, uuid.UUID{},
} }
changes = changes.Add(LockableExtType, "requirements") changes = changes.Add("requirements")
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), source) messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), source)
} }
case "remove": case "remove":
@ -126,7 +126,7 @@ func (ext *LockableExt) HandleLinkSignal(ctx *Context, node *Node, source NodeID
messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "can't link: not_requirement"), source) messages = messages.Add(ctx, node.ID, node.Key, NewErrorSignal(signal.ID(), "can't link: not_requirement"), source)
} else { } else {
delete(ext.Requirements, signal.NodeID) delete(ext.Requirements, signal.NodeID)
changes = changes.Add(LockableExtType, "requirements") changes = changes.Add("requirements")
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), source) messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), source)
} }
default: default:
@ -154,7 +154,7 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
} else if info.MsgID != signal.ReqID { } else if info.MsgID != signal.ReqID {
ctx.Log.Logf("lockable", "Got success for wrong signal for %s: %s, expecting %s", source, signal.ReqID, info.MsgID) ctx.Log.Logf("lockable", "Got success for wrong signal for %s: %s, expecting %s", source, signal.ReqID, info.MsgID)
} else { } else {
changes = changes.Add(LockableExtType, "requirements") changes = changes.Add("requirements")
if info.State == Locking { if info.State == Locking {
if ext.State == Locking { if ext.State == Locking {
info.State = Locked info.State = Locked
@ -173,9 +173,9 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
ctx.Log.Logf("lockable", "WHOLE LOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner) ctx.Log.Logf("lockable", "WHOLE LOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner)
ext.State = Locked ext.State = Locked
ext.Owner = ext.PendingOwner ext.Owner = ext.PendingOwner
changes = changes.Add(LockableExtType, "state") changes = changes.Add("state")
changes = changes.Add(LockableExtType, "owner") changes = changes.Add("owner")
changes = changes.Add(LockableExtType, "pending_owner") changes = changes.Add("pending_owner")
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), *ext.Owner) messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), *ext.Owner)
} else { } else {
ctx.Log.Logf("lockable", "PARTIAL LOCK: %s - %d/%d", node.ID, locked, reqs) ctx.Log.Logf("lockable", "PARTIAL LOCK: %s - %d/%d", node.ID, locked, reqs)
@ -203,17 +203,17 @@ func (ext *LockableExt) HandleSuccessSignal(ctx *Context, node *Node, source Nod
if unlocked == reqs { if unlocked == reqs {
old_state := ext.State old_state := ext.State
ext.State = Unlocked ext.State = Unlocked
changes = changes.Add(LockableExtType, "state") changes = changes.Add("state")
ctx.Log.Logf("lockable", "WHOLE UNLOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner) ctx.Log.Logf("lockable", "WHOLE UNLOCK: %s - %s - %+v", node.ID, ext.PendingID, ext.PendingOwner)
if old_state == Unlocking { if old_state == Unlocking {
previous_owner := *ext.Owner previous_owner := *ext.Owner
ext.Owner = ext.PendingOwner ext.Owner = ext.PendingOwner
ext.ReqID = nil ext.ReqID = nil
changes = changes.Add(LockableExtType, "owner") changes = changes.Add("owner")
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), previous_owner) messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(ext.PendingID), previous_owner)
} else if old_state == AbortingLock { } else if old_state == AbortingLock {
messages = messages.Add(ctx ,node.ID, node.Key, NewErrorSignal(*ext.ReqID, "not_unlocked"), *ext.PendingOwner) messages = messages.Add(ctx ,node.ID, node.Key, NewErrorSignal(*ext.ReqID, "not_unlocked"), *ext.PendingOwner)
changes = changes.Add(LockableExtType, "pending_owner") changes = changes.Add("pending_owner")
ext.PendingOwner = ext.Owner ext.PendingOwner = ext.Owner
} }
} else { } else {
@ -240,9 +240,9 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
new_owner := source new_owner := source
ext.PendingOwner = &new_owner ext.PendingOwner = &new_owner
ext.Owner = &new_owner ext.Owner = &new_owner
changes = changes.Add(LockableExtType, "state") changes = changes.Add("state")
changes = changes.Add(LockableExtType, "pending_owner") changes = changes.Add("pending_owner")
changes = changes.Add(LockableExtType, "owner") changes = changes.Add("owner")
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner) messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner)
} else { } else {
ext.State = Locking ext.State = Locking
@ -251,9 +251,9 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
new_owner := source new_owner := source
ext.PendingOwner = &new_owner ext.PendingOwner = &new_owner
ext.PendingID = signal.ID() ext.PendingID = signal.ID()
changes = changes.Add(LockableExtType, "state") changes = changes.Add("state")
changes = changes.Add(LockableExtType, "pending_owner") changes = changes.Add("pending_owner")
changes = changes.Add(LockableExtType, "requirements") changes = changes.Add("requirements")
for id, info := range(ext.Requirements) { for id, info := range(ext.Requirements) {
if info.State != Unlocked { if info.State != Unlocked {
ctx.Log.Logf("lockable", "REQ_NOT_UNLOCKED_WHEN_LOCKING") ctx.Log.Logf("lockable", "REQ_NOT_UNLOCKED_WHEN_LOCKING")
@ -275,9 +275,9 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
new_owner := source new_owner := source
ext.PendingOwner = nil ext.PendingOwner = nil
ext.Owner = nil ext.Owner = nil
changes = changes.Add(LockableExtType, "state") changes = changes.Add("state")
changes = changes.Add(LockableExtType, "owner") changes = changes.Add("owner")
changes = changes.Add(LockableExtType, "pending_owner") changes = changes.Add("pending_owner")
messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner) messages = messages.Add(ctx, node.ID, node.Key, NewSuccessSignal(signal.ID()), new_owner)
} else if source == *ext.Owner { } else if source == *ext.Owner {
ext.State = Unlocking ext.State = Unlocking
@ -285,9 +285,9 @@ func (ext *LockableExt) HandleLockSignal(ctx *Context, node *Node, source NodeID
ext.ReqID = &id ext.ReqID = &id
ext.PendingOwner = nil ext.PendingOwner = nil
ext.PendingID = signal.ID() ext.PendingID = signal.ID()
changes = changes.Add(LockableExtType, "requirements") changes = changes.Add("requirements")
changes = changes.Add(LockableExtType, "pending_owner") changes = changes.Add("pending_owner")
changes = changes.Add(LockableExtType, "state") changes = changes.Add("state")
for id, info := range(ext.Requirements) { for id, info := range(ext.Requirements) {
if info.State != Locked { if info.State != Locked {
ctx.Log.Logf("lockable", "REQ_NOT_LOCKED_WHEN_UNLOCKING") ctx.Log.Logf("lockable", "REQ_NOT_LOCKED_WHEN_UNLOCKING")

@ -47,28 +47,10 @@ func RandID() NodeID {
return NodeID(uuid.New()) return NodeID(uuid.New())
} }
type Change struct { type Changes []string
Extension ExtType
Field string
Detail string
}
type Changes []Change
func (changes Changes) Add(ext ExtType, field string) Changes { func (changes Changes) Add(detail string) Changes {
return append(changes, Change{ return append(changes, detail)
Extension: ext,
Field: field,
Detail: "",
})
}
func (changes Changes) AddDetail(ext ExtType, field string, detail string) Changes {
return append(changes, Change{
Extension: ext,
Field: field,
Detail: detail,
})
} }
// Extensions are data attached to nodes that process signals // Extensions are data attached to nodes that process signals
@ -538,15 +520,7 @@ func (node *Node) Stop(ctx *Context) error {
} }
func (node *Node) QueueChanges(ctx *Context, changes Changes) error { func (node *Node) QueueChanges(ctx *Context, changes Changes) error {
change_map := map[ExtType][]string{} node.QueueSignal(time.Now(), NewStatusSignal(node.ID, fmt.Sprintf("%+v", changes)))
for _, change := range(changes) {
_, exists := change_map[change.Extension]
if exists == false {
change_map[change.Extension] = []string{}
}
change_map[change.Extension] = append(change_map[change.Extension], change.Field)
}
node.QueueSignal(time.Now(), NewStatusSignal(node.ID, fmt.Sprintf("%+v", change_map)))
return nil return nil
} }