add better task and agent work status to cli
This commit is contained in:
parent
b97bfcbc6f
commit
5e80e9e496
|
@ -40,7 +40,7 @@
|
||||||
(define (call-with-server-connection func)
|
(define (call-with-server-connection func)
|
||||||
(match-define (list client-node server-node) (call-with-input-file *client-key-file* read))
|
(match-define (list client-node server-node) (call-with-input-file *client-key-file* read))
|
||||||
|
|
||||||
(define (noshutdown)
|
(define (no-shutdown)
|
||||||
(current-to-node server-node)
|
(current-to-node server-node)
|
||||||
(current-comms (make-comms client-node))
|
(current-comms (make-comms client-node))
|
||||||
(current-tm (make-transaction-manager client-node (current-comms)))
|
(current-tm (make-transaction-manager client-node (current-comms)))
|
||||||
|
@ -51,7 +51,9 @@
|
||||||
(tm-shutdown (current-tm))
|
(tm-shutdown (current-tm))
|
||||||
(comms-shutdown (current-comms)))
|
(comms-shutdown (current-comms)))
|
||||||
|
|
||||||
(dynamic-wind noshutdown func shutdown))
|
;; here's my absolutely genius naming scheme for networking stuff it's "shutdown" and
|
||||||
|
;; "no shutdown" yes i'm an employee of Sysco Corporation™
|
||||||
|
(dynamic-wind no-shutdown func shutdown))
|
||||||
|
|
||||||
(define-simple-macro (with-server-connection body ...+)
|
(define-simple-macro (with-server-connection body ...+)
|
||||||
#:with no-hygiene
|
#:with no-hygiene
|
||||||
|
@ -171,12 +173,13 @@
|
||||||
(define projects
|
(define projects
|
||||||
(with-server-connection
|
(with-server-connection
|
||||||
(get-projects)))
|
(get-projects)))
|
||||||
(cons '("project id" "name" "progress" "matches")
|
(cons '("project id" "name" "progress" "matches" "active agents")
|
||||||
(let ([body (for/list ([proj (in-list projects)])
|
(let ([body (for/list ([proj (in-list projects)])
|
||||||
(list (~a (project-info-id proj))
|
(list (~a (project-info-id proj))
|
||||||
(project-info-name proj)
|
(project-info-name proj)
|
||||||
(format "~a%" (inexact->exact (* 100 (project-info-progress proj))))
|
(format "~a%" (inexact->exact (* 100 (project-info-progress proj))))
|
||||||
(~a (project-info-matches proj))))])
|
(~a (project-info-matches proj))
|
||||||
|
(~a (project-info-agent-state proj))))])
|
||||||
(if (empty? body)
|
(if (empty? body)
|
||||||
'(("" " - no projects - " "" ""))
|
'(("" " - no projects - " "" ""))
|
||||||
body))))
|
body))))
|
||||||
|
@ -210,16 +213,29 @@
|
||||||
|
|
||||||
|
|
||||||
(define (cmd-agent-list)
|
(define (cmd-agent-list)
|
||||||
(define agents (with-server-connection (get-agents)))
|
(define-values [agents projects]
|
||||||
|
(with-server-connection
|
||||||
|
(values (get-agents) (get-projects))))
|
||||||
(cons '("id" "name" "arch" "resources" "status")
|
(cons '("id" "name" "arch" "resources" "status")
|
||||||
(if (empty? agents)
|
(if (empty? agents)
|
||||||
'(("" " - no agents - " "" "" ""))
|
'(("" " - no agents - " "" "" ""))
|
||||||
(for/list ([info (in-list agents)])
|
(for/list ([info (in-list agents)])
|
||||||
|
(define detailed-status
|
||||||
|
(if (node-info-online? info)
|
||||||
|
(let ([assignments
|
||||||
|
(for/list ([proj (in-list projects)]
|
||||||
|
#:when (member (node-info-id info)
|
||||||
|
(project-info-agent-state proj)))
|
||||||
|
(project-info-id proj))])
|
||||||
|
(if (empty? assignments)
|
||||||
|
"online, idle"
|
||||||
|
(format "working on ~a" assignments)))
|
||||||
|
"OFFLINE"))
|
||||||
(list (~a (node-info-id info))
|
(list (~a (node-info-id info))
|
||||||
(~a (node-info-name info))
|
(~a (node-info-name info))
|
||||||
(~a (node-info-arch info))
|
(~a (node-info-arch info))
|
||||||
(~a (string-join (map ~a (sort (node-info-resources info) string<?)) ", "))
|
(~a (string-join (map ~a (sort (node-info-resources info) string<?)) ", "))
|
||||||
(if (node-info-online? info) "ONLINE" "OFFLINE"))))))
|
detailed-status)))))
|
||||||
|
|
||||||
(define (cmd-agent-create name arch resources out-port)
|
(define (cmd-agent-create name arch resources out-port)
|
||||||
(with-server-connection
|
(with-server-connection
|
||||||
|
|
|
@ -44,5 +44,5 @@
|
||||||
|
|
||||||
(struct node-info [id name arch type resources online?] #:prefab)
|
(struct node-info [id name arch type resources online?] #:prefab)
|
||||||
;; manifest is the raw source format
|
;; manifest is the raw source format
|
||||||
(struct project-info [id name manifest progress matches] #:prefab)
|
(struct project-info [id name manifest progress matches agent-state] #:prefab)
|
||||||
(provide (struct-out node-info) (struct-out project-info))
|
(provide (struct-out node-info) (struct-out project-info))
|
||||||
|
|
|
@ -327,6 +327,12 @@
|
||||||
(integer-set-count sub)))
|
(integer-set-count sub)))
|
||||||
(/ completed-size total-size))
|
(/ completed-size total-size))
|
||||||
|
|
||||||
|
;; map of task id to list of agent ids (that are actively working on an assignment in this task)
|
||||||
|
;; TODO : provide a more detailed view of individual projects tbh. work log, match log, error log
|
||||||
|
;; (this doesn't exist yet lol), which agents are able to do it, which agents gave up because of
|
||||||
|
;; errors (also not implemented)
|
||||||
|
(define agent-states (agent-handler-get-status))
|
||||||
|
|
||||||
(for/list ([(id name manifest complete?) (in-query (current-db) q-get-tasks)])
|
(for/list ([(id name manifest complete?) (in-query (current-db) q-get-tasks)])
|
||||||
(define mf (fasl->s-exp manifest))
|
(define mf (fasl->s-exp manifest))
|
||||||
;; XXX this should be a join t b h
|
;; XXX this should be a join t b h
|
||||||
|
@ -336,7 +342,7 @@
|
||||||
;; XXX this could also _maybe_ be a join but idk
|
;; XXX this could also _maybe_ be a join but idk
|
||||||
(get-progress id mf)
|
(get-progress id mf)
|
||||||
1.0))
|
1.0))
|
||||||
(project-info id name mf progress matches)))
|
(project-info id name mf progress matches (hash-ref agent-states id '()))))
|
||||||
|
|
||||||
(define/contract (get-project-file taskid)
|
(define/contract (get-project-file taskid)
|
||||||
(-> integer? bytes?)
|
(-> integer? bytes?)
|
||||||
|
@ -834,6 +840,12 @@
|
||||||
(cons 'agent-report (cons assignment-id state)))]
|
(cons 'agent-report (cons assignment-id state)))]
|
||||||
[(cons 'cancel-task task-id)
|
[(cons 'cancel-task task-id)
|
||||||
(handle-stop-task task-id)]
|
(handle-stop-task task-id)]
|
||||||
|
[(cons 'get-status ch)
|
||||||
|
(channel-put
|
||||||
|
ch
|
||||||
|
(for/hash ([(tid ts) (in-hash current-tasks)])
|
||||||
|
(define agent-ids (hash-keys (task-state-agent-todo ts)))
|
||||||
|
(values tid agent-ids)))]
|
||||||
['shutdown
|
['shutdown
|
||||||
(for ([(id _) (in-hash agents)])
|
(for ([(id _) (in-hash agents)])
|
||||||
(handle-delete-agent id))
|
(handle-delete-agent id))
|
||||||
|
@ -868,6 +880,11 @@
|
||||||
(define (agent-handler-cancel-task task-id [ah (current-agent-handler)])
|
(define (agent-handler-cancel-task task-id [ah (current-agent-handler)])
|
||||||
(thread-send ah (cons 'cancel-task task-id)))
|
(thread-send ah (cons 'cancel-task task-id)))
|
||||||
|
|
||||||
|
(define (agent-handler-get-status [ah (current-agent-handler)])
|
||||||
|
(define ch (make-channel))
|
||||||
|
(thread-send ah (cons 'get-status ch))
|
||||||
|
(channel-get ch))
|
||||||
|
|
||||||
(define (agent-handler-shutdown [ah (current-agent-handler)])
|
(define (agent-handler-shutdown [ah (current-agent-handler)])
|
||||||
(thread-send ah 'shutdown)
|
(thread-send ah 'shutdown)
|
||||||
(thread-wait ah))
|
(thread-wait ah))
|
||||||
|
|
Loading…
Reference in New Issue