feat: 更新保持工作空间存活技能,优化错误处理并添加保活数据

This commit is contained in:
2026-03-07 02:19:49 +08:00
parent 81a3aae8ec
commit 21ba07e55b
2 changed files with 12 additions and 13 deletions

View File

@@ -30,21 +30,20 @@ app.route({
ctx.throw(401, 'CNB_COOKIE 环境变量无效或已过期请重新登录获取新的cookie');
}
const res = await cnb.workspace.getWorkspaceCookie(repo, pipelineId);
let wsUrl = `wss://${pipelineId}.cnb.space:443?skipWebSocketFrames=false`;
let cookie = '';
if (res.code === 200) {
cookie = res.data.value;
console.log(`启动保持工作空间 ${wsUrl} 存活的任务`);
} else {
ctx.throw(500, `获取工作空间访问cookie失败: ${res.message}`);
if (res.code !== 200 || !res.data?.cookie) {
ctx.throw(500, `获取工作空间 Cookie 失败: ${res.message}`);
}
console.log(`启动保持工作空间 ${wsUrl} 存活的任务`);
// 添加保活数据
const liveData = createLiveData({
repo,
pipelineId,
cookie: res.data.cookie
});
addKeepAliveData(liveData);
console.log('已添加 keep-alive 数据');
const config: KeepAliveData = createLiveData({ cookie, repo, pipelineId });
addKeepAliveData(config);
ctx.body = { content: `已启动保持工作空间 ${wsUrl} 存活的任务`, data: config };
ctx.body = { content: `已启动保持工作空间 ${repo}/${pipelineId} 存活的任务`, data: liveData };
}).addTo(app);
// 停止保持工作空间存活技能

View File

@@ -1,6 +1,6 @@
{
"name": "@kevisual/cnb",
"version": "0.0.36",
"version": "0.0.37",
"description": "",
"main": "index.js",
"scripts": {