Skip to content

fix(billing): properly filters active leases and triggers the job#2354

Merged
ygrishajev merged 2 commits intomainfrom
feature/auto-reload
Dec 15, 2025
Merged

fix(billing): properly filters active leases and triggers the job#2354
ygrishajev merged 2 commits intomainfrom
feature/auto-reload

Conversation

@ygrishajev
Copy link
Contributor

@ygrishajev ygrishajev commented Dec 15, 2025

refs #1779

Summary by CodeRabbit

Release Notes

  • New Features

    • Auto top-up settings now automatically trigger immediate wallet reloads when enabled.
  • Improvements

    • Enhanced filtering to properly manage active deployments and leases in the system.
  • Documentation

    • Updated method documentation for cost calculation to clarify deployment closure behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@ygrishajev ygrishajev requested a review from a team as a code owner December 15, 2025 14:54
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 15, 2025

Walkthrough

This PR integrates wallet reload job scheduling into the deployment setting creation flow by injecting WalletReloadJobService and triggering an immediate reload when auto top-up is enabled. Additionally, the draining deployment RPC service is updated to filter results by active state, and documentation is clarified.

Changes

Cohort / File(s) Change Summary
Wallet Reload Integration
apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts
Injects WalletReloadJobService via constructor and schedules an immediate wallet reload job for the associated user after creating a deployment setting if autoTopUpEnabled is true.
Active State Filtering
apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.ts
Updates lease and deployment RPC fetch flows to filter results by state equal to "active" before applying dseq filter, ensuring only active items are considered.
Test & Documentation Updates
apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.spec.ts, apps/api/src/deployment/services/draining-deployment/draining-deployment.service.ts
Test descriptions and expectations updated to reflect closedHeight behavior tied to closed_on value; deployment test objects now explicitly include active state. JSDoc clarified for calculateAllDeploymentCostUntilDate parameter describing target date behavior.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

  • Verify WalletReloadJobService injection and scheduleImmediate call is properly integrated with autoTopUpEnabled check
  • Confirm state filtering logic correctly restricts draining deployment RPC results to active items
  • Review test expectations align with updated closed_on semantics

Possibly related PRs

Suggested reviewers

  • baktun14

Poem

🐰 A wallet hops with joy,
When settings dance with auto-pay,
Reloads hop forth right away,
Active states now filter fray,
Code's more clear—what a ploy! ✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately captures the main changes: filtering active leases/deployments and triggering wallet reload jobs when auto top-up is enabled.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feature/auto-reload

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 759c702 and 0ce5f90.

📒 Files selected for processing (4)
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts (3 hunks)
  • apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.spec.ts (2 hunks)
  • apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.ts (2 hunks)
  • apps/api/src/deployment/services/draining-deployment/draining-deployment.service.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/general.mdc)

**/*.{ts,tsx,js}: Never use type any or cast to type any. Always define the proper TypeScript types.
Never use deprecated methods from libraries.
Don't add unnecessary comments to the code.

Files:

  • apps/api/src/deployment/services/draining-deployment/draining-deployment.service.ts
  • apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts
  • apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.ts
  • apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.spec.ts
**/*.spec.{ts,tsx}

📄 CodeRabbit inference engine (.cursor/rules/no-jest-mock.mdc)

Don't use jest.mock() in test files. Instead, use jest-mock-extended to create mocks and pass mocks as dependencies to the service under test

Use setup function instead of beforeEach in test files. The setup function must be at the bottom of the root describe block, should create an object under test and return it, accept a single parameter with inline type definition, avoid shared state, and not have a specified return type.

**/*.spec.{ts,tsx}: Use <Subject>.name in the root describe suite description instead of hardcoded class/service name strings to enable automated refactoring tools to find all references
Use either a method name or a condition starting with 'when' for nested suite descriptions in tests
Use present simple, 3rd person singular for test descriptions without prepending 'should'

Files:

  • apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.spec.ts
🧠 Learnings (1)
📚 Learning: 2025-06-03T15:06:34.211Z
Learnt from: baktun14
Repo: akash-network/console PR: 1428
File: apps/api/src/deployment/controllers/deployment/deployment.controller.ts:0-0
Timestamp: 2025-06-03T15:06:34.211Z
Learning: The `getByOwnerAndDseq` method in `apps/api/src/deployment/controllers/deployment/deployment.controller.ts` is intentionally public without the `Protected` decorator because it serves public blockchain data from an indexer, following the pattern of public blockchain APIs.

Applied to files:

  • apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: validate / validate-app
  • GitHub Check: test-build
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (4)
apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.ts (1)

60-60: LGTM! Active state filtering properly implemented.

The filtering logic correctly restricts results to active leases and deployments before applying the dseq filter. This ensures that only currently active resources are considered in the draining deployment calculations.

Also applies to: 87-87

apps/api/src/deployment/services/draining-deployment/draining-deployment.service.ts (1)

127-127: LGTM! Documentation clarification.

The updated JSDoc parameter description provides better clarity about the targetDate parameter's role in determining both cost calculation and deployment closure timing.

apps/api/src/deployment/services/draining-deployment-rpc/draining-deployment-rpc.service.spec.ts (1)

169-174: LGTM! Test updates align with implementation.

The test changes correctly reflect the new behavior where:

  • closedHeight is determined by the closed_on field rather than the state
  • Leases and deployments can have state: "active" while still having closure information
  • Test fixtures now explicitly set state: "active" to match the filtering logic in the implementation

Also applies to: 251-252

apps/api/src/deployment/services/deployment-setting/deployment-setting.service.ts (1)

8-8: LGTM! Wallet reload job integration properly implemented.

The integration of WalletReloadJobService correctly triggers an immediate wallet reload when a deployment setting is created with autoTopUpEnabled set to true. The await on scheduleImmediate ensures that any scheduling failures will propagate, maintaining proper error handling.

Also applies to: 29-29, 51-57


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

@codecov
Copy link

codecov bot commented Dec 15, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 51.03%. Comparing base (e1bcc8e) to head (1613a09).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2354      +/-   ##
==========================================
- Coverage   51.31%   51.03%   -0.29%     
==========================================
  Files        1060     1050      -10     
  Lines       28947    28603     -344     
  Branches     6315     6337      +22     
==========================================
- Hits        14855    14597     -258     
- Misses      13685    13721      +36     
+ Partials      407      285     -122     
Flag Coverage Δ *Carryforward flag
api 80.97% <100.00%> (+0.01%) ⬆️
deploy-web 31.04% <ø> (ø) Carriedforward from 0ce5f90
log-collector ?
notifications 87.94% <ø> (ø) Carriedforward from 0ce5f90
provider-console 81.48% <ø> (ø) Carriedforward from 0ce5f90
provider-proxy 84.35% <ø> (ø) Carriedforward from 0ce5f90

*This pull request uses carry forward flags. Click here to find out more.

Files with missing lines Coverage Δ
...s/deployment-setting/deployment-setting.service.ts 92.00% <100.00%> (+0.88%) ⬆️
...-deployment-rpc/draining-deployment-rpc.service.ts 98.57% <100.00%> (ø)
...draining-deployment/draining-deployment.service.ts 96.34% <ø> (ø)

... and 49 files with indirect coverage changes

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Comments