Observer embryo, Maestro done

This commit is contained in:
STEINNI
2026-06-13 13:47:46 +00:00
parent 932b6e4752
commit 26aefd3fe2
45 changed files with 1889 additions and 143 deletions
+138
View File
@@ -0,0 +1,138 @@
import { publishActionReply } from '../../actionsHelper.js'
import { isValidUuid } from '../../simRepository.js'
export const methods = {
/* Event-Rx:
{
"action": "STARTSIMULATION",
"reqid": "6az5e4r6a",
"sender": "<user-uuid>",
"roles": ["*"],
"payload": {
"simulationUuid": "...",
"keyframeId": "...",
"infraId": "..."
}
}
*/
async action_STARTSIMULATION(action, payload, reqid, sender, roles) {
const replyOpts = {
action,
reqid,
sender,
replyChannel: this.config.maestro.maestroActionsReply,
}
if(!this.accessRights.canDo(roles, action)) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: 'Unauthorized action !',
} })
return
}
if(!sender || !isValidUuid(sender)) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: 'Missing or invalid sender (user UUID)',
} })
return
}
if(!payload?.simulationUuid || !payload?.keyframeId) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: 'Missing simulationUuid or keyframeId',
} })
return
}
try {
const result = await this.maestroSrv.startSimulation(sender, payload)
if(!result.ok) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: result.err,
} })
return
}
publishActionReply(this, { ...replyOpts, reply: {
success: true,
payload: {
simulationId: result.simulationId,
keyframeId: result.keyframeId,
infraId: result.infraId,
agentIds: result.agentIds,
},
} })
} catch(err) {
console.error(`[${this.redisId}] STARTSIMULATION failed:`, err)
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: err.message ?? 'STARTSIMULATION failed',
} })
}
},
/* Event-Rx:
{
"action": "STOPSIMULATION",
"reqid": "6az5e4r6a",
"sender": "<user-uuid>",
"payload": { "simulationUuid": "..." }
}
*/
async action_STOPSIMULATION(action, payload, reqid, sender, roles) {
const replyOpts = {
action,
reqid,
sender,
replyChannel: this.config.maestro.maestroActionsReply,
}
if(!this.accessRights.canDo(roles, action)) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: 'Unauthorized action !',
} })
return
}
if(!sender || !isValidUuid(sender)) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: 'Missing or invalid sender (user UUID)',
} })
return
}
if(!payload?.simulationUuid) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: 'Missing simulationUuid',
} })
return
}
try {
const result = await this.maestroSrv.stopSimulation(sender, payload)
if(!result.ok) {
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: result.err,
} })
return
}
publishActionReply(this, { ...replyOpts, reply: {
success: true,
payload: { simulationId: result.simulationId },
} })
} catch(err) {
console.error(`[${this.redisId}] STOPSIMULATION failed:`, err)
publishActionReply(this, { ...replyOpts, reply: {
success: false,
err: err.message ?? 'STOPSIMULATION failed',
} })
}
},
}