Fix race conditions and implement queue metrics aggregation #2
+611
−97
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
This PR eliminates race conditions in Redis operations and implements queue-level metrics aggregation for real-time autoscaling decisions.
Changes
Queue Metrics Aggregation (Feature)
CalculateQueueMetricsAction- Aggregates job-level metrics into queue-level metricsqueue-metrics:calculate- Artisan command for manual/scheduled executionthroughput_per_minute- Jobs completed in last 60 secondsavg_duration_ms- Weighted average duration across all job classesfailure_rate- Percentage of failed jobs (0-100)Race Condition Fixes (Critical)
recordStart()Defensive Programming
Test Updates
RecordJobStartActionTestto reflect atomic queue discoveryTest Plan
✅ Completed Tests
RecordJobStartActionTest- All 5 tests passingCalculateQueueMetricsTest- All 6 scenarios covered (requires Redis)Test Suites Covered
tests/Unit/Actions/RecordJobStartActionTest.phptests/Feature/CalculateQueueMetricsTest.phptests/Unit/Actions/RecordJobCompletionActionTest.phptests/Unit/Actions/RecordJobFailureActionTest.phpIntegration Testing (Requires Redis)
To run Redis-dependent tests:
Breaking Changes
Failure Rate Format: The
failure_ratemetric now returns a percentage (0-100) instead of a ratio (0-1). Applications expecting the ratio format should divide by 100.Performance Impact
Migration Notes