Add Recent Runs visibility for rule executions (#376)

* Add Recent Runs visibility for rule executions

Adds a comprehensive tracking system for rule execution history with the following features:

- Creates RuleRun model to track execution metadata:
  * Date/time of execution
  * Execution type (manual/scheduled)
  * Success/failure status
  * Rule reference
  * Transaction counts (processed and modified)
  * Error messages for failed runs

- Updates RuleJob to automatically record execution results:
  * Captures transaction processing statistics
  * Handles success/failure states
  * Stores error details for debugging

- Adds "Recent Runs" section to rules index page:
  * Paginated display (20 runs per page)
  * Columnar layout similar to LLM usage page
  * Visual status indicators (success/failed badges)
  * Error tooltips for failed runs
  * Responsive design with design system tokens

- Includes i18n translations for all user-facing strings

This provides users with visibility into rule execution history, making it easier to debug issues and monitor rule performance.

* Update schema.rb with rule_runs table definition

* Linter noise

* Separate transaction counts into Queued, Processed, and Modified

Previously, the code eagerly reported transactions as "processed" when they
were only queued for processing. This commit separates the counts into three
distinct metrics:

- Transactions Queued: Count of transactions matching the rule's filter
  conditions before any processing begins
- Transactions Processed: Count of transactions that were actually processed
  and modified by the rule actions
- Transactions Modified: Count of transactions that had their values changed
  (currently same as Processed, but allows for future differentiation)

Changes:
- Add transactions_queued column to rule_runs table
- Update RuleJob to track all three counts separately
- Update action executors to return count of modified transactions
- Update Rule#apply to aggregate modification counts from actions
- Add transactions_queued label to locales
- Update Recent Runs view to display new column
- Add validation for transactions_queued in RuleRun model

The tracking now correctly reports:
1. How many transactions matched the filter (queued)
2. How many were actually modified (processed/modified)
3. Distinguishes between matching and modifying transactions

* Add Pending status to track async rule execution progress

Introduced a new "pending" status for rule runs to properly track async
AI operations. The system now:

- Tracks pending async jobs with a counter that decrements as jobs complete
- Updates transactions_modified incrementally as each job finishes
- Only counts transactions that were actually modified (not just queued)
- Displays pending status with yellow badge in the UI
- Automatically transitions from pending to success when all jobs complete

This provides better visibility into long-running AI categorization and
merchant detection operations, showing real-time progress as Sidekiq
processes the batches.

* Fix migration version to 7.2 as per project standards

* Consolidate rule_runs migrations into single migration file

Merged three separate migrations (create, add_transactions_queued,
add_pending_jobs_count) into a single CreateRuleRuns migration.
This provides better clarity and maintains a clean migration history.

Changes:
- Updated CreateRuleRuns migration to include all columns upfront
- Removed redundant add_column migrations
- Updated schema version to 2025_11_24_000000

* Linter and test fixes

* Space optimization

* LLM l10n is better than no l10n

* Fix implementation for tags/AI rules

* Fix tests

* Use batch_size

* Consider jobs "unknown" status sometimes

* Rabbit suggestion

* Rescue block for RuleRun.create!

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Juan José Mata
2025-12-07 16:30:02 +01:00
committed by GitHub
parent 04189dec00
commit bf90cad9a0
29 changed files with 636 additions and 45 deletions

View File

@@ -0,0 +1,24 @@
---
ca:
rules:
recent_runs:
title: Execucions Recents
description: Visualitza l'historial d'execució de les teves regles incloent l'estat d'èxit/fallada i els recomptes de transaccions.
unnamed_rule: Regla Sense Nom
columns:
date_time: Data/Hora
execution_type: Tipus
status: Estat
rule_name: Nom de la Regla
transactions_counts:
queued: En Cua
processed: Processades
modified: Modificades
execution_types:
manual: Manual
scheduled: Programada
statuses:
pending: Pendent
success: Èxit
failed: Fallada

View File

@@ -0,0 +1,24 @@
---
de:
rules:
recent_runs:
title: Letzte Ausführungen
description: Zeige die Ausführungsgeschichte deiner Regeln einschließlich Erfolgs-/Fehlerstatus und Transaktionsanzahlen.
unnamed_rule: Unbenannte Regel
columns:
date_time: Datum/Uhrzeit
execution_type: Typ
status: Status
rule_name: Regelname
transactions_counts:
queued: In Warteschlange
processed: Verarbeitet
modified: Geändert
execution_types:
manual: Manuell
scheduled: Geplant
statuses:
pending: Ausstehend
success: Erfolgreich
failed: Fehlgeschlagen

View File

@@ -0,0 +1,23 @@
---
en:
rules:
recent_runs:
title: Recent Runs
description: View the execution history of your rules including success/failure status and transaction counts.
unnamed_rule: Unnamed Rule
columns:
date_time: Date/Time
execution_type: Type
status: Status
rule_name: Rule Name
transactions_counts:
queued: Queued
processed: Processed
modified: Modified
execution_types:
manual: Manual
scheduled: Scheduled
statuses:
pending: Pending
success: Success
failed: Failed

View File

@@ -0,0 +1,24 @@
---
es:
rules:
recent_runs:
title: Ejecuciones Recientes
description: Ver el historial de ejecución de tus reglas incluyendo el estado de éxito/fallo y los conteos de transacciones.
unnamed_rule: Regla Sin Nombre
columns:
date_time: Fecha/Hora
execution_type: Tipo
status: Estado
rule_name: Nombre de Regla
transactions_counts:
queued: En Cola
processed: Procesadas
modified: Modificadas
execution_types:
manual: Manual
scheduled: Programada
statuses:
pending: Pendiente
success: Éxito
failed: Fallido

View File

@@ -0,0 +1,24 @@
---
nb:
rules:
recent_runs:
title: Siste Kjøringer
description: Se kjøringsloggen for reglene dine inkludert suksess/feil-status og transaksjonsantall.
unnamed_rule: Navnløs Regel
columns:
date_time: Dato/Tid
execution_type: Type
status: Status
rule_name: Regelnavn
transactions_counts:
queued: I Kø
processed: Behandlet
modified: Endret
execution_types:
manual: Manuell
scheduled: Planlagt
statuses:
pending: Ventende
success: Vellykket
failed: Mislyktes

View File

@@ -0,0 +1,24 @@
---
ro:
rules:
recent_runs:
title: Rulări Recente
description: Vezi istoricul de execuție al regulilor tale incluzând statusul de succes/eșec și numărul de tranzacții.
unnamed_rule: Regulă Fără Nume
columns:
date_time: Dată/Ora
execution_type: Tip
status: Status
rule_name: Nume Regulă
transactions_counts:
queued: În Așteptare
processed: Procesate
modified: Modificate
execution_types:
manual: Manual
scheduled: Programată
statuses:
pending: În Așteptare
success: Succes
failed: Eșuat

View File

@@ -0,0 +1,24 @@
---
tr:
rules:
recent_runs:
title: Son Çalıştırmalar
description: Başarı/başarısızlık durumu ve işlem sayıları dahil olmak üzere kurallarınızın yürütme geçmişini görüntüleyin.
unnamed_rule: İsimsiz Kural
columns:
date_time: Tarih/Saat
execution_type: Tür
status: Durum
rule_name: Kural Adı
transactions_counts:
queued: Kuyruğa Alındı
processed: İşlendi
modified: Değiştirildi
execution_types:
manual: Manuel
scheduled: Zamanlanmış
statuses:
pending: Beklemede
success: Başarılı
failed: Başarısız