class ExecutionTracker {
constructor() {
this.lists = {}; // Store lists with execution status
}
/**
* Adds a new list to the tracker.
* @param {string} listName The name of the list.
*/
addList(listName) {
if (!this.lists[listName]) {
this.lists[listName] = {
items: [],
executed: false,
errors: [],
lastExecuted: null
};
}
}
/**
* Adds an item to a list.
* @param {string} listName The name of the list.
* @param {any} item The item to add.
*/
addItem(listName, item) {
if (!this.lists[listName]) {
this.addList(listName);
}
this.lists[listName].items.push(item);
}
/**
* Marks a list as executed.
* @param {string} listName The name of the list.
*/
executeList(listName) {
if (!this.lists[listName]) {
console.warn(`List "${listName}" not found.`);
return;
}
this.lists[listName].executed = true;
this.lists[listName].lastExecuted = new Date();
this.lists[listName].errors = []; // Reset errors
this.processList(listName);
}
/**
* Processes a list, simulating quick fixes.
* @param {string} listName The name of the list.
*/
processList(listName) {
const list = this.lists[listName];
for (const item of list.items) {
try {
// Simulate a quick fix/check
if (typeof item === 'string' && item.length > 10) {
// Example fix: Truncate long strings
const fixedItem = item.substring(0, 10) + "...";
console.log(`Fixed: ${item} -> ${fixedItem}`);
list.items[list.items.indexOf(item)] = fixedItem; // Update the item
} else if (typeof item === 'number' && item < 0) {
//Example fix: Make numbers positive
const fixedItem = Math.abs(item);
console.log(`Fixed: ${item} -> ${fixedItem}`);
list.items[list.items.indexOf(item)] = fixedItem;
}
} catch (error) {
console.error(`Error processing item ${item} in list ${listName}:`, error);
list.errors.push({ item, error });
}
}
}
/**
* Gets the execution status of a list.
* @param {string} listName The name of the list.
* @returns {object} An object containing the list's status.
*/
getListStatus(listName) {
if (!this.lists[listName]) {
console.warn(`List "${listName}" not found.`);
return null;
}
return this.lists[listName];
}
/**
* Logs all errors across all lists.
*/
logAllErrors() {
for (const listName in this.lists) {
if (this.lists.hasOwnProperty(listName)) {
const list = this.lists[listName];
if (list.errors.length > 0) {
console.warn(`Errors in list "${listName}":`);
list.errors.forEach(error => {
console.error(` Item: ${error.item}, Error: ${error.error}`);
});
}
}
}
}
}
// Example Usage:
const tracker = new ExecutionTracker();
tracker.addList("config_values");
tracker.addItem("config_values", "This is a long string");
tracker.addItem("config_values", 123);
tracker.addItem("config_values", -5);
tracker.executeList("config_values");
tracker.executeList("config_values");
console.log(tracker.getListStatus("config_values")); // Access the status
tracker.logAll
Add your comment