Skip to content
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

Do not delete canceled tasks #2103

Merged
merged 2 commits into from
Oct 9, 2024
Merged

Do not delete canceled tasks #2103

merged 2 commits into from
Oct 9, 2024

Conversation

jasquat
Copy link
Contributor

@jasquat jasquat commented Oct 9, 2024

Do not delete the tasks that spiff says have been canceled. These tasks have not actually been deleted by spiff and so the database should also not delete them. This has been at least one cause for the PendingRollbackError.

This is probably the correct fix for #1861.

Summary by CodeRabbit

  • New Features

    • Introduced a new BPMN process titled "subprocess_with_manual_task," enhancing user interaction and process management.
    • Added functionality to terminate process instances that include subprocesses.
  • Bug Fixes

    • Simplified task termination logic for improved process flow and reliability.
  • Tests

    • Implemented a new test to verify the termination of process instances with subprocesses.

Copy link
Contributor

coderabbitai bot commented Oct 9, 2024

📝 Walkthrough

Walkthrough

The pull request introduces several changes to the ProcessInstanceProcessor class, simplifying the task termination logic by removing unnecessary variables and updating method calls. A new BPMN file defining a process with a manual task is added, enhancing the workflow capabilities. Additionally, a test method is introduced to validate the termination of a process instance that includes a subprocess, ensuring the new functionality is covered by automated tests.

Changes

File Change Summary
spiffworkflow-backend/src/spiffworkflow_backend/services/.../process_instance_processor.py Modified remove_spiff_tasks_for_termination and terminate methods to simplify task termination logic.
spiffworkflow-backend/tests/data/subprocess_with_manual_task/.../subprocess_with_manual_task.bpmn Introduced a new BPMN process with a manual task, start event, subprocess, and end event.
spiffworkflow-backend/tests/spiffworkflow_backend/unit/.../test_process_instance_processor.py Added test_can_terminate_instance_with_subprocess to validate the termination of a process instance with a subprocess.

Possibly related PRs

  • pi-migration-delete-tasks #1929: The changes in this PR involve modifications to the process_instance_service.py file, which may relate to task management and deletion during process instance migration, similar to the task termination logic updated in the main PR.

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (4)
spiffworkflow-backend/tests/data/subprocess_with_manual_task/subprocess_with_manual_task.bpmn (2)

12-36: LGTM: Subprocess is well-defined with clear instructions.

The subprocess "Activity_subprocess_task_in_level_1" is correctly defined with proper internal structure (start event, manual task, end event). The instructions for the end user are comprehensive and provide good guidance on how to proceed and suggestions for further modifications.

Consider adding a brief explanation of what a subprocess is and how it relates to the main process in the instructions. This could help users better understand the structure of the workflow.


32-35: LGTM: Manual task is correctly defined and connected.

The manual task "manual_task_in_level_2" is properly defined within the subprocess and correctly connected to the start and end events using sequence flows.

Consider adding more specific instructions or data inputs/outputs for the manual task to provide clearer guidance on what needs to be done during this step of the process.

spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py (1)

1139-1163: LGTM! Consider adding assertions for termination state.

The new test method test_can_terminate_instance_with_subprocess is a valuable addition to ensure that process instances with subprocesses can be terminated correctly. The test setup, process model loading, and execution steps are well-structured.

To further enhance the test, consider adding assertions after the termination to verify the final state of the process instance and its subprocesses. For example:

processor.terminate()

assert process_instance.status == ProcessInstanceStatus.terminated.value
assert len(process_instance.active_human_tasks) == 0
# Add more assertions as needed to verify the termination state

This will provide stronger guarantees that the termination behaves as expected.

spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py (1)

Line range hint 1947-1962: Good addition of task removal, consider adding a comment for KeyError suppression.

The changes to the terminate method improve the process by calling self.remove_spiff_tasks_for_termination() before setting the status to "terminated". This ensures that tasks are properly cleaned up during termination.

Consider adding a brief comment explaining why KeyError is being suppressed in the with suppress(KeyError): block. This would help future developers understand the rationale behind this decision.

Example:

# Suppress KeyError that might occur during task removal to ensure termination completes
with suppress(KeyError):
    self.remove_spiff_tasks_for_termination()
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between f88ec49 and b1c0e20.

📒 Files selected for processing (3)
  • spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py (2 hunks)
  • spiffworkflow-backend/tests/data/subprocess_with_manual_task/subprocess_with_manual_task.bpmn (1 hunks)
  • spiffworkflow-backend/tests/spiffworkflow_backend/unit/test_process_instance_processor.py (1 hunks)
🧰 Additional context used
🔇 Additional comments (6)
spiffworkflow-backend/tests/data/subprocess_with_manual_task/subprocess_with_manual_task.bpmn (4)

1-3: LGTM: BPMN definitions and process declaration are correct.

The XML declaration, namespaces, and process definition are properly set up. The process is correctly marked as executable, which is essential for running the workflow.


4-11: LGTM: Start and end events are properly defined and connected.

The start and end events of the main process are correctly defined and properly connected to the subprocess using sequence flows. This ensures a clear flow of execution in the process.


38-80: LGTM: BPMN diagram definitions are complete and accurate.

The BPMN diagram definitions for both the main process and the subprocess are correctly specified. They include proper shapes and edges with coordinates and dimensions, ensuring an accurate visual representation of the process structure.


1-81: Overall, the BPMN file is well-structured and correctly implements the required process.

This new BPMN file successfully defines a process with a subprocess containing a manual task, which aligns with the PR objective of "Do not delete canceled tasks". The implementation is correct and provides a good foundation for testing the behavior of subprocesses and manual tasks.

Key strengths:

  1. Proper XML structure and namespace declarations
  2. Clear process flow with correct event connections
  3. Well-defined subprocess with comprehensive instructions
  4. Correctly implemented manual task
  5. Accurate BPMN diagram definitions for visual representation

The file serves its purpose as a test data file and will be valuable for validating the handling of subprocesses and manual tasks in the SpiffWorkflow backend.

spiffworkflow-backend/src/spiffworkflow_backend/services/process_instance_processor.py (2)

Line range hint 1937-1947: Simplified task removal logic looks good, but verify no information loss.

The changes to the remove_spiff_tasks_for_termination method simplify the logic by directly calling cancel() on self.bpmn_process_instance and passing an empty list to update_all_tasks_from_spiff_tasks instead of tracking deleted tasks. This approach could improve performance and reduce complexity.

Please verify that no critical information is lost by not explicitly tracking deleted tasks. Run the following script to check if there are any references to deleted_tasks in other parts of the codebase that might be affected by this change:


Line range hint 1937-1962: Overall improvements to termination process, ensure thorough testing.

The changes to both remove_spiff_tasks_for_termination and terminate methods appear to streamline and improve the process of terminating workflow instances. The simplification of task removal logic and the addition of explicit task removal during termination are positive changes.

To ensure these changes don't introduce any unintended side effects, please conduct thorough testing of the termination process, including:

  1. Terminating processes at various stages of completion
  2. Verifying that all associated tasks are properly removed or updated
  3. Checking database consistency after termination
  4. Testing error handling during termination

Consider adding or updating unit tests to cover these scenarios:

@burnettk burnettk merged commit b1359e3 into main Oct 9, 2024
21 checks passed
@burnettk burnettk deleted the do-not-delete-canceled-tasks branch October 9, 2024 15:58
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