Skip to content

Handle concurrent order taking: refactor PerOrderIdMutex, move it to util/index.ts for more clean reusability [1/2]#823

Merged
grunch merged 2 commits into
mainfrom
refactor/move-per-order-id-mutex
Jun 8, 2026
Merged

Handle concurrent order taking: refactor PerOrderIdMutex, move it to util/index.ts for more clean reusability [1/2]#823
grunch merged 2 commits into
mainfrom
refactor/move-per-order-id-mutex

Conversation

@Luquitasjeffrey

@Luquitasjeffrey Luquitasjeffrey commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Summary by CodeRabbit

  • Chores
    • Internal code reorganization to centralize utility functions and improve maintainability.

@coderabbitai

coderabbitai Bot commented May 31, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: cb70f928-263c-417a-a056-991a2ff5f6af

📥 Commits

Reviewing files that changed from the base of the PR and between e838c79 and 04aacc1.

📒 Files selected for processing (4)
  • jobs/cancel_orders.ts
  • jobs/check_hold_invoice_expired.ts
  • ln/subscribe_invoice.ts
  • util/index.ts

Walkthrough

This PR consolidates the PerOrderIdMutex per-order locking utility from a Lightning Network-specific module into the shared utilities module, then updates all consumer code to import from the new location. The implementation moves unchanged; only its location and export sites are refactored.

Changes

PerOrderIdMutex Utility Consolidation

Layer / File(s) Summary
Introduce PerOrderIdMutex in util module
util/index.ts
Adds Mutex from async-mutex dependency, implements PerOrderIdMutex class that manages a map of per-orderId mutex instances with lock counting and lifecycle cleanup, and exports it.
Refactor ln/subscribe_invoice.ts to use util-exported PerOrderIdMutex
ln/subscribe_invoice.ts
Updates util import to include PerOrderIdMutex and removes it from the module's public exports, transitioning from local implementation to shared utility.
Update consumer modules to import from util
jobs/cancel_orders.ts, jobs/check_hold_invoice_expired.ts
Both job files update their imports to source PerOrderIdMutex from ../util instead of ../ln/subscribe_invoice.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

  • lnp2pBot/bot#746: Introduced initial use of PerOrderIdMutex in jobs/check_hold_invoice_expired.ts around per-order locking behavior.
  • lnp2pBot/bot#705: Likely addresses related per-order mutex usage patterns in job scheduling.

Suggested reviewers

  • grunch
  • Catrya
  • mostronatorcoder

Poem

🐰 Locks and keys find their home,
From subscribe's nest they roam,
To util's shared embrace,
Order mutexes find their place!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main change: refactoring PerOrderIdMutex and moving it from ln/subscribe_invoice.ts to util/index.ts for improved reusability, which is accurately reflected in all the file changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/move-per-order-id-mutex

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@ermeme ermeme Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed only the changes in scope of this PR. The refactor is clean and I did not find functional issues.

@grunch grunch left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@grunch grunch merged commit 6978372 into main Jun 8, 2026
7 checks passed
@grunch grunch deleted the refactor/move-per-order-id-mutex branch June 8, 2026 18:02
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.

2 participants