Compare commits
1 Commits
78b1ec5181
...
bc1ab7b6ea
| Author | SHA1 | Date | |
|---|---|---|---|
| bc1ab7b6ea |
@@ -158,6 +158,9 @@ func (s *Scheduler) tickForAgent(ctx context.Context, agent ReportableAgent, now
|
|||||||
chosen = slot
|
chosen = slot
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
s.host.Log("info", "calendar slot selection", map[string]any{
|
||||||
|
"agent": agent.ID, "available": len(resp.Slots), "chosen": chosen != nil,
|
||||||
|
})
|
||||||
if chosen != nil {
|
if chosen != nil {
|
||||||
s.dispatchSlot(ctx, agent.ID, *chosen)
|
s.dispatchSlot(ctx, agent.ID, *chosen)
|
||||||
}
|
}
|
||||||
@@ -173,14 +176,19 @@ func (s *Scheduler) tickForAgent(ctx context.Context, agent ReportableAgent, now
|
|||||||
// transition immediately.
|
// transition immediately.
|
||||||
func (s *Scheduler) dispatchSlot(ctx context.Context, agentID string, slot Slot) {
|
func (s *Scheduler) dispatchSlot(ctx context.Context, agentID string, slot Slot) {
|
||||||
ident := slot.SlotIdent()
|
ident := slot.SlotIdent()
|
||||||
|
s.host.Log("info", "calendar dispatchSlot enter", map[string]any{
|
||||||
|
"agent": agentID, "slot_ident": ident,
|
||||||
|
})
|
||||||
s.mu.Lock()
|
s.mu.Lock()
|
||||||
if _, dup := s.activeBySlotIdent[ident]; dup {
|
if _, dup := s.activeBySlotIdent[ident]; dup {
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
s.host.Log("info", "calendar dispatchSlot skipped (already active)", map[string]any{"slot": ident})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if _, agentBusy := s.activeByAgentID[agentID]; agentBusy {
|
if _, agentBusy := s.activeByAgentID[agentID]; agentBusy {
|
||||||
// Don't pick up another slot until the current one resolves.
|
// Don't pick up another slot until the current one resolves.
|
||||||
s.mu.Unlock()
|
s.mu.Unlock()
|
||||||
|
s.host.Log("info", "calendar dispatchSlot skipped (agent has active slot)", map[string]any{"agent": agentID})
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
@@ -191,12 +199,21 @@ func (s *Scheduler) dispatchSlot(ctx context.Context, agentID string, slot Slot)
|
|||||||
|
|
||||||
message := buildWakeMessage(slot)
|
message := buildWakeMessage(slot)
|
||||||
source := "calendar:" + ident
|
source := "calendar:" + ident
|
||||||
|
s.host.Log("info", "calendar firing WakeAgent", map[string]any{
|
||||||
|
"agent": agentID, "slot": ident, "source": source, "msg_len": len(message),
|
||||||
|
})
|
||||||
if err := s.host.WakeAgent(ctx, sdkplugin.WakeAgentRequest{
|
if err := s.host.WakeAgent(ctx, sdkplugin.WakeAgentRequest{
|
||||||
AgentID: agentID, Message: message, Source: source,
|
AgentID: agentID, Message: message, Source: source,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
|
s.host.Log("warn", "calendar WakeAgent failed", map[string]any{
|
||||||
|
"agent": agentID, "err": err.Error(),
|
||||||
|
})
|
||||||
s.resolveLocally(ident, agentID, SlotAborted, "", "wake failed: "+err.Error())
|
s.resolveLocally(ident, agentID, SlotAborted, "", "wake failed: "+err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
s.host.Log("info", "calendar WakeAgent enqueued ok", map[string]any{
|
||||||
|
"agent": agentID, "slot": ident,
|
||||||
|
})
|
||||||
// Mark Ongoing on the backend.
|
// Mark Ongoing on the backend.
|
||||||
update := SlotAgentUpdate{
|
update := SlotAgentUpdate{
|
||||||
Status: SlotOngoing, StartedAt: now.Format("15:04:05"),
|
Status: SlotOngoing, StartedAt: now.Format("15:04:05"),
|
||||||
|
|||||||
@@ -8,16 +8,18 @@ package calendar
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
// SlotStatus enumerates the lifecycle. String values match backend's
|
// SlotStatus enumerates the lifecycle. String values match backend's
|
||||||
// SlotStatus enum verbatim (camelCase as stored in DB).
|
// SlotStatus enum verbatim (snake_case — verified via heartbeat
|
||||||
|
// response shape against running harborforge-backend).
|
||||||
type SlotStatus string
|
type SlotStatus string
|
||||||
|
|
||||||
const (
|
const (
|
||||||
SlotNotStarted SlotStatus = "NotStarted"
|
SlotNotStarted SlotStatus = "not_started"
|
||||||
SlotOngoing SlotStatus = "Ongoing"
|
SlotOngoing SlotStatus = "ongoing"
|
||||||
SlotFinished SlotStatus = "Finished"
|
SlotFinished SlotStatus = "finished"
|
||||||
SlotAborted SlotStatus = "Aborted"
|
SlotAborted SlotStatus = "aborted"
|
||||||
SlotDeferred SlotStatus = "Deferred"
|
SlotDeferred SlotStatus = "deferred"
|
||||||
SlotPaused SlotStatus = "Paused"
|
SlotPaused SlotStatus = "paused"
|
||||||
|
SlotSkipped SlotStatus = "skipped"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SlotType: work vs on_call. Affects whether the agent flips to busy.
|
// SlotType: work vs on_call. Affects whether the agent flips to busy.
|
||||||
|
|||||||
Reference in New Issue
Block a user