Refactor GoogleBatchTaskHandler.newSubmitRequest for reduced complexity#6687
Merged
pditommaso merged 2 commits intomasterfrom Jan 3, 2026
Merged
Refactor GoogleBatchTaskHandler.newSubmitRequest for reduced complexity#6687pditommaso merged 2 commits intomasterfrom
pditommaso merged 2 commits intomasterfrom
Conversation
Break down the monolithic newSubmitRequest method (~250 lines) into smaller, focused helper methods to improve maintainability and testability. Changes: - Extract buildComputeResource() for CPU, memory, boot disk config - Extract buildSpotRetryPolicy() for spot instance retry lifecycle policy - Extract buildNetworkPolicy() for network/subnet configuration - Extract buildTaskGroup() for task group with array support - Extract buildContainerRunnable() for container and environment setup - Extract buildInstancePolicyOrTemplate() for instance policy/template - Extract buildAllocationPolicy() for full allocation policy assembly - Extract buildScratchVolume() for scratch disk volume creation - Add AllocationPolicyResult and InstancePolicyResult static classes to return multiple values without side effects - Add unit tests for new helper methods using Spock where blocks Benefits: - Reduces cyclomatic complexity of newSubmitRequest from ~40 to ~10 - Each helper method is independently unit-testable - Clear separation of concerns (compute, container, allocation, network) - Explicit data flow via result classes instead of hidden side effects - Easier to understand, maintain, and extend Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
✅ Deploy Preview for nextflow-docs-staging canceled.
|
pditommaso
added a commit
that referenced
this pull request
Jan 16, 2026
…ty (#6687) Break down the monolithic newSubmitRequest method (~250 lines) into smaller, focused helper methods to improve maintainability and testability. Changes: - Extract buildComputeResource() for CPU, memory, boot disk config - Extract buildSpotRetryPolicy() for spot instance retry lifecycle policy - Extract buildNetworkPolicy() for network/subnet configuration - Extract buildTaskGroup() for task group with array support - Extract buildContainerRunnable() for container and environment setup - Extract buildInstancePolicyOrTemplate() for instance policy/template - Extract buildAllocationPolicy() for full allocation policy assembly - Extract buildScratchVolume() for scratch disk volume creation - Add AllocationPolicyResult and InstancePolicyResult static classes to return multiple values without side effects - Add unit tests for new helper methods using Spock where blocks Benefits: - Reduces cyclomatic complexity of newSubmitRequest from ~40 to ~10 - Each helper method is independently unit-testable - Clear separation of concerns (compute, container, allocation, network) - Explicit data flow via result classes instead of hidden side effects - Easier to understand, maintain, and extend Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com> Co-authored-by: Jorge Ejarque <jorgee@users.noreply.github.com>
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
Refactors the
newSubmitRequestmethod inGoogleBatchTaskHandlerfrom a monolithic ~250-line method into smaller, focused helper methods.Before
taskSpecin nested calls)After
buildComputeResource()buildSpotRetryPolicy()buildNetworkPolicy()buildTaskGroup()buildContainerRunnable()buildInstancePolicyOrTemplate()buildAllocationPolicy()buildScratchVolume()Key Design Decisions
Static result classes (
AllocationPolicyResult,InstancePolicyResult) instead of output parameters or tuples - provides named properties and clear data flowExplicit volume handling - scratch volume requirement is returned via result class rather than modifying
taskSpecas a side effectProtected visibility - all helpers are
protectedto allow subclassing/extensionBenefits
Test Plan
GoogleBatchTaskHandlerTesttests passwhereblocks:buildComputeResource- 5 test cases for CPU/memory/disk combinationsbuildSpotRetryPolicy- verifies retry action and exit codesbuildNetworkPolicy- 5 test cases for network/subnet/private combinationsbuildTaskGroup- verifies task spec inclusionbuildScratchVolume- verifies device name and mount pathbuildContainerRunnable- verifies container options, mounts, environmentbuildContainerRunnablewith fusion - verifies--privilegedflag