mirror of
https://github.com/kolbytn/mindcraft.git
synced 2025-08-28 09:53:06 +02:00
added full shutdown from ui/task
This commit is contained in:
parent
3717d9b9f4
commit
7ad48c29ad
6 changed files with 58 additions and 12 deletions
|
@ -438,22 +438,18 @@ export class Agent {
|
||||||
}, INTERVAL);
|
}, INTERVAL);
|
||||||
|
|
||||||
this.bot.emit('idle');
|
this.bot.emit('idle');
|
||||||
|
|
||||||
// Check for task completion
|
|
||||||
if (this.task.data) {
|
|
||||||
setInterval(() => {
|
|
||||||
let res = this.task.isDone();
|
|
||||||
if (res) {
|
|
||||||
// TODO kill other bots
|
|
||||||
this.cleanKill(res.message, res.code);
|
|
||||||
}
|
|
||||||
}, 1000);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async update(delta) {
|
async update(delta) {
|
||||||
await this.bot.modes.update();
|
await this.bot.modes.update();
|
||||||
this.self_prompter.update(delta);
|
this.self_prompter.update(delta);
|
||||||
|
if (this.task.data) {
|
||||||
|
let res = this.task.isDone();
|
||||||
|
if (res) {
|
||||||
|
console.log('Task finished:', res.message);
|
||||||
|
this.killAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
isIdle() {
|
isIdle() {
|
||||||
|
@ -466,4 +462,8 @@ export class Agent {
|
||||||
this.history.save();
|
this.history.save();
|
||||||
process.exit(code);
|
process.exit(code);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
killAll() {
|
||||||
|
serverProxy.shutdown();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,10 @@ class AgentServerProxy {
|
||||||
this.socket.emit('login-agent', this.agent.name);
|
this.socket.emit('login-agent', this.agent.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
shutdown() {
|
||||||
|
this.socket.emit('shutdown');
|
||||||
|
}
|
||||||
|
|
||||||
getSocket() {
|
getSocket() {
|
||||||
return this.socket;
|
return this.socket;
|
||||||
}
|
}
|
||||||
|
|
|
@ -179,7 +179,7 @@ export class Task {
|
||||||
await new Promise((resolve) => setTimeout(resolve, 10000));
|
await new Promise((resolve) => setTimeout(resolve, 10000));
|
||||||
if (available_agents.length < this.data.agent_count) {
|
if (available_agents.length < this.data.agent_count) {
|
||||||
console.log(`Missing ${this.data.agent_count - available_agents.length} bot(s).`);
|
console.log(`Missing ${this.data.agent_count - available_agents.length} bot(s).`);
|
||||||
this.agent.cleanKill('Not all required players/bots are present in the world. Exiting.', 4);
|
this.agent.killAll();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,16 @@ class MainProxy {
|
||||||
this.socket.on('register-agents-success', () => {
|
this.socket.on('register-agents-success', () => {
|
||||||
console.log('Agents registered');
|
console.log('Agents registered');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.socket.on('shutdown', () => {
|
||||||
|
console.log('Shutting down');
|
||||||
|
for (let agentName in this.agent_processes) {
|
||||||
|
this.agent_processes[agentName].stop();
|
||||||
|
}
|
||||||
|
setTimeout(() => {
|
||||||
|
process.exit(0);
|
||||||
|
}, 2000);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
addAgent(agent) {
|
addAgent(agent) {
|
||||||
|
|
|
@ -101,6 +101,19 @@ export function createMindServer(port = 8080) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
socket.on('stop-all-agents', () => {
|
||||||
|
console.log('Killing all agents');
|
||||||
|
stopAllAgents();
|
||||||
|
});
|
||||||
|
|
||||||
|
socket.on('shutdown', () => {
|
||||||
|
console.log('Shutting down');
|
||||||
|
for (let manager of Object.values(agentManagers)) {
|
||||||
|
manager.emit('shutdown');
|
||||||
|
}
|
||||||
|
process.exit(0);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
server.listen(port, 'localhost', () => {
|
server.listen(port, 'localhost', () => {
|
||||||
|
@ -121,6 +134,15 @@ function agentsUpdate(socket) {
|
||||||
socket.emit('agents-update', agents);
|
socket.emit('agents-update', agents);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function stopAllAgents() {
|
||||||
|
for (const agentName in inGameAgents) {
|
||||||
|
let manager = agentManagers[agentName];
|
||||||
|
if (manager) {
|
||||||
|
manager.emit('stop-agent', agentName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Optional: export these if you need access to them from other files
|
// Optional: export these if you need access to them from other files
|
||||||
export const getIO = () => io;
|
export const getIO = () => io;
|
||||||
export const getServer = () => server;
|
export const getServer = () => server;
|
||||||
|
|
|
@ -85,6 +85,8 @@
|
||||||
`}
|
`}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<button class="stop-btn" onclick="killAllAgents()">Stop All</button>
|
||||||
|
<button class="stop-btn" onclick="shutdown()">Shutdown</button>
|
||||||
`).join('') :
|
`).join('') :
|
||||||
'<div class="agent">No agents connected</div>';
|
'<div class="agent">No agents connected</div>';
|
||||||
});
|
});
|
||||||
|
@ -100,6 +102,14 @@
|
||||||
function stopAgent(agentName) {
|
function stopAgent(agentName) {
|
||||||
socket.emit('stop-agent', agentName);
|
socket.emit('stop-agent', agentName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function killAllAgents() {
|
||||||
|
socket.emit('stop-all-agents');
|
||||||
|
}
|
||||||
|
|
||||||
|
function shutdown() {
|
||||||
|
socket.emit('shutdown');
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
Add table
Reference in a new issue