Phase6
This commit is contained in:
@@ -110,10 +110,18 @@ export class NodesService {
|
||||
}
|
||||
|
||||
async markNodeOnline(nodeId: string, agentVersion?: string): Promise<void> {
|
||||
const node = await this.prisma.gameNode.findUnique({ where: { id: nodeId } });
|
||||
const nextStatus =
|
||||
node?.status === 'UNREACHABLE' || node?.status === 'OFFLINE'
|
||||
? 'ONLINE'
|
||||
: node?.status === 'MAINTENANCE' || node?.status === 'DRAINING'
|
||||
? node.status
|
||||
: 'ONLINE';
|
||||
|
||||
await this.prisma.gameNode.update({
|
||||
where: { id: nodeId },
|
||||
data: {
|
||||
status: 'ONLINE',
|
||||
status: nextStatus,
|
||||
lastHeartbeatAt: new Date(),
|
||||
enrolledAt: new Date(),
|
||||
agentVersion,
|
||||
@@ -172,17 +180,35 @@ export class NodesService {
|
||||
payload?: Record<string, unknown>,
|
||||
): Promise<void> {
|
||||
const now = new Date();
|
||||
const node = await this.prisma.gameNode.findUnique({ where: { id: nodeId } });
|
||||
|
||||
const nextStatus =
|
||||
node?.status === 'UNREACHABLE'
|
||||
? 'ONLINE'
|
||||
: node?.status === 'MAINTENANCE' || node?.status === 'DRAINING'
|
||||
? node.status
|
||||
: 'ONLINE';
|
||||
|
||||
await this.prisma.$transaction([
|
||||
this.prisma.gameNode.update({
|
||||
where: { id: nodeId },
|
||||
data: {
|
||||
lastHeartbeatAt: now,
|
||||
status: 'ONLINE',
|
||||
status: nextStatus,
|
||||
agentVersion:
|
||||
typeof payload?.['agentVersion'] === 'string'
|
||||
? payload['agentVersion']
|
||||
: undefined,
|
||||
metadata: payload
|
||||
? ({
|
||||
cpuUsagePercent: payload['cpuUsagePercent'],
|
||||
memoryUsedBytes: payload['memoryUsedBytes'],
|
||||
memoryTotalBytes: payload['memoryTotalBytes'],
|
||||
diskUsedBytes: payload['diskUsedBytes'],
|
||||
diskTotalBytes: payload['diskTotalBytes'],
|
||||
runningServers: payload['runningServers'],
|
||||
} as Prisma.InputJsonValue)
|
||||
: undefined,
|
||||
},
|
||||
}),
|
||||
this.prisma.gameNodeHeartbeat.create({
|
||||
|
||||
Reference in New Issue
Block a user