From 26a2a63d8342e164c2adca7d1097815ea61da6b1 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Wed, 31 May 2023 00:37:51 -0600 Subject: [PATCH] Removed graphql dependency --- event.go | 7 +++---- graph.go | 11 +++++------ manager.go | 9 ++++----- resource.go | 2 +- vex.go | 41 +++++++++++++++++++++-------------------- 5 files changed, 34 insertions(+), 36 deletions(-) diff --git a/event.go b/event.go index 083ce11..787aea6 100644 --- a/event.go +++ b/event.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "errors" - graphql "github.com/graph-gophers/graphql-go" "reflect" "sort" ) @@ -54,7 +53,7 @@ type Event interface { RequiredResources() []Resource DoneResource() Resource AddChild(child Event, info EventInfo) error - FindChild(id graphql.ID) Event + FindChild(id string) Event Run() error Abort() error Signal(action string) error @@ -177,7 +176,7 @@ func NewBaseEvent(name string, description string, required_resources []Resource BaseNode: BaseNode{ name: name, description: description, - id: gql_randid(), + id: randid(), listeners: []chan error{}, }, parent: nil, @@ -315,7 +314,7 @@ func (event * BaseEvent) ChildInfo(idx Event) EventInfo { return val } -func (event * BaseEvent) FindChild(id graphql.ID) Event { +func (event * BaseEvent) FindChild(id string) Event { if id == event.ID() { return event } diff --git a/graph.go b/graph.go index a727a53..3f5b30b 100644 --- a/graph.go +++ b/graph.go @@ -3,21 +3,20 @@ package main import ( "errors" "sync" - graphql "github.com/graph-gophers/graphql-go" "github.com/google/uuid" ) // Generate a random graphql id -func gql_randid() graphql.ID{ +func randid() string{ uuid_str := uuid.New().String() - return graphql.ID(uuid_str) + return uuid_str } // GraphNode is the interface common to both DAG nodes and Event tree nodes type GraphNode interface { Name() string Description() string - ID() graphql.ID + ID() string UpdateListeners() error UpdateChannel() chan error Update() error @@ -28,7 +27,7 @@ type GraphNode interface { type BaseNode struct { name string description string - id graphql.ID + id string listeners []chan error listeners_lock sync.Mutex } @@ -41,7 +40,7 @@ func (node * BaseNode) Description() string { return node.description } -func (node * BaseNode) ID() graphql.ID { +func (node * BaseNode) ID() string { return node.id } diff --git a/manager.go b/manager.go index 9ebacee..31f1527 100644 --- a/manager.go +++ b/manager.go @@ -4,11 +4,10 @@ import ( "fmt" "log" "errors" - graphql "github.com/graph-gophers/graphql-go" ) type EventManager struct { - dag_nodes map[graphql.ID]Resource + dag_nodes map[string]Resource root_event Event } @@ -16,7 +15,7 @@ type EventManager struct { func NewEventManager(root_event Event, dag_nodes []Resource) * EventManager { manager := &EventManager{ - dag_nodes: map[graphql.ID]Resource{}, + dag_nodes: map[string]Resource{}, root_event: nil, } @@ -41,7 +40,7 @@ func (manager * EventManager) Run() error { return manager.root_event.Run() } -func (manager * EventManager) FindResource(id graphql.ID) Resource { +func (manager * EventManager) FindResource(id string) Resource { resource, exists := manager.dag_nodes[id] if exists == false { return nil @@ -50,7 +49,7 @@ func (manager * EventManager) FindResource(id graphql.ID) Resource { return resource } -func (manager * EventManager) FindEvent(id graphql.ID) Event { +func (manager * EventManager) FindEvent(id string) Event { event := manager.root_event.FindChild(id) return event diff --git a/resource.go b/resource.go index ef6c636..8f21ce3 100644 --- a/resource.go +++ b/resource.go @@ -153,7 +153,7 @@ func NewResource(name string, description string, children []Resource) * BaseRes BaseNode: BaseNode{ name: name, description: description, - id: gql_randid(), + id: randid(), listeners: []chan error{}, }, parents: []Resource{}, diff --git a/vex.go b/vex.go index aeb350b..bbde665 100644 --- a/vex.go +++ b/vex.go @@ -3,19 +3,11 @@ package main import ( "fmt" "log" + "time" ) -type ArenaDriver interface { - -} - -type VirtualArenaDriver struct { - -} - type Arena struct { BaseResource - driver ArenaDriver } func NewVirtualArena(name string) * Arena { @@ -24,13 +16,12 @@ func NewVirtualArena(name string) * Arena { BaseNode: BaseNode{ name: name, description: "A virtual vex arena", - id: gql_randid(), + id: randid(), listeners: []chan error{}, }, parents: []Resource{}, children: []Resource{}, }, - driver: VirtualArenaDriver{}, } return arena @@ -46,7 +37,7 @@ func NewMember(name string) * Member { BaseNode: BaseNode{ name: name, description: "A Team Member", - id: gql_randid(), + id: randid(), listeners: []chan error{}, }, parents: []Resource{}, @@ -80,7 +71,7 @@ func NewTeam(org string, team string, members []*Member) * Team { BaseNode: BaseNode{ name: name, description: description, - id: gql_randid(), + id: randid(), listeners: []chan error{}, }, parents: []Resource{}, @@ -108,7 +99,7 @@ func NewAlliance(team0 * Team, team1 * Team) * Alliance { BaseNode: BaseNode{ name: name, description: description, - id: gql_randid(), + id: randid(), listeners: []chan error{}, }, parents: []Resource{}, @@ -121,8 +112,12 @@ func NewAlliance(team0 * Team, team1 * Team) * Alliance { type Match struct { BaseEvent state string + control string + control_start time.Time } +const start_slack = 3000 * time.Millisecond + func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena * Arena) * Match { name := fmt.Sprintf("Match: %s vs. %s", alliance0.Name(), alliance1.Name() ) description := "A vex match" @@ -130,22 +125,28 @@ func NewMatch(alliance0 * Alliance, alliance1 * Alliance, arena * Arena) * Match match := &Match{ BaseEvent: NewBaseEvent(name, description, []Resource{alliance0, alliance1, arena}), state: "init", + control: "init", + control_start: time.UnixMilli(0), } match.LockDone() match.actions["start"] = func() (string, error) { - // put the match into "scheduled" state log.Printf("Starting match") + match.control = "none" match.state = "scheduled" return "wait", nil } + match.actions["queue_autonomous"] = func() (string, error) { + match.control = "none" + match.state = "autonomous_queued" + match.control_start = time.Now().Add(start_slack) + return "wait", nil + } + match.actions["start_autonomous"] = func() (string, error) { - if match.state != "scheduled" { - log.Printf("Cannot start_autonomous when the match is in %s", match.state) - return "wait", nil - } - log.Printf("Starting autonomous") + match.control = "autonomous" + match.state = "autonomous_running" return "wait", nil }