feat(center-nodes): add node heartbeat endpoint
This commit is contained in:
@@ -65,6 +65,27 @@ export class NodesController {
|
||||
};
|
||||
}
|
||||
|
||||
@Post(':nodeId/heartbeat')
|
||||
async heartbeat(@Param('nodeId') nodeId: string) {
|
||||
const node = await this.nodeRepo.findOne({ where: { nodeId } });
|
||||
if (!node) {
|
||||
throw new NotFoundException('node not found');
|
||||
}
|
||||
|
||||
node.lastHeartbeatAt = new Date();
|
||||
if (node.status !== 'revoked') {
|
||||
node.status = 'active';
|
||||
}
|
||||
|
||||
const saved = await this.nodeRepo.save(node);
|
||||
return {
|
||||
status: 'ok',
|
||||
nodeId: saved.nodeId,
|
||||
nodeStatus: saved.status,
|
||||
lastHeartbeatAt: saved.lastHeartbeatAt,
|
||||
};
|
||||
}
|
||||
|
||||
@Patch(':nodeId/status')
|
||||
async updateStatus(
|
||||
@Param('nodeId') nodeId: string,
|
||||
|
||||
Reference in New Issue
Block a user