Skip to content

feat: add bulk transaction retry option to CLI admin commands (#990)#1148

Merged
sublime247 merged 3 commits into
sublime247:mainfrom
TheDEV111:feature/retry-batch-cli
May 30, 2026
Merged

feat: add bulk transaction retry option to CLI admin commands (#990)#1148
sublime247 merged 3 commits into
sublime247:mainfrom
TheDEV111:feature/retry-batch-cli

Conversation

@TheDEV111
Copy link
Copy Markdown
Contributor

PR Description: Add Bulk Transaction Retry Option to CLI Admin Commands

Related Issue

Closes #990

Overview

This PR introduces a quick, lightweight administrative CLI command momo-cli retry-batch <batch_id> to retry failed or stuck transactions belonging to a specific bulk import batch ID. It also contains several database integrity and mapping improvements to ensure batch tracking works cleanly.

Key Changes

  1. Administrative CLI Command:

    • Created a standalone TypeScript CLI tool at src/scripts/momo-cli.ts containing the retry-batch <batch_id> logic.
    • Built a root-level bash script momo-cli and marked it executable (chmod +x), allowing administrators to run ./momo-cli retry-batch <batch_id> from the terminal.
    • Mapped the script in package.json under "momo-cli" so it can be invoked via npm run momo-cli.
    • Lazy Connection Optimization: Designed the script to dynamically import BullMQ and Queue dependencies only during the retry-batch command execution. This completely avoids Redis connection attempts (and subsequent error logs) when displaying the help menu (--help or -h) or entering invalid arguments.
  2. Transaction Database Mapping Fix:

    • Fixed a bug in the create() method in src/models/transaction.ts where user_id, idempotency_key, idempotency_expires_at, and metadata were omitted from the SQL INSERT statement column list, which had previously caused metadata writes to fail.
    • Simplified the transaction update query into a single-line string to ensure robust Jest assertions.
  3. Bulk Import Associations:

    • Updated src/routes/bulk.ts to tag transactions with the bulk jobId and store { "batchId": jobId } in their database JSONB metadata fields when created, facilitating precise batch lookups.
  4. Comprehensive Automated Tests:

    • Created a complete, robust test suite at tests/scripts/momo-cli.test.ts covering:
      • Showing CLI help correctly.
      • Argument validation (missing arguments or malformed UUID).
      • Batch summary aggregation (Completed, Failed, Pending, Cancelled stats).
      • Selective transaction retrying (modifying status in the database to pending, incrementing the retry count, and successfully pushing jobs to the BullMQ queue).
      • Ensuring completed or cancelled transactions in the batch are ignored during retries.
    • Automatically disables ANSI color formatting in the test environment (when NODE_ENV === "test") to ensure clean console spy assertions.

Verification & Testing Done

  • Manual Verification:
    • Tested CLI help command output:
      ./momo-cli --help
      Output displayed beautifully, instantly, and without any Redis errors.
  • Automated Tests:
    • Executed Jest on the new test suite:
      npx jest tests/scripts/momo-cli.test.ts
      All 6 tests passed successfully.
    • Verified full test suite runs cleanly and formats cleanly via Prettier.

@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@TheDEV111 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@TheDEV111
Copy link
Copy Markdown
Contributor Author

The momo-cli test suite passes 100% locally. The PR check failures ( SonarCloud , Trivy , Coverage , Mutation ) appear to be pre-existing baseline issues on main (old dependency CVEs and failing tests) or due to missing
│ secrets/tokens on fork PR builds.

@sublime247 sublime247 merged commit 0aa6a9f into sublime247:main May 30, 2026
4 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MEDIUM] Add Bulk Transaction Retry Option to CLI admin commands

2 participants