Skip to content

feat(spider-py): Add storage functions to get job status and results. - #194

Closed
sitaowang1998 wants to merge 232 commits into
y-scope:mainfrom
sitaowang1998:py-job-status
Closed

feat(spider-py): Add storage functions to get job status and results.#194
sitaowang1998 wants to merge 232 commits into
y-scope:mainfrom
sitaowang1998:py-job-status

Conversation

@sitaowang1998

@sitaowang1998 sitaowang1998 commented Aug 14, 2025

Copy link
Copy Markdown
Collaborator

Description

This PR:

  • Adds storage functions to get job status and results.
  • Adds unit test for getting job status.

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

  • Adds unit tests for getting job status.
  • Unit tests pass in Ubuntu 24.04.
  • GitHub workflows pass.

Summary by CodeRabbit

  • New Features

    • Introduces a Python package for building and composing task graphs (group/chain), submitting jobs via a driver, type utilities, JDBC URL parsing, and a MariaDB-backed storage. Adds an initial task executor CLI and exposes typed numerics (Int8/16/32/64, Float, Double).
  • Documentation

    • Adds uv (0.7.0+) to requirements and reorganizes testing docs with language-scoped tasks.
  • Tests

    • Adds unit and integration tests for types, task graphs, storage, and driver workflows.
  • Chores

    • Adds Python build/lint/test tasks, updates CI to log uv and refine test selection, pins Python 3.13, and introduces project tooling config.

sitaowang1998 and others added 30 commits July 15, 2025 13:40
Co-authored-by: Lin Zhihao <59785146+LinZhihao-723@users.noreply.github.com>
…ider into dep-concurrency"

This reverts commit 1769c95, reversing
changes made to 90aa5a2.
@sitaowang1998
sitaowang1998 requested a review from a team as a code owner August 14, 2025 16:17
@sitaowang1998
sitaowang1998 requested a review from Copilot August 14, 2025 16:17
@coderabbitai

coderabbitai Bot commented Aug 14, 2025

Copy link
Copy Markdown
Contributor

Caution

Review failed

The pull request is closed.

Walkthrough

Adds a Python client/core/type/storage implementation and tests; introduces uv-based build/lint/test tasks and Python project config; updates CI to log uv and adjusts unit test task; documents new test task names and uv requirement.

Changes

Cohort / File(s) Summary
CI workflows
.github/workflows/code-linting-checks.yaml, .github/workflows/unit-tests.yaml
Log uv version in tool versions; unit tests job switches to task test:python-non-storage-tests.
Docs
docs/src/dev-docs/testing.md, README.md
Testing docs now use cpp-* and python-* tasks; add uv (>=0.7.0) to requirements with link.
Taskfile/Build/Lint/Test configs
taskfile.yaml, build-tasks.yaml, lint-tasks.yaml, test-tasks.yaml
Add G_SRC_PYTHON_DIR/G_BUILD_PYTHON_DIR vars; new py-build task using uv build; python lint uses uv run over source dir; rename C++ tasks to cpp-, add python- test tasks (all/non-storage/storage).
Python project setup
python/.python-version, python/pyproject.toml
Set Python 3.13; add pyproject with metadata, deps (runtime/dev), console script, mypy/pytest/ruff config, hatchling backend.
Spider package root
python/src/spider/__init__.py
Re-exports client and type symbols via all.
Client API
python/src/spider/client/__init__.py, python/src/spider/client/data.py, .../driver.py, .../job.py, .../task.py, .../taskgraph.py
Introduces Data wrapper; Driver with submit_jobs; Job wrapper; TaskContext/type utilities and function-to-core Task translation; TaskGraph with chain/group helpers and bridging to core.
Core API
python/src/spider/core/__init__.py, .../data.py, .../driver.py, .../job.py, .../task.py, .../taskgraph.py
Adds core data types, IDs, enums; task I/O/state and graph composition/merge/chain with ID remap; exports aggregated in init.
Storage
python/src/spider/storage/__init__.py, .../jdbc_url.py, .../mariadb_storage.py, .../storage.py
Define Storage interface and error; JDBC URL parsing; MariaDBStorage with submit/status/results and transactions; export surface.
Type system
python/src/spider/type/__init__.py, .../tdl_convert.py, .../tdl_parse.py, .../tdl_type.py, .../type.py, .../utils.py
Implement TDL types, parsing, Python<->TDL conversions, bounded ints/floats, and class name resolution; expose via init.
Task executor stub
python/src/spider/task_executor/__init__.py, .../task_executor.py
Adds package and main() entry point stub; wired as console script.
Tests
python/tests/client/*, python/tests/storage/*, python/tests/type/*
Add unit/integration tests for client TaskGraph/Driver, JDBC URL and MariaDB storage, and type conversions.

Sequence Diagram(s)

sequenceDiagram
  actor User
  participant Client as spider.client.Driver
  participant Storage as spider.storage.MariaDBStorage
  participant DB as MariaDB

  User->>Client: submit_jobs(graphs, args)
  Client->>Client: Validate counts and arg types
  Client->>Client: Build core.TaskGraph inputs
  Client->>Storage: submit_jobs(driver_id, task_graphs)
  Storage->>DB: Insert jobs/tasks/dependencies/IO
  DB-->>Storage: Job IDs
  Storage-->>Client: core.Job[]
  Client-->>User: Job[]
Loading
sequenceDiagram
  participant TG1 as core.TaskGraph (parent)
  participant TG2 as core.TaskGraph (child)
  participant NewTG as core.TaskGraph (chained)

  TG1->>TG1: reset_ids()
  TG2->>TG2: reset_ids()
  TG1->>TG2: Validate outputs vs inputs (count/type)
  TG1->>NewTG: Connect outputs→inputs, merge deps/IO
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • LinZhihao-723
  • davidlion

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.


📜 Recent review details

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

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 4a061e0 and 2410829.

⛔ Files ignored due to path filters (1)
  • python/uv.lock is excluded by !**/*.lock
📒 Files selected for processing (41)
  • .github/workflows/code-linting-checks.yaml (1 hunks)
  • .github/workflows/unit-tests.yaml (2 hunks)
  • README.md (2 hunks)
  • build-tasks.yaml (1 hunks)
  • docs/src/dev-docs/testing.md (2 hunks)
  • lint-tasks.yaml (1 hunks)
  • python/.python-version (1 hunks)
  • python/pyproject.toml (1 hunks)
  • python/src/spider/__init__.py (1 hunks)
  • python/src/spider/client/__init__.py (1 hunks)
  • python/src/spider/client/data.py (1 hunks)
  • python/src/spider/client/driver.py (1 hunks)
  • python/src/spider/client/job.py (1 hunks)
  • python/src/spider/client/task.py (1 hunks)
  • python/src/spider/client/taskgraph.py (1 hunks)
  • python/src/spider/core/__init__.py (1 hunks)
  • python/src/spider/core/data.py (1 hunks)
  • python/src/spider/core/driver.py (1 hunks)
  • python/src/spider/core/job.py (1 hunks)
  • python/src/spider/core/task.py (1 hunks)
  • python/src/spider/core/taskgraph.py (1 hunks)
  • python/src/spider/storage/__init__.py (1 hunks)
  • python/src/spider/storage/jdbc_url.py (1 hunks)
  • python/src/spider/storage/mariadb_storage.py (1 hunks)
  • python/src/spider/storage/storage.py (1 hunks)
  • python/src/spider/task_executor/__init__.py (1 hunks)
  • python/src/spider/task_executor/task_executor.py (1 hunks)
  • python/src/spider/type/__init__.py (1 hunks)
  • python/src/spider/type/tdl_convert.py (1 hunks)
  • python/src/spider/type/tdl_parse.py (1 hunks)
  • python/src/spider/type/tdl_type.py (1 hunks)
  • python/src/spider/type/type.py (1 hunks)
  • python/src/spider/type/utils.py (1 hunks)
  • python/tests/client/test_driver.py (1 hunks)
  • python/tests/client/test_task_graph.py (1 hunks)
  • python/tests/storage/test_jdbc_url.py (1 hunks)
  • python/tests/storage/test_mariadb.py (1 hunks)
  • python/tests/type/test_to_native.py (1 hunks)
  • python/tests/type/test_to_tdl.py (1 hunks)
  • taskfile.yaml (1 hunks)
  • test-tasks.yaml (3 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds Python storage functions for getting job status and results, along with comprehensive unit tests and build configurations. The changes establish the Python client interface for the Spider distributed task execution framework.

  • Introduces storage functions for retrieving job status and results in the Python client
  • Adds comprehensive unit tests for task graphs, data types, storage backends, and client functionality
  • Sets up Python project configuration with pytest, mypy, and ruff for testing and linting

Reviewed Changes

Copilot reviewed 41 out of 43 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
python/src/spider/storage/storage.py Defines abstract storage interface with methods for job submission, status retrieval, and result fetching
python/src/spider/storage/mariadb_storage.py Implements MariaDB storage backend with concrete implementations of storage interface methods
python/tests/storage/test_mariadb.py Adds unit tests for MariaDB storage functionality including job submission and status checking
python/src/spider/client/ Contains client-side classes for Driver, TaskGraph, Job, and task management
python/src/spider/type/ Implements TDL type system with conversion utilities between Python and TDL types
taskfile.yaml, test-tasks.yaml Updates build configuration to support Python testing and separate C++ vs Python test tasks

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

type=output_type,
value=core.TaskOutputValue(msgpack.unpackb(data_id)),
)
)

Copilot AI Aug 14, 2025

Copy link

Choose a reason for hiding this comment

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

Using executemany followed by iterating over cursor is incorrect. executemany doesn't return results for iteration. Use execute in a loop or executemany without expecting results.

Suggested change
)
results = []
for task_id in task_ids:
cursor.execute(GetTaskOutputs, (task_id,))
for output_type, value, data_id in cursor.fetchall():
if value is not None:
results.append(
core.TaskOutput(
type=output_type,
value=core.TaskOutputValue(msgpack.unpackb(value)),
)
)
if data_id is not None:
results.append(
core.TaskOutput(
type=output_type,
value=core.TaskOutputValue(msgpack.unpackb(data_id)),
)
)

Copilot uses AI. Check for mistakes.
value=core.TaskOutputValue(msgpack.unpackb(value)),
)
)
if data_id is not None:

Copilot AI Aug 14, 2025

Copy link

Choose a reason for hiding this comment

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

Both value and data_id conditions can be true simultaneously, leading to duplicate results being added. Use elif instead of separate if statements.

Suggested change
if data_id is not None:
elif data_id is not None:

Copilot uses AI. Check for mistakes.

def __init__(self, value: bytes) -> None:
"""Initialize the Data object with the given value."""
self.data_id = core.DataId()

Copilot AI Aug 14, 2025

Copy link

Choose a reason for hiding this comment

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

DataId is an alias for UUID, but calling UUID() without arguments creates a new UUID each time. This should likely be uuid4() to generate a proper UUID.

Suggested change
self.data_id = core.DataId()
from uuid import uuid4
class Data:
"""Represents a spider client data."""
def __init__(self, value: bytes) -> None:
"""Initialize the Data object with the given value."""
self.data_id = core.DataId(uuid4())

Copilot uses AI. Check for mistakes.


@pytest.fixture(scope="session")
def mariadb_storage() -> MariaDBStorage:

Copilot AI Aug 14, 2025

Copy link

Choose a reason for hiding this comment

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

The hardcoded database credentials (user=spider&password=password) in MariaDBTestUrl pose a security risk. Consider using environment variables or a secure configuration method for test credentials.

Copilot uses AI. Check for mistakes.
raise StorageError(str(e)) from e
except msgpack.exceptions.UnpackValueError:
self._conn.rollback()
raise

Copilot AI Aug 14, 2025

Copy link

Choose a reason for hiding this comment

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

The exception is caught but re-raised without providing context about which job or task failed during unpacking, making debugging difficult.

Suggested change
raise
except msgpack.exceptions.UnpackValueError as e:
self._conn.rollback()
raise StorageError(
f"Failed to unpack task output for job {job.job_id}: {str(e)}"
) from e

Copilot uses AI. Check for mistakes.
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