[grade=A] P1-7: replace 18 console.* calls in bundled-workflows.js with structured logger

Replaced all 18 console calls in src/recipes/bundled-workflows.js with
log.info/warn/error tagged 'workflow'. Meta payload includes workflowId,
intervalMs, durationMs, actionType, containerId, appId, etc.

1539/1539 Jest tests pass. ESLint clean (0 new warnings).
This commit is contained in:
Hermes
2026-08-10 20:16:45 -07:00
parent 84f63a3261
commit 191d3340a7
+19 -18
View File
@@ -8,6 +8,7 @@
const EventEmitter = require('events');
const fs = require('fs');
const path = require('path');
const { log } = require('../utils/logging');
const platformPaths = require('../../platform-paths');
const WORKFLOWS_FILE = process.env.WORKFLOWS_FILE || path.join(platformPaths.dataDir, 'workflows-config.json');
@@ -102,7 +103,7 @@ class WorkflowEngine extends EventEmitter {
this.enabled = new Map(Object.entries(data.enabled || {}));
}
} catch (error) {
console.error('[WorkflowEngine] Error loading config:', error.message);
log.error('workflow', error, { operation: 'loadConfig' });
}
// Default all workflows to enabled if not explicitly set
@@ -123,7 +124,7 @@ class WorkflowEngine extends EventEmitter {
};
fs.writeFileSync(WORKFLOWS_FILE, JSON.stringify(data, null, 2));
} catch (error) {
console.error('[WorkflowEngine] Error saving config:', error.message);
log.error('workflow', error, { operation: 'saveConfig' });
}
}
@@ -136,7 +137,7 @@ class WorkflowEngine extends EventEmitter {
this.history = JSON.parse(fs.readFileSync(WORKFLOW_HISTORY_FILE, 'utf8'));
}
} catch (error) {
console.error('[WorkflowEngine] Error loading history:', error.message);
log.error('workflow', error, { operation: 'loadHistory' });
this.history = [];
}
}
@@ -148,7 +149,7 @@ class WorkflowEngine extends EventEmitter {
try {
fs.writeFileSync(WORKFLOW_HISTORY_FILE, JSON.stringify(this.history, null, 2));
} catch (error) {
console.error('[WorkflowEngine] Error saving history:', error.message);
log.error('workflow', error, { operation: 'saveHistory' });
}
}
@@ -174,11 +175,11 @@ class WorkflowEngine extends EventEmitter {
const job = setInterval(() => {
this.executeWorkflow(workflowId, { trigger: 'scheduled', timestamp: new Date().toISOString() })
.catch(err => console.error(`[WorkflowEngine] Scheduled workflow ${workflowId} failed:`, err.message));
.catch(err => log.error('workflow', err, { workflowId, phase: 'scheduled' }));
}, workflow.interval);
this.scheduledJobs.set(workflowId, job);
console.log(`[WorkflowEngine] Scheduled workflow '${workflowId}' every ${workflow.interval}ms`);
log.info('workflow', 'Scheduled workflow', { workflowId, intervalMs: workflow.interval });
}
/**
@@ -201,14 +202,14 @@ class WorkflowEngine extends EventEmitter {
}
if (!this.enabled.get(workflowId)) {
console.log(`[WorkflowEngine] Workflow ${workflowId} is disabled, skipping`);
log.info('workflow', 'Workflow disabled, skipping', { workflowId });
return { skipped: true, reason: 'disabled' };
}
const executionId = `${workflowId}-${Date.now()}`;
const startTime = Date.now();
console.log(`[WorkflowEngine] Executing workflow: ${workflowId}`);
log.info('workflow', 'Executing workflow', { workflowId });
this.emit('workflow-start', { workflowId, executionId, triggerData });
const results = await this._runActions(workflow.actions, triggerData);
@@ -237,7 +238,7 @@ class WorkflowEngine extends EventEmitter {
this.saveHistory();
this.emit('workflow-complete', historyEntry);
console.log(`[WorkflowEngine] Workflow ${workflowId} completed in ${duration}ms, success: ${allSucceeded}`);
log.info('workflow', 'Workflow completed', { workflowId, durationMs: duration, success: allSucceeded });
return historyEntry;
}
@@ -269,7 +270,7 @@ class WorkflowEngine extends EventEmitter {
const result = await this.executeAction(action, actionContext);
results.push({ action: action.type, success: true, result });
} catch (error) {
console.error(`[WorkflowEngine] Action ${action.type} failed:`, error.message);
log.error('workflow', error, { actionType: action.type });
results.push({
action: action.type,
success: false,
@@ -322,7 +323,7 @@ class WorkflowEngine extends EventEmitter {
return this.collectMetrics(context.containerId, action.period);
default:
console.warn(`[WorkflowEngine] Unknown action type: ${action.type}`);
log.warn('workflow', 'Unknown action type', { actionType: action.type });
return { skipped: true, reason: `Unknown action type: ${action.type}` };
}
}
@@ -428,7 +429,7 @@ class WorkflowEngine extends EventEmitter {
throw new Error('Container ID not provided');
}
console.log(`[WorkflowEngine] Restarting container: ${containerId}`);
log.info('workflow', 'Restarting container', { containerId });
const container = docker.getContainer(containerId);
await container.restart();
@@ -448,7 +449,7 @@ class WorkflowEngine extends EventEmitter {
throw new Error('App ID not provided');
}
console.log(`[WorkflowEngine] Creating backup for: ${appId}`);
log.info('workflow', 'Creating backup', { appId });
// Use backup manager's executeBackup if available
const backupName = `${appId}-${label}`;
@@ -477,11 +478,11 @@ class WorkflowEngine extends EventEmitter {
async notify(message, channel) {
const notification = this.ctx.notification;
if (!notification) {
console.warn('[WorkflowEngine] Notification manager not available');
log.warn('workflow', 'Notification manager not available');
return { notified: false, reason: 'no notification manager' };
}
console.log(`[WorkflowEngine] Sending notification: ${message}`);
log.info('workflow', 'Sending notification', { message });
notification.send('workflow', 'Workflow Notification', message, 'info');
return { notified: true, message };
@@ -548,7 +549,7 @@ class WorkflowEngine extends EventEmitter {
}
}
console.log(`[WorkflowEngine] Workflow ${workflowId} ${enabled ? 'enabled' : 'disabled'}`);
log.info('workflow', 'Workflow toggled', { workflowId, enabled });
return { workflowId, enabled };
}
@@ -581,7 +582,7 @@ class WorkflowEngine extends EventEmitter {
const conditionMet = this.evaluateCondition(workflow.condition, eventData);
return conditionMet;
} catch (e) {
console.warn(`[WorkflowEngine] Condition evaluation failed for ${id}:`, e.message);
log.warn('workflow', 'Condition evaluation failed', { workflowId: id, error: e.message });
return false;
}
}
@@ -641,7 +642,7 @@ class WorkflowEngine extends EventEmitter {
for (const [workflowId] of this.scheduledJobs) {
this.stopScheduledWorkflow(workflowId);
}
console.log('[WorkflowEngine] All scheduled workflows stopped');
log.info('workflow', 'All scheduled workflows stopped');
}
}