archied's own build has carried a compiled-in gatewayVersion and an internal/installtype stamp since archie-core-522/b5d08d0, but archie-agent's build had neither -- its Taskfile.yml and Dockerfile build steps passed no -ldflags at all, so even a daemon that wanted to verify what agent build is actually in service had nothing to check against. daemonRunningVersions said as much explicitly: the agent was left out of every verification on purpose, because nothing self-reported a real value. Every archie-agent process is task-scoped and ephemeral (spawned per task, dies after), not a long-lived process the daemon can poll on demand the way it polls Telegram's gateway. So there's no "ask the agent its version" request -- the only channel back is whatever a worker includes in the taskrun.Response it already sends on every completed task. Stamp archie-agent's build the same way archied's is (installtype, plus a new agentworker.Version()), have executeTaskRequest report both in its Response, and have the daemon record the latest observation in a new mutex-guarded AgentStatus, fed from runViaAgent on every successful response only -- never off a request that never reached an agent, or one describing a failed/parked task. daemonRunningVersions now includes the agent component once (and only once) something has actually been observed, so Report.Verify gets a real value to check future update claims against instead of omitting the component entirely. Part 1/3 of archie-core-1786751948782-3-837a8fd0 point 4. Closes archie-core-1786751948782-3-837a8fd0.1.
42 lines
1.5 KiB
Go
42 lines
1.5 KiB
Go
package daemon
|
|
|
|
import "sync"
|
|
|
|
// AgentStatus tracks the most recent version and install type an
|
|
// archie-agent worker reported about itself. It is observed passively, off
|
|
// ordinary taskrun.Response traffic in runViaAgent -- there is no dedicated
|
|
// poll, since every archie-agent process is task-scoped and ephemeral (see
|
|
// docs/architecture and internal/app/agentworker), not a long-lived process
|
|
// the daemon could query on demand the way it can Telegram's gateway.
|
|
//
|
|
// Before the first task completes, nothing is known: Snapshot's ok return
|
|
// reports that honestly rather than a caller guessing a value.
|
|
type AgentStatus struct {
|
|
mu sync.RWMutex
|
|
version string
|
|
installType string
|
|
observed bool
|
|
}
|
|
|
|
// Observe records the version/install-type an archie-agent worker reported
|
|
// in a task response. Called for every completed task, so the value always
|
|
// reflects whichever agent build most recently ran -- the same one that is
|
|
// actually in service, not the version archied's own release pipeline
|
|
// stamped for it (those two can diverge, which is exactly what this exists
|
|
// to catch).
|
|
func (s *AgentStatus) Observe(version, installType string) {
|
|
s.mu.Lock()
|
|
defer s.mu.Unlock()
|
|
s.version = version
|
|
s.installType = installType
|
|
s.observed = true
|
|
}
|
|
|
|
// Snapshot returns the most recently observed version/install-type, and
|
|
// whether any task has reported one yet.
|
|
func (s *AgentStatus) Snapshot() (version, installType string, ok bool) {
|
|
s.mu.RLock()
|
|
defer s.mu.RUnlock()
|
|
return s.version, s.installType, s.observed
|
|
}
|