synkrokonn-dev
Version:
Plugin-based cross-chain orchestration middleware for Web3 enterprise automation.
25 lines (24 loc) • 941 B
JavaScript
// src/core/RollbackManager.ts
export class RollbackManager {
constructor() {
this.rollbackSteps = [];
}
addRollbackStep(stepId, reverseFunction) {
this.rollbackSteps.unshift({ stepId, reverseFunction }); // Reverse order
}
async executeRollback(context) {
const contextId = context?.id || 'unknown';
console.log(`[ROLLBACK] Starting rollback for context ${contextId}`);
for (const step of this.rollbackSteps) {
try {
console.log(`[ROLLBACK] Reversing step ${step.stepId}...`);
await step.reverseFunction();
console.log(`[ROLLBACK] Step ${step.stepId} rolled back successfully.`);
}
catch (err) {
console.error(`[ROLLBACK] Failed to rollback step ${step.stepId}:`, err);
}
}
console.log(`[ROLLBACK] Rollback complete for context ${contextId}`);
}
}