Skip to content

Refactor TowerClient onFlowComplete method for improved ordering#6387

Merged
pditommaso merged 2 commits intomasterfrom
refactor-tower-client-flow-complete
Sep 8, 2025
Merged

Refactor TowerClient onFlowComplete method for improved ordering#6387
pditommaso merged 2 commits intomasterfrom
refactor-tower-client-flow-complete

Conversation

@pditommaso
Copy link
Member

Summary

  • Remove unused terminated field that was set but never used
  • Reorganize onFlowComplete method to ensure sender operations complete before workflow completion notification
  • Move reports publishing and completion after workflow completion notification for better sequencing

Test plan

  • Verify existing TowerClient tests pass
  • Confirm workflow completion flow works correctly with Tower integration
  • Check that reports are properly published after completion

🤖 Generated with Claude Code

- Remove unused 'terminated' field that was set but never used
- Reorganize onFlowComplete method to ensure sender operations complete before workflow completion notification
- Move reports publishing and completion after workflow completion notification for better sequencing

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

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
@netlify
Copy link

netlify bot commented Sep 6, 2025

Deploy Preview for nextflow-docs-staging canceled.

Name Link
🔨 Latest commit 924e41d
🔍 Latest deploy log https://app.netlify.com/projects/nextflow-docs-staging/deploys/68bf03d97551180008d68318

@bentsherman
Copy link
Member

@claude please review

@claude
Copy link

claude bot commented Sep 8, 2025

Claude finished @bentsherman's task —— View job


PR Review: Refactor TowerClient onFlowComplete method

  • Read the modified TowerClient.groovy file
  • Read the modified TowerClientTest.groovy file
  • Analyze the git diff to understand exact changes
  • Review the refactoring logic and ordering improvements
  • Check for potential issues or side effects
  • Provide comprehensive review feedback

Review Summary

Approved - This is a well-executed refactoring that improves the workflow completion ordering as described.

Analysis

Changes Made

  1. Removed unused terminated field (line 125) - was set but never read
  2. Reorganized onFlowComplete() method (lines 397-414) to improve operation ordering:
    • Moved sender operations into a conditional block for better structure
    • Ensured sender completion happens before workflow completion notification
    • Moved reports publishing after workflow completion notification
  3. Updated test - removed reference to the terminated field in test setup

Positive Aspects

  1. Clean code improvement: Removing the unused terminated field reduces code complexity and potential confusion.

  2. Improved ordering logic: The new sequence makes more sense:

    // 1. Complete sender operations first (if sender exists)
    if( sender ) {
        events << new ProcessEvent(completed: true)
        sender.join()  // Wait for all pending events to be sent
    }
    
    // 2. Then notify workflow completion
    if( workflowId ) {
        // Send completion notification to Tower
    }
    
    // 3. Finally handle reports
    reports.publishRuntimeReports()
    reports.flowComplete()
  3. Better resource management: Ensuring the sender thread completes before proceeding prevents potential race conditions.

  4. Consistent with Tower integration patterns: The ordering now follows a logical progression from internal operations to external notifications to cleanup.

Potential Considerations

  1. Thread safety: The refactoring maintains the same thread safety characteristics as before since the operations remain sequential within onFlowComplete().

  2. Error handling: The existing error handling patterns are preserved - if any step fails, subsequent steps won't execute, which is appropriate for cleanup operations.

  3. Reports timing: Moving reports publishing after completion notification could potentially delay reports if the Tower API call takes time, but this is likely the intended behavior to ensure completion is recorded first.

Recommendation

✅ APPROVE - This refactoring improves code clarity and ensures proper operation ordering without introducing any breaking changes or new risks.

The changes are:

  • ✅ Backwards compatible
  • ✅ Improve code maintainability
  • ✅ Follow logical operation sequencing
  • ✅ Remove unused code
  • ✅ Have appropriate test coverage updates

Signed-off-by: Paolo Di Tommaso <paolo.ditommaso@gmail.com>
@pditommaso pditommaso merged commit d743667 into master Sep 8, 2025
25 checks passed
@pditommaso pditommaso deleted the refactor-tower-client-flow-complete branch September 8, 2025 18:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants