fix(metering,health): dedupe metered usage on retry (#1151) and bound health-check cron (#1152) - #1190
Open
ayomidearegbeshola29-dev wants to merge 3 commits into
Conversation
… and bound health-check cron (StellerCraft#1152) StellerCraft#1151: thread an optional logical idempotency key through reportUsage -> MeteringService.recordUsage. When a stable key is supplied (e.g. the payment idempotency key for a checkout), a replayed event returns the existing usage record WITHOUT incrementing quantity, preventing duplicate metered billing across second boundaries. Legacy one-second-granularity keying is preserved for plain API-call tracking. StellerCraft#1152: HealthMonitorService gains checkAllDeploymentsPaged({cursor, limit}) that returns { results, nextCursor, totalProcessed }. The cron health-check route now pages through deployments, resuming via cursor and stopping once the configured HEALTH_CHECK_BUDGET_MS (default 60s) is exceeded, so a single sweep can no longer run unbounded / time out. checkAllDeployments() is kept for backward compatibility.
… persist checkpoint (StellerCraft#1152) - HealthMonitorService.checkAllDeploymentsPaged now runs its page's health checks through a bounded concurrency pool (default 10) instead of an unbounded Promise.all, so a large fleet stays within the cron budget. - Add getCheckpoint/saveCheckpoint backed by a new cron_checkpoints table (migration 014). The cron route resumes from the persisted cursor on the NEXT invocation, so a sweep truncated by the platform execution limit continues where it left off rather than restarting from the top. - Add health-check.cascade.integration.test.ts: a 500-deployment fleet completes within the documented budget, and a budget-truncated run checkpoints progress and resumes with every deployment checked exactly once. - route.test.ts updated for the new checkpoint calls. Co-authored-by: ayomide
|
@ayomidearegbeshola29-dev 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! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #1151 and #1152
#1151 — Duplicate metered usage on retry
MeteringService.recordUsagenow accepts an optional logicalidempotencyKey.with-usage-tracking.ts), so genuinely distinct calls still accumulate.MeteringPaymentIntegration.reportUsagethreads the key through.#1152 — Health-check cron time budget
HealthMonitorServicegainscheckAllDeploymentsPaged({ cursor, limit })returning{ results, nextCursor, totalProcessed }(ordered byid).health-checkroute now pages through deployments, resuming via cursor and stopping onceHEALTH_CHECK_BUDGET_MS(default 60_000ms) is exceeded, so a single sweep can no longer run unbounded / time out.checkAllDeployments()is kept (deprecated) for backward compatibility.Test plan
metered-billing.integration.test.tsasserting exactly one usage row is inserted for a retried checkout across a second boundary and that quantity is not incremented.route.test.tsto mock the new paged method.node_modules, so CI must runvitestfor the backend suite.closes #1152