Skip to content

fix: Move create_task_instance from scheduler to worker - #76

Merged
sitaowang1998 merged 2 commits into
y-scope:mainfrom
sitaowang1998:create_task_instance
Mar 11, 2025
Merged

fix: Move create_task_instance from scheduler to worker#76
sitaowang1998 merged 2 commits into
y-scope:mainfrom
sitaowang1998:create_task_instance

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Mar 10, 2025

Copy link
Copy Markdown
Collaborator

Description

Scheduler runs create_task_instance, a storage call, for each schedule task, increasing response delay. This pr moves the call from scheduler to worker.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • GitHub workflows pass
  • Unit tests pass in dev container
  • Integration tests pass in dev container

Summary by CodeRabbit

  • Refactor

    • Streamlined task scheduling by moving from dual identifiers to a single task identifier.
    • Enhanced error handling to provide a more reliable and straightforward task management process.
  • Tests

    • Expanded test scenarios to validate scheduling under varied conditions, including multiple task scheduling and handling cases with no available tasks.

@sitaowang1998
sitaowang1998 requested a review from a team as a code owner March 10, 2025 22:45
@coderabbitai

coderabbitai Bot commented Mar 10, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

This pull request consolidates task identifier management by transitioning from a tuple-based approach to a single task identifier throughout the code. The ScheduleTaskResponse class is updated with a new constructor and accessor methods that handle a single task_id. In addition, the scheduler server logic now omits the creation of a separate task instance, while the worker client’s task retrieval method is modified to include additional error handling and a new return type. Corresponding test cases have been adjusted to validate the updated interface.

Changes

File(s) Change Summary
src/spider/scheduler/…/SchedulerMessage.hpp Updated ScheduleTaskResponse: replaced tuple (m_task_ids) with a single m_task_id, modified constructor, accessor (get_task_ids()get_task_id()), and serialization macro accordingly.
src/spider/scheduler/…/SchedulerServer.cpp Removed code for creating a task instance; response now directly constructed using a single task_id without specific error handling for task instance creation.
src/spider/worker/…/WorkerClient.cpp Modified get_next_task: now retrieves a single task_id, establishes a MySQL connection, handles connection and instance creation errors, and returns a tuple of task and instance IDs.
tests/scheduler/…/test-SchedulerPolicy.cpp
tests/scheduler/…/test-SchedulerServer.cpp
Updated test cases: added tests for scheduling a later task and handling no tasks; replaced tuple-based assertions with direct calls to get_task_id() in response validation.

Sequence Diagram(s)

sequenceDiagram
    participant WC as WorkerClient
    participant SS as SchedulerServer
    participant DB as MySQL/MetadataStore

    WC->>SS: Request next task
    SS-->>WC: Return single task_id
    WC->>DB: Establish MySQL connection
    alt Connection successful
        WC->>DB: Create TaskInstance using task_id
        DB-->>WC: TaskInstance created (or failure)
    else Connection fails
        WC->>WC: Log error and return nullopt
    end
Loading

Possibly related PRs

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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 generate docstrings to generate docstrings for this 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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/spider/worker/WorkerClient.cpp (1)

116-132: Augment error logging for better maintainability.

The new logic properly creates the task instance in the worker after retrieving the task_id from the scheduler, consistent with the PR objective. However, if create_task_instance fails, consider logging the specific task_id and error details to aid in debugging:

 if (!err.success()) {
+    spdlog::error("Cannot create task instance for task {}: {}",
+                  boost::uuids::to_string(task_id),
+                  err.description);
     return std::nullopt;
 }
🧰 Tools
🪛 Cppcheck (2.10-2)

[performance] 116-116: Variable 'm_id' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cf758fe and a3140bb.

📒 Files selected for processing (5)
  • src/spider/scheduler/SchedulerMessage.hpp (1 hunks)
  • src/spider/scheduler/SchedulerServer.cpp (1 hunks)
  • src/spider/worker/WorkerClient.cpp (2 hunks)
  • tests/scheduler/test-SchedulerPolicy.cpp (1 hunks)
  • tests/scheduler/test-SchedulerServer.cpp (1 hunks)
🧰 Additional context used
🪛 Cppcheck (2.10-2)
src/spider/worker/WorkerClient.cpp

[performance] 116-116: Variable 'm_id' is assigned in constructor body. Consider performing initialization in initialization list.

(useInitializationList)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: non-storage-unit-tests (ubuntu-24.04)
  • GitHub Check: lint
  • GitHub Check: non-storage-unit-tests (ubuntu-22.04)
🔇 Additional comments (9)
src/spider/scheduler/SchedulerServer.cpp (1)

162-162: Implementation aligns with PR objective.

Setting the response to a single task_id simplifies the scheduling flow and correctly delegates task instance creation to the worker side. Ensure that this change is fully propagated to any remaining references of the old tuple approach.

tests/scheduler/test-SchedulerServer.cpp (1)

111-111: Verified test logic.

This assertion correctly checks the single task_id, guaranteeing that the server’s simplified response is consistent with the new scheduling approach.

tests/scheduler/test-SchedulerPolicy.cpp (3)

69-70: Good modification to allow testing multiple scheduling operations

Removing const qualifier from optional_task_id correctly allows the variable to be reassigned, which is necessary for testing sequential scheduling operations.


77-83: Good test coverage enhancement

Adding the test case for scheduling the later task provides better test coverage by ensuring the policy returns tasks in the correct FIFO order. This properly verifies that the second scheduled task (task_2) is returned after the first one.


88-90: Good test coverage for edge case

Adding the test for "Schedule when no task available" appropriately verifies the behavior when there are no more tasks to be scheduled. It ensures that the policy correctly returns an empty optional, which is important for proper error handling in the worker.

src/spider/scheduler/SchedulerMessage.hpp (4)

57-57: Constructor simplified for single task identifier pattern

The constructor has been properly simplified to only accept a single task_id, aligning with the PR objective to move the task instance creation responsibility from the scheduler to the worker.


59-64: Interface updated to support single task identifier pattern

The methods has_task_id() and get_task_id() have been correctly modified to work with the new single task identifier approach. This maintains the API contract while simplifying the implementation.


66-66: Serialization updated to match the new data structure

The serialization macro has been correctly updated to only include the single task_id field.


69-69: Member variable updated to simplified model

Good change to replace the tuple-based task identifiers with a single task identifier, which aligns perfectly with the PR's goal of moving task instance creation responsibility to the worker.

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.

1 participant