feat(config): add configurable default shutdown delay for shutdown actions
This commit is contained in:
@@ -4,6 +4,7 @@ import { type ITableColumn, logger } from '../logger.ts';
|
||||
import { symbols, theme } from '../colors.ts';
|
||||
import type { IActionConfig } from '../actions/base-action.ts';
|
||||
import { ProxmoxAction } from '../actions/proxmox-action.ts';
|
||||
import { SHUTDOWN } from '../constants.ts';
|
||||
import type { IGroupConfig, IUpsConfig } from '../daemon.ts';
|
||||
import * as helpers from '../helpers/index.ts';
|
||||
|
||||
@@ -81,16 +82,20 @@ export class ActionHandler {
|
||||
if (typeValue === 1) {
|
||||
// Shutdown action
|
||||
newAction.type = 'shutdown';
|
||||
const defaultShutdownDelay =
|
||||
this.nupst.getDaemon().getConfig().defaultShutdownDelay ?? SHUTDOWN.DEFAULT_DELAY_MINUTES;
|
||||
|
||||
const delayStr = await prompt(
|
||||
` ${theme.dim('Shutdown delay')} ${theme.dim('(minutes) [5]:')} `,
|
||||
` ${theme.dim('Shutdown delay')} ${theme.dim(`(minutes, leave empty for default ${defaultShutdownDelay}):`)} `,
|
||||
);
|
||||
const shutdownDelay = delayStr ? parseInt(delayStr, 10) : 5;
|
||||
if (isNaN(shutdownDelay) || shutdownDelay < 0) {
|
||||
logger.error('Invalid shutdown delay. Must be >= 0.');
|
||||
process.exit(1);
|
||||
if (delayStr.trim()) {
|
||||
const shutdownDelay = parseInt(delayStr, 10);
|
||||
if (isNaN(shutdownDelay) || shutdownDelay < 0) {
|
||||
logger.error('Invalid shutdown delay. Must be >= 0.');
|
||||
process.exit(1);
|
||||
}
|
||||
newAction.shutdownDelay = shutdownDelay;
|
||||
}
|
||||
newAction.shutdownDelay = shutdownDelay;
|
||||
} else if (typeValue === 2) {
|
||||
// Webhook action
|
||||
newAction.type = 'webhook';
|
||||
@@ -468,7 +473,9 @@ export class ActionHandler {
|
||||
];
|
||||
|
||||
const rows = target.actions.map((action, index) => {
|
||||
let details = `${action.shutdownDelay || 5}min delay`;
|
||||
const defaultShutdownDelay =
|
||||
this.nupst.getDaemon().getConfig().defaultShutdownDelay ?? SHUTDOWN.DEFAULT_DELAY_MINUTES;
|
||||
let details = `${action.shutdownDelay ?? defaultShutdownDelay}min delay`;
|
||||
if (action.type === 'proxmox') {
|
||||
const mode = action.proxmoxMode || 'auto';
|
||||
if (mode === 'cli' || (mode === 'auto' && !action.proxmoxTokenId)) {
|
||||
|
||||
+13
-5
@@ -10,7 +10,7 @@ import type { TProtocol } from '../protocol/types.ts';
|
||||
import type { INupstConfig, IUpsConfig } from '../daemon.ts';
|
||||
import type { IActionConfig } from '../actions/base-action.ts';
|
||||
import { ProxmoxAction } from '../actions/proxmox-action.ts';
|
||||
import { UPSD } from '../constants.ts';
|
||||
import { SHUTDOWN, UPSD } from '../constants.ts';
|
||||
|
||||
/**
|
||||
* Thresholds configuration for CLI display
|
||||
@@ -1152,11 +1152,19 @@ export class UpsHandler {
|
||||
if (typeValue === 1) {
|
||||
// Shutdown action
|
||||
action.type = 'shutdown';
|
||||
const defaultShutdownDelay =
|
||||
this.nupst.getDaemon().getConfig().defaultShutdownDelay ?? SHUTDOWN.DEFAULT_DELAY_MINUTES;
|
||||
|
||||
const delayInput = await prompt('Shutdown delay in minutes [5]: ');
|
||||
const delay = parseInt(delayInput, 10);
|
||||
if (delayInput.trim() && !isNaN(delay)) {
|
||||
action.shutdownDelay = delay;
|
||||
const delayInput = await prompt(
|
||||
`Shutdown delay in minutes (leave empty for default ${defaultShutdownDelay}): `,
|
||||
);
|
||||
if (delayInput.trim()) {
|
||||
const delay = parseInt(delayInput, 10);
|
||||
if (isNaN(delay) || delay < 0) {
|
||||
logger.warn('Invalid shutdown delay, using configured default');
|
||||
} else {
|
||||
action.shutdownDelay = delay;
|
||||
}
|
||||
}
|
||||
} else if (typeValue === 2) {
|
||||
// Webhook action
|
||||
|
||||
Reference in New Issue
Block a user