[APP-974] scheduled sp locks - #999
Open
ericbuckley wants to merge 8 commits into
Open
Conversation
Update scheduled cleanup procedures (event metric and lab 100) to capture and evaluate their return execution status codes. Previously, procedures were executed without inspecting return values. Now, status codes are mapped via ScheduledExecutionStatus to log skips when already running, throw on failures, and support legacy completion codes.
Prevent concurrent execution of the event metric cleanup stored procedure by acquiring an exclusive application lock using `sys.sp_getapplock`. Update return code on completion to 1 and adjust unit test expectations accordingly.
Prevent concurrent execution of the lab 100 cleanup stored procedure by acquiring an exclusive application lock using sys.sp_getapplock. Update return code on completion to 1 and update repository tests.
Ensure application locks are released in the CATCH block of event metric and lab 100 cleanup stored procedures if an error occurs after the lock has been acquired. Add integration tests verifying lock release on failure.
Update cleanup tests for EventMetricCleanup and Lab100Cleanup to assert exact log messages, verify repository interactions, and check for DataProcessingException on failure. Also fix test naming typo.
Add concurrency tests for scheduled cleanup application locks. Verify that event metric and lab 100 cleanup procedures skip execution when their respective application locks are held without writing normal job flow logs, and ensure locks do not block each other.
Add documentation for scheduled cleanup coordination using SQL Server application locks. Explain that event-metric and LAB100 cleanup procedures use separate locks with zero timeout to prevent duplicate execution across service pods without blocking the scheduler.
Remove legacy handling for return code 0 in scheduled execution status, treating it as an unexpected return code.
ericbuckley
marked this pull request as ready for review
August 12, 2026 21:19
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.
Description
This PR coordinates scheduled event-metric and LAB100 cleanup across service pods with independent SQL Server session application locks, returning clear completed, skipped, or failed statuses. Cleanup locks use exclusive zero-timeout acquisition, release on success and failure, and allow the two different cleanup jobs to run concurrently.
Related Issues
Additional Notes
sys.sp_getapplock(@LockTimeout = 0) andsys.sp_releaseapplocktosp_event_metric_cleanup_postprocessingandsp_lab100_cleanup.ScheduledExecutionStatusenum to handle return codes (1/0completion,-2skipped,-1failure).ScheduledCleanupAppLockConcurrencyTest,ScheduledCleanupAppLockReleaseTest, etc.).README.mdwith documentation on scheduled cleanup coordination behavior and lock resource identifiers.Checklist