Sistema de ejecución de limpieza automatizada
Este es unDevOpsflujo de automatización del dominio deautomatización que contiene 12 nodos.Utiliza principalmente nodos como N8n, Set, Code, ScheduleTrigger. Sistema automatizado de ejecución y limpieza con API de n8n y reglas de retención personalizadas
- •No hay requisitos previos especiales, puede importar y usarlo directamente
Nodos utilizados (12)
Categoría
{
"meta": {
"instanceId": "0a82a9d5784b67ad963ceff89283b2e40cb771be10fe58ba2682f3598a37c6e1",
"templateCredsSetupCompleted": true
},
"nodes": [
{
"id": "fc2eb1d2-8c2e-4956-a084-ef685652cdbd",
"name": "Disparador programado",
"type": "n8n-nodes-base.scheduleTrigger",
"position": [
320,
-32
],
"parameters": {
"rule": {
"interval": [
{
"triggerAtHour": 2
}
]
}
},
"typeVersion": 1.2
},
{
"id": "f528c67c-0077-4d84-a756-5b9020b838d8",
"name": "Get many executions",
"type": "n8n-nodes-base.n8n",
"position": [
816,
-32
],
"parameters": {
"limit": 250,
"filters": {},
"options": {
"activeWorkflows": false
},
"resource": "execution",
"requestOptions": {}
},
"credentials": {
"n8nApi": {
"id": "VSxAuLMW3kDlXjYA",
"name": "EMPTY"
}
},
"typeVersion": 1
},
{
"id": "9e3f98f2-f2f6-4d15-8858-1dacc46582a0",
"name": "Código",
"type": "n8n-nodes-base.code",
"position": [
1824,
-32
],
"parameters": {
"jsCode": "const executionsToKeep = $input.first().json.executionsToKeep ?? 10;\n\n// Filtrar ejecuciones válidas (con workflowId y startedAt)\nconst validExecutions = items.filter(item =>\n item.json.workflowId && item.json.startedAt\n);\n\n// Agrupar por workflowId\nconst grouped = {};\nfor (const item of validExecutions) {\n const wfId = item.json.workflowId;\n if (!grouped[wfId]) grouped[wfId] = [];\n grouped[wfId].push(item);\n}\n\n// Ordenar por startedAt descendente (más reciente primero)\nfor (const wfId in grouped) {\n grouped[wfId].sort((a, b) =>\n new Date(b.json.startedAt) - new Date(a.json.startedAt)\n );\n}\n\n// Obtener ejecuciones a eliminar\nlet toDelete = [];\nfor (const wfId in grouped) {\n const executions = grouped[wfId];\n if (executions.length > executionsToKeep) {\n toDelete = toDelete.concat(executions.slice(executionsToKeep));\n }\n}\n\nreturn toDelete;\n"
},
"typeVersion": 2
},
{
"id": "68e8939a-10f0-4a65-a56c-5f643d2dceec",
"name": "Delete an execution",
"type": "n8n-nodes-base.n8n",
"position": [
2304,
-32
],
"parameters": {
"resource": "execution",
"operation": "delete",
"executionId": "={{ $json.id }}",
"requestOptions": {}
},
"credentials": {
"n8nApi": {
"id": "VSxAuLMW3kDlXjYA",
"name": "EMPTY"
}
},
"typeVersion": 1
},
{
"id": "c59692b1-8dc8-44f8-bd31-dcc3898a2978",
"name": "Nota adhesiva",
"type": "n8n-nodes-base.stickyNote",
"position": [
-800,
-880
],
"parameters": {
"width": 896,
"height": 1680,
"content": "# 🧹 Automatically Clean Up Old Executions in n8n (Keep Only the Most Recent Per Workflow)\nMake your n8n instance faster, cleaner, and more efficient by deleting old workflow executions — while keeping only the most recent ones you actually need. Whether you're using n8n Cloud or self-hosted, this lightweight workflow helps reduce database/storage usage and improves UI responsiveness, using only official n8n nodes.\n\n## 🔍 Description\nAutomatically clean up old executions in your n8n instance using only official nodes — no external database queries required. Whether you're on the Cloud version or running self-hosted, this workflow helps you optimize performance and keep your instance tidy by maintaining only the most recent executions per workflow.\n\nIdeal for users managing dozens or hundreds of workflows, this solution reduces storage usage and improves the responsiveness of the n8n UI, especially in environments where execution logs can accumulate quickly.\n\n✅ What It Does\n* Retrieves up to 250 recent executions across all workflows\n* Groups executions by workflow\n* Keeps only the most recent N executions per workflow (value is configurable)\n* Deletes all older executions (regardless of their status: success, error, etc.)\n* Works entirely with native n8n nodes — no external database access required\n* Optionally: set the number of executions to keep as 0 to delete all past executions from your instance in a single run\n\n## 🛠️ How to Set Up\n🔑 Create a Personal API Key in your n8n instance:\nGo to Settings → API Keys → Create a new key\n\n🔧 Create a new n8n API Credential (used by both nodes):\nIn your n8n credentials panel:\n\nName: anything you like (e.g., “Internal API Access”)\n\nAPI Key: paste the Personal API Key you just created\n\nBase URL: your full n8n instance URL with the /api/v1 path, e.g.\nhttps://your-n8n-instance.com/api/v1\n\n✅ Use this credential in both:\n\nThe Get Many Executions node (to fetch recent executions)\n\nThe Delete Many Executions node (to remove outdated executions)\n\n🧩 In the “Set Executions to Keep” node:\n\nEdit the variable executionsToKeep and set the number of most recent executions to retain per workflow (e.g. 10)\n\nTip: Set it to 0 to delete all executions\n\n📦 Note: The “Get Many Executions” node will retrieve up to 250 executions per run — this is the maximum allowed by the n8n API.\n\n🧠 No further setup is required — the filtering and grouping logic is handled inside the Code Node automatically.\n\n\n## 🧪 Included Nodes Overview\n🕒 Schedule Trigger → Set to run daily, weekly, etc.\n\n📥 Get Many Executions → Fetches past executions via n8n API\n\n🛠️ Set Executions to Keep → Set how many recent ones to keep\n\n🧠 Code Node → Filters out executions to delete per workflow\n\n🗑️ Delete Executions → Deletes outdated executions\n\n## 💡 Why Use This?\nReduce clutter and improve performance in your n8n instance\n\nMaintain execution logs only when they’re useful\n\nAvoid bloating your storage or database with obsolete data\n\nCompatible with both n8n Cloud and self-hosted setups\n\nUses only official, supported n8n nodes — no SQL, no extra setup\n\n🔒 This workflow modifies and deletes execution data. Always review and test it first on a staging instance or on a limited set of workflows before using it in production.\n\n\n\n\n"
},
"typeVersion": 1
},
{
"id": "8ecf0fc5-9917-474c-b3f2-32d45ecf7059",
"name": "Establecer Executions to Keep",
"type": "n8n-nodes-base.set",
"position": [
1328,
-32
],
"parameters": {
"options": {},
"assignments": {
"assignments": [
{
"id": "a7f3a2de-0606-434c-8a81-4bf64e766899",
"name": "executionsToKeep",
"type": "number",
"value": 10
}
]
},
"includeOtherFields": true
},
"typeVersion": 3.4
},
{
"id": "a249ad6e-6abc-42b8-a272-506c0f3f76a6",
"name": "Nota adhesiva1",
"type": "n8n-nodes-base.stickyNote",
"position": [
128,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# 🕒 Schedule Trigger\nThis node defines how often the cleanup workflow should run. You can schedule it to execute daily, weekly, or at any custom interval.\n[to learn more about Schedule Trigger node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.scheduletrigger/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.scheduleTrigger)"
},
"typeVersion": 1
},
{
"id": "7f7c076d-2bb6-4cef-88c2-6fef8e22f4e1",
"name": "Nota adhesiva2",
"type": "n8n-nodes-base.stickyNote",
"position": [
624,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# 📥 Get Many Executions\nFetches up to 250 of the most recent executions from your n8n instance. It includes data like workflow ID, execution status, and timestamps.\n[to learn more about Get Many Executions node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.n8n/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.n8n#get-many-executions)"
},
"typeVersion": 1
},
{
"id": "b2be8559-6cbd-4778-8830-4fa467efe363",
"name": "Nota adhesiva3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1120,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# 🛠️ Set Executions to Keep\nThis node defines how many of the most recent executions per workflow should be kept. You can easily adjust the executionsToKeep variable — set it to 10, 5, or 0 to delete all.\n[to learn more about Set node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.set/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.set)"
},
"typeVersion": 1
},
{
"id": "f31f51a1-70ba-46f5-adbb-4752b6c6d2c8",
"name": "Nota adhesiva4",
"type": "n8n-nodes-base.stickyNote",
"position": [
1616,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# 🧠 Code Node (Filter Executions to Delete)\nThis node processes the list of executions, groups them by workflow ID, sorts each group by most recent first, and filters out the oldest executions beyond the number you want to keep. Running executions are automatically excluded.\n[o learn more about Code node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.code/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.code)"
},
"typeVersion": 1
},
{
"id": "a7b5add2-eab2-4b79-b7d3-6e84fb4dc118",
"name": "Nota adhesiva5",
"type": "n8n-nodes-base.stickyNote",
"position": [
2112,
-720
],
"parameters": {
"color": 7,
"width": 464,
"height": 1520,
"content": "# 🗑️ Delete Many Executions\nDeletes the selected executions using the official n8n API. It works in bulk and uses the same API credential as the \"Get Many Executions\" node.\n[to learn more about Delete Executions node see the documentation](https://docs.n8n.io/integrations/builtin/core-nodes/n8n-nodes-base.n8n/?utm_source=n8n_app&utm_medium=node_settings_modal-credential_link&utm_campaign=n8n-nodes-base.n8n#delete-execution)"
},
"typeVersion": 1
},
{
"id": "00e57fb6-961a-4e85-81c6-2de04f301a93",
"name": "Nota adhesiva6",
"type": "n8n-nodes-base.stickyNote",
"position": [
128,
-880
],
"parameters": {
"color": 3,
"width": 2432,
"height": 128,
"content": "# ❗ This workflow deletes data. Always test in staging before enabling in production. "
},
"typeVersion": 1
}
],
"pinData": {},
"connections": {
"Code": {
"main": [
[
{
"node": "68e8939a-10f0-4a65-a56c-5f643d2dceec",
"type": "main",
"index": 0
}
]
]
},
"Schedule Trigger": {
"main": [
[
{
"node": "f528c67c-0077-4d84-a756-5b9020b838d8",
"type": "main",
"index": 0
}
]
]
},
"68e8939a-10f0-4a65-a56c-5f643d2dceec": {
"main": [
[]
]
},
"f528c67c-0077-4d84-a756-5b9020b838d8": {
"main": [
[
{
"node": "Set Executions to Keep",
"type": "main",
"index": 0
}
]
]
},
"Set Executions to Keep": {
"main": [
[
{
"node": "Code",
"type": "main",
"index": 0
}
]
]
}
}
}¿Cómo usar este flujo de trabajo?
Copie el código de configuración JSON de arriba, cree un nuevo flujo de trabajo en su instancia de n8n y seleccione "Importar desde JSON", pegue la configuración y luego modifique la configuración de credenciales según sea necesario.
¿En qué escenarios es adecuado este flujo de trabajo?
Intermedio - DevOps
¿Es de pago?
Este flujo de trabajo es completamente gratuito, puede importarlo y usarlo directamente. Sin embargo, tenga en cuenta que los servicios de terceros utilizados en el flujo de trabajo (como la API de OpenAI) pueden requerir un pago por su cuenta.
Flujos de trabajo relacionados recomendados
Arlin Perez
@arlindeveloper👋 Hi! I'm Arlin - a QA Engineer with 2 years of experience and a background in Dart & Flutter for mobile app development. ⚙️ I'm passionate about automation and love building efficient workflows using n8n. 📬 Reach out for any help with custom workflows
Compartir este flujo de trabajo