u
This commit is contained in:
@@ -215,7 +215,12 @@ const activeAgentEvents = new Map();
|
|||||||
export function notifyAgentJob(agentId, action, job) {
|
export function notifyAgentJob(agentId, action, job) {
|
||||||
const aId = Number(agentId);
|
const aId = Number(agentId);
|
||||||
const conns = activeAgentEvents.get(aId);
|
const conns = activeAgentEvents.get(aId);
|
||||||
if (!conns || conns.size === 0) return false;
|
const count = conns ? conns.size : 0;
|
||||||
|
log.info(`notifyAgentJob: agentId=${aId} action=${action} jobId=${job?.id} activeConnections=${count}`);
|
||||||
|
if (!conns || conns.size === 0) {
|
||||||
|
log.warn(`notifyAgentJob: No active SSE connection for agent ${aId} (jobId=${job?.id}); agent must poll/reconnect`);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
const payload = JSON.stringify({
|
const payload = JSON.stringify({
|
||||||
action,
|
action,
|
||||||
jobId: job.id,
|
jobId: job.id,
|
||||||
@@ -228,6 +233,7 @@ export function notifyAgentJob(agentId, action, job) {
|
|||||||
if (!clientRes.writableEnded) {
|
if (!clientRes.writableEnded) {
|
||||||
clientRes.write(`event: job\ndata: ${payload}\n\n`);
|
clientRes.write(`event: job\ndata: ${payload}\n\n`);
|
||||||
clientRes.write(`event: printerjob\ndata: ${payload}\n\n`);
|
clientRes.write(`event: printerjob\ndata: ${payload}\n\n`);
|
||||||
|
clientRes.flush?.();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user