GitHub(nextgroup2706/ken_nogi)は今後使わず自社Gitea運用に切替え。 NodeSrvは旧リポジトリの履歴を破棄しファイルのみ統合(Dokploy用サービスアカウントは 別途mygit-admin/NodeSrv.gitに履歴あり)。notepmエクスポート(12GB)とPleasanter インストーラzip(208MB)はサイズが大きいため.gitignoreで除外。 Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
34 lines
1.3 KiB
JavaScript
34 lines
1.3 KiB
JavaScript
function initialState() {
|
|
return { consecutiveFailures: 0, alerted: false, lastAlertAt: null };
|
|
}
|
|
|
|
// Keycloakのtoken発行チェック結果からアラート状態を遷移させる純粋関数。
|
|
// alertThreshold回連続失敗するまでは通知しない(単発の揺らぎで騒がない)。
|
|
// 通知後もダウンが続く場合はrealertIntervalMsごとに再通知、復旧したら1回だけ復旧通知する。
|
|
function evaluate(state, checkOk, now, { alertThreshold, realertIntervalMs }) {
|
|
if (checkOk) {
|
|
if (state.alerted) {
|
|
return { newState: initialState(), action: 'alert-recovered' };
|
|
}
|
|
return { newState: initialState(), action: 'none' };
|
|
}
|
|
|
|
const consecutiveFailures = state.consecutiveFailures + 1;
|
|
|
|
if (consecutiveFailures < alertThreshold) {
|
|
return { newState: { ...state, consecutiveFailures }, action: 'none' };
|
|
}
|
|
|
|
if (!state.alerted) {
|
|
return { newState: { consecutiveFailures, alerted: true, lastAlertAt: now }, action: 'alert-down' };
|
|
}
|
|
|
|
if (now - state.lastAlertAt >= realertIntervalMs) {
|
|
return { newState: { consecutiveFailures, alerted: true, lastAlertAt: now }, action: 'alert-still-down' };
|
|
}
|
|
|
|
return { newState: { consecutiveFailures, alerted: true, lastAlertAt: state.lastAlertAt }, action: 'none' };
|
|
}
|
|
|
|
module.exports = { initialState, evaluate };
|