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

Reset some rq meta fields when retrying rq job #8719

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

Marishka17
Copy link
Contributor

@Marishka17 Marishka17 commented Nov 19, 2024

Motivation and context

In the current implementation, if a job is rescheduled for later execution (due to a LockNotAvailableError raised during the export process), the job's metadata is not filtered when creating a new job. This PR introduces RQ job metadata fields that must be reset when rescheduling a job.

How has this been tested?

Checklist

  • I submit my changes into the develop branch
  • I have created a changelog fragment
    - [ ] I have updated the documentation accordingly
  • I have added tests to cover my changes
  • I have linked related issues (see GitHub docs)
    - [ ] I have increased versions of npm packages if it is necessary
    (cvat-canvas,
    cvat-core,
    cvat-data and
    cvat-ui)

License

  • I submit my code changes under the same MIT License that covers the project.
    Feel free to contact the maintainers if that's a concern.

Summary by CodeRabbit

  • New Features
    • Enhanced job retry logic with improved metadata management.
    • Introduced a new mechanism for resetting job metadata during retries.
  • Bug Fixes
    • Improved error handling for export cache operations, specifying file usage errors more clearly.

Copy link
Contributor

coderabbitai bot commented Nov 19, 2024

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The changes involve modifications to job metadata handling during retries and enhancements to error handling within the export cache process. The _retry_current_rq_job function now utilizes a new static method, reset_meta_on_retry, from the newly introduced RQMeta class to manage job metadata more effectively. Additionally, the clear_export_cache function has improved error handling by specifying a FileIsBeingUsedError for better clarity when the export cache file is in use.

Changes

File Path Change Summary
cvat/apps/dataset_manager/views.py Updated _retry_current_rq_job to use RQMeta.reset_meta_on_retry for job metadata handling. Improved clear_export_cache error handling to raise FileIsBeingUsedError.
cvat/apps/engine/rq_job_handler.py Introduced RQMeta class with methods get_resettable_fields and reset_meta_on_retry for managing job metadata during retries. Added typing import for Any.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant JobHandler
    participant RQMeta

    User->>JobHandler: Retry Job
    JobHandler->>RQMeta: reset_meta_on_retry(current_rq_job.meta)
    RQMeta-->>JobHandler: Updated Metadata
    JobHandler->>User: Job Retried with Updated Metadata
Loading

🐰 "In the garden where jobs do play,
Metadata dances, come what may.
With retries fresh and errors clear,
Our caching woes have disappeared!
Hopping high, we cheer with glee,
For better code, oh joy, oh me!" 🐇


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.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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

sonarcloud bot commented Nov 19, 2024

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 (2)
cvat/apps/engine/rq_job_handler.py (1)

26-32: Consider adding documentation and validation

The implementation is good, but could benefit from these enhancements:

  1. Add a docstring to reset_meta_on_retry explaining its purpose and parameters
  2. Consider adding validation for meta_to_update keys to ensure they're valid RQJobMetaField values

Example enhancement:

 @classmethod
 def reset_meta_on_retry(cls, meta_to_update: dict[RQJobMetaField, Any]) -> dict[RQJobMetaField, Any]:
+    """Filter out resettable fields from the job metadata during retry.
+    
+    Args:
+        meta_to_update: Dictionary containing job metadata
+    
+    Returns:
+        Dictionary with resettable fields removed
+    """
+    # Validate that all keys are valid RQJobMetaField values
+    if not all(isinstance(k, str) and hasattr(RQJobMetaField, k) for k in meta_to_update):
+        raise ValueError("Invalid metadata field found")
+
     resettable_fields = cls.get_resettable_fields()
 
     return {
         k: v for k, v in meta_to_update.items() if k not in resettable_fields
     }
cvat/apps/dataset_manager/views.py (1)

Line range hint 82-84: Consider addressing the parallel jobs concern

The TODO comment and the subsequent note raise important concerns:

  1. The plan to move to built-in RQ scheduler should be tracked
  2. The current implementation might lead to parallel jobs with the same name

Consider:

  1. Adding a unique suffix to retried job IDs to prevent parallel execution
  2. Creating a tracking issue for the scheduler migration

Would you like me to help create a GitHub issue to track these improvements?

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 3eec9fe and 9c62908.

📒 Files selected for processing (2)
  • cvat/apps/dataset_manager/views.py (2 hunks)
  • cvat/apps/engine/rq_job_handler.py (1 hunks)
🔇 Additional comments (5)
cvat/apps/engine/rq_job_handler.py (3)

9-9: LGTM: Import changes are appropriate

The addition of Any to the typing imports is necessary and correctly placed with other typing-related imports.


15-24: LGTM: Well-structured metadata field management

The RQMeta class and get_resettable_fields method provide a clean, maintainable way to manage fields that should be reset during job retries. The chosen fields (exception, progress, task progress, and status) are logical choices for reset during retry operations.


15-32: Verify integration with retry mechanism

The implementation looks solid, but let's verify its integration with the retry mechanism.

✅ Verification successful

Integration with retry mechanism is properly implemented

The implementation is correctly integrated with the retry mechanism:

  • The RQMeta class is properly used in _retry_current_rq_job function to reset metadata fields during job retries
  • The retry mechanism is correctly triggered when LockNotAvailableError occurs during export operations
  • Test coverage confirms the behavior:
    • Verifies metadata reset during retries
    • Validates retry behavior when lock acquisition fails
    • Ensures job retry counter is properly set
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check how the new RQMeta class is integrated with retry logic

# Look for retry-related code that should use this new functionality
rg -l "retry.*rq.*job" --type py

# Check for any existing error handling of LockNotAvailableError
rg -l "LockNotAvailableError" --type py

# Look for test coverage
rg -l "test.*retry" --type py

Length of output: 324


Script:

#!/bin/bash
# Let's examine the retry implementation and LockNotAvailableError handling

# Check dataset_manager/views.py for retry implementation
rg -B 5 -A 10 "retry.*rq.*job|LockNotAvailableError" cvat/apps/dataset_manager/views.py

# Check how RQMeta is used in the codebase
rg -B 3 -A 3 "RQMeta" 

# Look at the test implementation
rg -B 5 -A 10 "LockNotAvailableError" cvat/apps/dataset_manager/tests/test_rest_api_formats.py

Length of output: 13131

cvat/apps/dataset_manager/views.py (2)

23-23: LGTM!

The import statement is correctly placed and the RQMeta class is properly utilized in the code.


88-88: Verify the implementation of RQMeta.reset_meta_on_retry

The change correctly introduces meta field reset during job retry. However, we should verify the implementation of the reset_meta_on_retry method to ensure it properly handles all meta fields.

Let's check the implementation:

✅ Verification successful

Based on the results, I can now generate the final response since I have found the implementation of RQMeta.reset_meta_on_retry and its usage context.

Implementation of RQMeta.reset_meta_on_retry is properly handling critical fields

The implementation correctly resets the essential meta fields during job retry through get_resettable_fields():

  • FORMATTED_EXCEPTION: Clears previous error information
  • PROGRESS: Resets overall progress
  • TASK_PROGRESS: Resets task-specific progress
  • STATUS: Resets status messages

These fields are the key ones that need resetting when retrying a job, while preserving other important metadata like user info, task IDs, etc.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the implementation of RQMeta.reset_meta_on_retry

# Find the RQMeta class definition and its reset_meta_on_retry method
rg -A 10 "class RQMeta" cvat/apps/engine/

# Find all usages of meta fields in RQ jobs to ensure we're resetting all necessary fields
rg "\.meta\b" --type py

Length of output: 9524

@codecov-commenter
Copy link

codecov-commenter commented Nov 19, 2024

Codecov Report

Attention: Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 74.23%. Comparing base (ae5d9b2) to head (f6b32db).
Report is 2 commits behind head on develop.

Additional details and impacted files
@@           Coverage Diff            @@
##           develop    #8719   +/-   ##
========================================
  Coverage    74.22%   74.23%           
========================================
  Files          401      401           
  Lines        43513    43522    +9     
  Branches      3953     3953           
========================================
+ Hits         32298    32307    +9     
  Misses       11215    11215           
Components Coverage Δ
cvat-ui 78.60% <ø> (+0.01%) ⬆️
cvat-server 70.49% <70.00%> (-0.01%) ⬇️
---- 🚨 Try these New Features:

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.

3 participants