mirror of
https://github.com/qingchencloud/clawpanel.git
synced 2026-05-30 04:40:18 +08:00
feat(hermes): add kanban worker log controls
This commit is contained in:
@@ -3800,6 +3800,22 @@ export function buildHermesKanbanConfigValues(config = {}) {
|
||||
1000,
|
||||
false,
|
||||
),
|
||||
workerLogRotateBytes: parseHermesInteger(
|
||||
kanban.worker_log_rotate_bytes,
|
||||
'kanban.worker_log_rotate_bytes',
|
||||
2097152,
|
||||
1,
|
||||
1073741824,
|
||||
false,
|
||||
),
|
||||
workerLogBackupCount: parseHermesInteger(
|
||||
kanban.worker_log_backup_count,
|
||||
'kanban.worker_log_backup_count',
|
||||
1,
|
||||
0,
|
||||
100,
|
||||
false,
|
||||
),
|
||||
dispatchStaleTimeoutSeconds: parseHermesInteger(
|
||||
kanban.dispatch_stale_timeout_seconds,
|
||||
'kanban.dispatch_stale_timeout_seconds',
|
||||
@@ -3864,6 +3880,22 @@ export function mergeHermesKanbanConfig(config = {}, form = {}) {
|
||||
1000,
|
||||
true,
|
||||
)
|
||||
kanban.worker_log_rotate_bytes = parseHermesInteger(
|
||||
Object.hasOwn(form, 'workerLogRotateBytes') ? form.workerLogRotateBytes : currentValues.workerLogRotateBytes,
|
||||
'kanban.worker_log_rotate_bytes',
|
||||
2097152,
|
||||
1,
|
||||
1073741824,
|
||||
true,
|
||||
)
|
||||
kanban.worker_log_backup_count = parseHermesInteger(
|
||||
Object.hasOwn(form, 'workerLogBackupCount') ? form.workerLogBackupCount : currentValues.workerLogBackupCount,
|
||||
'kanban.worker_log_backup_count',
|
||||
1,
|
||||
0,
|
||||
100,
|
||||
true,
|
||||
)
|
||||
kanban.dispatch_stale_timeout_seconds = parseHermesInteger(
|
||||
Object.hasOwn(form, 'dispatchStaleTimeoutSeconds') ? form.dispatchStaleTimeoutSeconds : currentValues.dispatchStaleTimeoutSeconds,
|
||||
'kanban.dispatch_stale_timeout_seconds',
|
||||
|
||||
@@ -6589,6 +6589,22 @@ fn build_hermes_kanban_config_values(config: &serde_yaml::Value) -> Value {
|
||||
1000,
|
||||
))
|
||||
.unwrap_or(3),
|
||||
"workerLogRotateBytes": kanban
|
||||
.map(|map| bounded_hermes_i64(
|
||||
yaml_i64_field(map, "worker_log_rotate_bytes"),
|
||||
2097152,
|
||||
1,
|
||||
1073741824,
|
||||
))
|
||||
.unwrap_or(2097152),
|
||||
"workerLogBackupCount": kanban
|
||||
.map(|map| bounded_hermes_i64(
|
||||
yaml_i64_field(map, "worker_log_backup_count"),
|
||||
1,
|
||||
0,
|
||||
100,
|
||||
))
|
||||
.unwrap_or(1),
|
||||
"dispatchStaleTimeoutSeconds": kanban
|
||||
.map(|map| bounded_hermes_i64(
|
||||
yaml_i64_field(map, "dispatch_stale_timeout_seconds"),
|
||||
@@ -6644,6 +6660,20 @@ fn merge_hermes_kanban_config(config: &mut serde_yaml::Value, form: &Value) -> R
|
||||
1,
|
||||
1000,
|
||||
)?;
|
||||
let worker_log_rotate_bytes = validate_hermes_i64(
|
||||
form_i64(form, "workerLogRotateBytes").or_else(|| current["workerLogRotateBytes"].as_i64()),
|
||||
"kanban.worker_log_rotate_bytes",
|
||||
2097152,
|
||||
1,
|
||||
1073741824,
|
||||
)?;
|
||||
let worker_log_backup_count = validate_hermes_i64(
|
||||
form_i64(form, "workerLogBackupCount").or_else(|| current["workerLogBackupCount"].as_i64()),
|
||||
"kanban.worker_log_backup_count",
|
||||
1,
|
||||
0,
|
||||
100,
|
||||
)?;
|
||||
let stale_timeout = validate_hermes_i64(
|
||||
form_i64(form, "dispatchStaleTimeoutSeconds")
|
||||
.or_else(|| current["dispatchStaleTimeoutSeconds"].as_i64()),
|
||||
@@ -6690,6 +6720,14 @@ fn merge_hermes_kanban_config(config: &mut serde_yaml::Value, form: &Value) -> R
|
||||
yaml_key("auto_decompose_per_tick"),
|
||||
serde_yaml::Value::Number(serde_yaml::Number::from(auto_decompose_per_tick)),
|
||||
);
|
||||
kanban.insert(
|
||||
yaml_key("worker_log_rotate_bytes"),
|
||||
serde_yaml::Value::Number(serde_yaml::Number::from(worker_log_rotate_bytes)),
|
||||
);
|
||||
kanban.insert(
|
||||
yaml_key("worker_log_backup_count"),
|
||||
serde_yaml::Value::Number(serde_yaml::Number::from(worker_log_backup_count)),
|
||||
);
|
||||
kanban.insert(
|
||||
yaml_key("dispatch_stale_timeout_seconds"),
|
||||
serde_yaml::Value::Number(serde_yaml::Number::from(stale_timeout)),
|
||||
@@ -19460,6 +19498,8 @@ mod hermes_kanban_config_tests {
|
||||
assert_eq!(values["failureLimit"], 2);
|
||||
assert_eq!(values["autoDecompose"], true);
|
||||
assert_eq!(values["autoDecomposePerTick"], 3);
|
||||
assert_eq!(values["workerLogRotateBytes"], 2097152);
|
||||
assert_eq!(values["workerLogBackupCount"], 1);
|
||||
assert_eq!(values["dispatchStaleTimeoutSeconds"], 14400);
|
||||
}
|
||||
|
||||
@@ -19475,6 +19515,8 @@ kanban:
|
||||
failure_limit: "5"
|
||||
auto_decompose: false
|
||||
auto_decompose_per_tick: "7"
|
||||
worker_log_rotate_bytes: "4194304"
|
||||
worker_log_backup_count: "3"
|
||||
dispatch_stale_timeout_seconds: "7200"
|
||||
"#,
|
||||
)
|
||||
@@ -19487,6 +19529,8 @@ kanban:
|
||||
assert_eq!(values["failureLimit"], 5);
|
||||
assert_eq!(values["autoDecompose"], false);
|
||||
assert_eq!(values["autoDecomposePerTick"], 7);
|
||||
assert_eq!(values["workerLogRotateBytes"], 4194304);
|
||||
assert_eq!(values["workerLogBackupCount"], 3);
|
||||
assert_eq!(values["dispatchStaleTimeoutSeconds"], 7200);
|
||||
}
|
||||
|
||||
@@ -19517,6 +19561,8 @@ memory:
|
||||
"failureLimit": 4,
|
||||
"autoDecompose": false,
|
||||
"autoDecomposePerTick": 2,
|
||||
"workerLogRotateBytes": 1048576,
|
||||
"workerLogBackupCount": 0,
|
||||
"dispatchStaleTimeoutSeconds": 0,
|
||||
}),
|
||||
)
|
||||
@@ -19541,6 +19587,14 @@ memory:
|
||||
config["kanban"]["auto_decompose_per_tick"].as_i64(),
|
||||
Some(2)
|
||||
);
|
||||
assert_eq!(
|
||||
config["kanban"]["worker_log_rotate_bytes"].as_i64(),
|
||||
Some(1048576)
|
||||
);
|
||||
assert_eq!(
|
||||
config["kanban"]["worker_log_backup_count"].as_i64(),
|
||||
Some(0)
|
||||
);
|
||||
assert_eq!(
|
||||
config["kanban"]["dispatch_stale_timeout_seconds"].as_i64(),
|
||||
Some(0)
|
||||
@@ -19595,6 +19649,14 @@ kanban:
|
||||
.unwrap_err();
|
||||
assert!(err.contains("kanban.auto_decompose_per_tick"));
|
||||
|
||||
let err = merge_hermes_kanban_config(&mut config, &json!({ "workerLogRotateBytes": 0 }))
|
||||
.unwrap_err();
|
||||
assert!(err.contains("kanban.worker_log_rotate_bytes"));
|
||||
|
||||
let err = merge_hermes_kanban_config(&mut config, &json!({ "workerLogBackupCount": -1 }))
|
||||
.unwrap_err();
|
||||
assert!(err.contains("kanban.worker_log_backup_count"));
|
||||
|
||||
let err =
|
||||
merge_hermes_kanban_config(&mut config, &json!({ "dispatchStaleTimeoutSeconds": -1 }))
|
||||
.unwrap_err();
|
||||
|
||||
@@ -181,6 +181,8 @@ const KANBAN_DEFAULTS = {
|
||||
failureLimit: 2,
|
||||
autoDecompose: true,
|
||||
autoDecomposePerTick: 3,
|
||||
workerLogRotateBytes: 2097152,
|
||||
workerLogBackupCount: 1,
|
||||
dispatchStaleTimeoutSeconds: 14400,
|
||||
}
|
||||
|
||||
@@ -1525,6 +1527,14 @@ export function render() {
|
||||
<span class="hm-field-label">${t('engine.hermesKanbanConfigAutoDecomposePerTick')}</span>
|
||||
<input id="hm-kanban-auto-decompose-per-tick" class="hm-input" type="number" inputmode="numeric" min="1" max="1000" step="1" value="${esc(kanbanValues.autoDecomposePerTick)}" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
<label class="hm-field">
|
||||
<span class="hm-field-label">${t('engine.hermesKanbanConfigWorkerLogRotateBytes')}</span>
|
||||
<input id="hm-kanban-worker-log-rotate-bytes" class="hm-input" type="number" inputmode="numeric" min="1" max="1073741824" step="1024" value="${esc(kanbanValues.workerLogRotateBytes)}" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
<label class="hm-field">
|
||||
<span class="hm-field-label">${t('engine.hermesKanbanConfigWorkerLogBackupCount')}</span>
|
||||
<input id="hm-kanban-worker-log-backup-count" class="hm-input" type="number" inputmode="numeric" min="0" max="100" step="1" value="${esc(kanbanValues.workerLogBackupCount)}" ${disabled ? 'disabled' : ''}>
|
||||
</label>
|
||||
<label class="hm-field">
|
||||
<span class="hm-field-label">${t('engine.hermesKanbanConfigDispatchStaleTimeoutSeconds')}</span>
|
||||
<input id="hm-kanban-dispatch-stale-timeout-seconds" class="hm-input" type="number" inputmode="numeric" min="0" max="604800" step="60" value="${esc(kanbanValues.dispatchStaleTimeoutSeconds)}" ${disabled ? 'disabled' : ''}>
|
||||
@@ -3530,6 +3540,8 @@ export function render() {
|
||||
failureLimit: el.querySelector('#hm-kanban-failure-limit')?.value || '2',
|
||||
autoDecompose: el.querySelector('#hm-kanban-auto-decompose')?.checked ?? true,
|
||||
autoDecomposePerTick: el.querySelector('#hm-kanban-auto-decompose-per-tick')?.value || '3',
|
||||
workerLogRotateBytes: el.querySelector('#hm-kanban-worker-log-rotate-bytes')?.value || '2097152',
|
||||
workerLogBackupCount: el.querySelector('#hm-kanban-worker-log-backup-count')?.value || '1',
|
||||
dispatchStaleTimeoutSeconds: el.querySelector('#hm-kanban-dispatch-stale-timeout-seconds')?.value || '14400',
|
||||
}
|
||||
kanbanSaving = true
|
||||
|
||||
@@ -1042,8 +1042,10 @@ export default {
|
||||
hermesKanbanConfigFailureLimit: _('失败重试上限', 'Failure retry limit', '失敗重試上限'),
|
||||
hermesKanbanConfigAutoDecompose: _('自动拆解待办任务', 'Auto decompose tasks', '自動拆解待辦任務'),
|
||||
hermesKanbanConfigAutoDecomposePerTick: _('每轮自动拆解数量', 'Auto decompose per tick', '每輪自動拆解數量'),
|
||||
hermesKanbanConfigWorkerLogRotateBytes: _('Worker 日志轮转大小(字节)', 'Worker log rotation size (bytes)', 'Worker 日誌輪轉大小(位元組)'),
|
||||
hermesKanbanConfigWorkerLogBackupCount: _('Worker 日志备份数量', 'Worker log backups', 'Worker 日誌備份數量'),
|
||||
hermesKanbanConfigDispatchStaleTimeoutSeconds: _('无心跳回收时间(秒)', 'Heartbeat reclaim timeout (s)', '無心跳回收時間(秒)'),
|
||||
hermesKanbanConfigFootnote: _('写入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、dispatch_stale_timeout_seconds。两个并发上限填 0 表示不写入限制;无心跳回收填 0 表示关闭自动回收。', 'Writes kanban.dispatch_in_gateway, dispatch_interval_seconds, max_spawn, max_in_progress, failure_limit, auto_decompose, auto_decompose_per_tick, and dispatch_stale_timeout_seconds. Set concurrency caps to 0 to omit limits; set heartbeat reclaim to 0 to disable automatic reclaim.', '寫入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、dispatch_stale_timeout_seconds。兩個並發上限填 0 表示不寫入限制;無心跳回收填 0 表示關閉自動回收。'),
|
||||
hermesKanbanConfigFootnote: _('写入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、worker_log_rotate_bytes、worker_log_backup_count、dispatch_stale_timeout_seconds。两个并发上限填 0 表示不写入限制;Worker 日志超过轮转大小会在下次启动前处理,备份数量填 0 表示超限时不保留旧日志;无心跳回收填 0 表示关闭自动回收。', 'Writes kanban.dispatch_in_gateway, dispatch_interval_seconds, max_spawn, max_in_progress, failure_limit, auto_decompose, auto_decompose_per_tick, worker_log_rotate_bytes, worker_log_backup_count, and dispatch_stale_timeout_seconds. Set concurrency caps to 0 to omit limits; worker logs are handled before the next worker starts after they exceed the rotation size, and 0 backups means old logs are not kept; set heartbeat reclaim to 0 to disable automatic reclaim.', '寫入 kanban.dispatch_in_gateway、dispatch_interval_seconds、max_spawn、max_in_progress、failure_limit、auto_decompose、auto_decompose_per_tick、worker_log_rotate_bytes、worker_log_backup_count、dispatch_stale_timeout_seconds。兩個並發上限填 0 表示不寫入限制;Worker 日誌超過輪轉大小會在下次啟動前處理,備份數量填 0 表示超限時不保留舊日誌;無心跳回收填 0 表示關閉自動回收。'),
|
||||
hermesSecurityConfigTitle: _('Tirith 安全扫描', 'Tirith security scanning', 'Tirith 安全掃描'),
|
||||
hermesSecurityConfigDesc: _('控制终端命令执行前的 Tirith 内容扫描,拦截明显的 URL 伪装、管道执行和注入风险。', 'Control Tirith content scanning before terminal commands run to catch obvious URL spoofing, pipe-to-shell, and injection risks.', '控制終端命令執行前的 Tirith 內容掃描,攔截明顯的 URL 偽裝、管道執行和注入風險。'),
|
||||
hermesSecurityConfigStatusReady: _('结构化配置', 'structured settings', '結構化設定'),
|
||||
|
||||
@@ -435,6 +435,8 @@ test('Hermes 配置页会暴露 Kanban 调度稳定性结构化配置字段', ()
|
||||
'hm-kanban-failure-limit',
|
||||
'hm-kanban-auto-decompose',
|
||||
'hm-kanban-auto-decompose-per-tick',
|
||||
'hm-kanban-worker-log-rotate-bytes',
|
||||
'hm-kanban-worker-log-backup-count',
|
||||
'hm-kanban-dispatch-stale-timeout-seconds',
|
||||
]) {
|
||||
assert.match(source, new RegExp(`id="${id}"`), `缺少 ${id}`)
|
||||
|
||||
@@ -17,6 +17,8 @@ test('Hermes Kanban 配置读取会提供上游默认值', () => {
|
||||
failureLimit: 2,
|
||||
autoDecompose: true,
|
||||
autoDecomposePerTick: 3,
|
||||
workerLogRotateBytes: 2097152,
|
||||
workerLogBackupCount: 1,
|
||||
dispatchStaleTimeoutSeconds: 14400,
|
||||
})
|
||||
})
|
||||
@@ -31,6 +33,8 @@ test('Hermes Kanban 配置读取会规范化已有字段', () => {
|
||||
failure_limit: '5',
|
||||
auto_decompose: false,
|
||||
auto_decompose_per_tick: '7',
|
||||
worker_log_rotate_bytes: '4194304',
|
||||
worker_log_backup_count: '3',
|
||||
dispatch_stale_timeout_seconds: '7200',
|
||||
},
|
||||
})
|
||||
@@ -42,6 +46,8 @@ test('Hermes Kanban 配置读取会规范化已有字段', () => {
|
||||
assert.equal(values.failureLimit, 5)
|
||||
assert.equal(values.autoDecompose, false)
|
||||
assert.equal(values.autoDecomposePerTick, 7)
|
||||
assert.equal(values.workerLogRotateBytes, 4194304)
|
||||
assert.equal(values.workerLogBackupCount, 3)
|
||||
assert.equal(values.dispatchStaleTimeoutSeconds, 7200)
|
||||
})
|
||||
|
||||
@@ -63,6 +69,8 @@ test('Hermes Kanban 配置保存会保留未知 YAML 并写入 kanban', () => {
|
||||
failureLimit: '4',
|
||||
autoDecompose: false,
|
||||
autoDecomposePerTick: '2',
|
||||
workerLogRotateBytes: '1048576',
|
||||
workerLogBackupCount: '0',
|
||||
dispatchStaleTimeoutSeconds: '0',
|
||||
})
|
||||
|
||||
@@ -76,6 +84,8 @@ test('Hermes Kanban 配置保存会保留未知 YAML 并写入 kanban', () => {
|
||||
assert.equal(next.kanban.failure_limit, 4)
|
||||
assert.equal(next.kanban.auto_decompose, false)
|
||||
assert.equal(next.kanban.auto_decompose_per_tick, 2)
|
||||
assert.equal(next.kanban.worker_log_rotate_bytes, 1048576)
|
||||
assert.equal(next.kanban.worker_log_backup_count, 0)
|
||||
assert.equal(next.kanban.dispatch_stale_timeout_seconds, 0)
|
||||
})
|
||||
|
||||
@@ -117,6 +127,14 @@ test('Hermes Kanban 配置保存会拒绝非法调度参数', () => {
|
||||
() => mergeHermesKanbanConfig({}, { autoDecomposePerTick: '0' }),
|
||||
/kanban\.auto_decompose_per_tick/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesKanbanConfig({}, { workerLogRotateBytes: '0' }),
|
||||
/kanban\.worker_log_rotate_bytes/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesKanbanConfig({}, { workerLogBackupCount: '-1' }),
|
||||
/kanban\.worker_log_backup_count/,
|
||||
)
|
||||
assert.throws(
|
||||
() => mergeHermesKanbanConfig({}, { dispatchStaleTimeoutSeconds: '-1' }),
|
||||
/kanban\.dispatch_stale_timeout_seconds/,
|
||||
|
||||
Reference in New Issue
Block a user