Skip to content

feat: improve transaction safety in CompleteJob function #17970

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 21, 2025

Conversation

ibetitsmike
Copy link
Contributor

This PR refactors the CompleteJob function to use database transactions more consistently for better atomicity guarantees. The large function was broken down into three specialized handlers:

  • completeTemplateImportJob
  • completeWorkspaceBuildJob
  • completeTemplateDryRunJob

Each handler now uses the Database.InTx wrapper to ensure all database operations for a job completion are performed within a single transaction, preventing partial updates in case of failures.

Added comprehensive tests for transaction behavior for each job type.

Fixes #17694

🤖 Generated with Claude Code

This commit refactors the CompleteJob function in provisionerdserver.go to
use database transactions more consistently for better atomicity guarantees.
The large function was broken down into three specialized handlers:

- completeTemplateImportJob
- completeWorkspaceBuildJob
- completeTemplateDryRunJob

Each handler now uses the Database.InTx wrapper to ensure all database
operations for a job completion are performed within a single transaction,
preventing partial updates in case of failures.

Added comprehensive tests for transaction behavior for each job type.

Fixes #17694

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Member

@Emyrk Emyrk left a comment

Choose a reason for hiding this comment

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

Since this is just a refactor, I found these diffs easier to grok.
The only diff is in workspace build, the insertion of timings was moved

Template import: https://www.diffchecker.com/ugtjYQgz/
Workspace build: https://www.diffchecker.com/KuvTwAPu/
DryRun: https://www.diffchecker.com/MxShZo2U/

@ibetitsmike ibetitsmike merged commit b7462fb into main May 21, 2025
36 checks passed
@ibetitsmike ibetitsmike deleted the mike/claude-attempts-17694 branch May 21, 2025 14:48
@github-actions github-actions bot locked and limited conversation to collaborators May 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Provisioner CompleteJob should do all db operations in a transaction
2 participants