fix(master): refuse jobs for revoked agents, signal revoked jobs, agent start time wins (#7)

This commit is contained in:
2026-10-12 19:14:32 +02:00
parent 93ba6915b9
commit c09e774d74
6 changed files with 138 additions and 57 deletions
+7 -2
View File
@@ -36,7 +36,8 @@ type Store interface {
ListJobs(ctx context.Context, f model.JobFilter) ([]model.Job, error)
ListAgents(ctx context.Context) ([]model.Agent, error)
CreateAgent(ctx context.Context, name, tokenHash string) (model.Agent, error)
RevokeAgent(ctx context.Context, id int64, at time.Time) error
// RevokeAgent returns the IDs of the jobs it failed.
RevokeAgent(ctx context.Context, id int64, at time.Time) ([]int64, error)
}
// Hub reports and controls live agent connections. *hub.Hub satisfies it.
@@ -389,13 +390,17 @@ func (s *Server) revokeAgent(w http.ResponseWriter, r *http.Request) {
http.Error(w, "invalid agent id", http.StatusBadRequest)
return
}
if err := s.store.RevokeAgent(r.Context(), id, s.now()); err != nil {
failedJobs, err := s.store.RevokeAgent(r.Context(), id, s.now())
if err != nil {
s.fail(w, err)
return
}
s.hub.Disconnect(id)
s.broker.Publish(events.Services) // the agent's services were marked removed
s.broker.Publish(events.Jobs) // the agent's active jobs were failed
for _, jobID := range failedJobs {
s.broker.Publish(events.JobTopic(jobID)) // open job pages show the failure
}
http.Redirect(w, r, "/agents", http.StatusSeeOther)
}