-
Notifications
You must be signed in to change notification settings - Fork 6
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
feat: Add example showing how to join tasks together. #52
base: main
Are you sure you want to change the base?
Conversation
WalkthroughThis pull request introduces comprehensive documentation and an example implementation for task joining in the Spider framework. The changes include a new markdown document explaining task integration methods, updates to the quick-start guide, and a complete example project demonstrating how to bind and start tasks. The implementation showcases two primary approaches: binding task outputs and initiating tasks within other tasks, with a focus on creating directed acyclic graphs (DAGs) of computational tasks. Changes
Sequence DiagramsequenceDiagram
participant Client
participant Driver
participant TaskGraph
participant Tasks
Client->>Driver: Create driver
Client->>Driver: Bind tasks
Driver->>TaskGraph: Configure task dependencies
Client->>Driver: Start job
Driver->>Tasks: Execute tasks
Tasks-->>Driver: Return results
Driver-->>Client: Job completion
Possibly related PRs
Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (7)
examples/joining-tasks/src/tasks.cpp (1)
7-17
: Mark unused TaskContext parameter.Consider marking the unused TaskContext parameter with [[maybe_unused]] attribute to suppress compiler warnings.
-auto square(spider::TaskContext&, int value) -> int { +auto square(spider::TaskContext& [[maybe_unused]] context, int value) -> int { -auto square_root(spider::TaskContext&, int value) -> double { +auto square_root(spider::TaskContext& [[maybe_unused]] context, int value) -> double { -auto sum(spider::TaskContext&, int x, int y) -> int { +auto sum(spider::TaskContext& [[maybe_unused]] context, int x, int y) -> int {examples/joining-tasks/src/tasks.hpp (1)
6-26
: Enhance function documentation.The documentation comments should include descriptions for all parameters and more detailed return value descriptions.
/** * @param context Task execution context for Spider framework * @param value The input value to square - * @return The square of the given value. + * @return The square of the given value (value * value). */ auto square(spider::TaskContext& context, int value) -> int; /** * @param context Task execution context for Spider framework * @param value The input value to calculate square root of - * @return The square root of the given value. + * @return The square root of the given value. Throws std::invalid_argument if value is negative. */ auto square_root(spider::TaskContext& context, int value) -> double; /** * @param context Task execution context for Spider framework * @param x First number to add * @param y Second number to add - * @return The sum of x and y. + * @return The sum of the two input values (x + y). */examples/joining-tasks/src/client.cpp (3)
19-19
: Improve const correctness of validate_job_output function.The job parameter should be const since the function only reads from it.
-auto validate_job_output(spider::Job<JobOutputType>& job, JobOutputType const& expected) -> bool { +auto validate_job_output(spider::Job<JobOutputType> const& job, JobOutputType const& expected) -> bool {
53-56
: Enhance storage URL validation.The current validation only checks if the URL is empty. Consider adding more thorough URL validation.
if (storage_url.empty()) { std::cerr << "storage-backend-url cannot be empty." << '\n'; return 1; } + if (storage_url.find("://") == std::string::npos) { + std::cerr << "Invalid storage-backend-url format. Expected: <scheme>://<path>" << '\n'; + return 1; + }
65-67
: Consider using named constants for test values.The values 4 and 5 are magic numbers. Consider using named constants to improve code readability.
+ // Using a 3-4-5 right triangle for testing + int const TRIANGLE_SIDE_A = 4; + int const TRIANGLE_SIDE_B = 5; - int const a = 4; - int const b = 5; - auto job = driver.start(hypotenuse_task_graph, a, b); + auto job = driver.start(hypotenuse_task_graph, TRIANGLE_SIDE_A, TRIANGLE_SIDE_B);docs/joining-tasks.md (2)
49-50
: Fix grammar in parameter description.Change "is a either a" to "is either a" to correct the grammar.
-- Each subsequent parameter is a either a *source* runnable, or a value that conforms to the +- Each subsequent parameter is either a *source* runnable, or a value that conforms to the🧰 Tools
🪛 LanguageTool
[misspelling] ~49-~49: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...nables*. - Each subsequent parameter is a either a source runnable, or a value ...(EN_A_VS_AN)
73-76
: Fix blockquote formatting.Remove the empty blockquote lines to comply with markdown formatting standards.
> Unlike `std::bind`, `spider::Driver::bind` doesn't support placeholder inputs. - -> ->🧰 Tools
🪛 Markdownlint (0.37.0)
73-73: null
Blank line inside blockquote(MD028, no-blanks-blockquote)
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (7)
docs/joining-tasks.md
(1 hunks)docs/quick-start.md
(1 hunks)examples/joining-tasks/.clang-format
(1 hunks)examples/joining-tasks/CMakeLists.txt
(1 hunks)examples/joining-tasks/src/client.cpp
(1 hunks)examples/joining-tasks/src/tasks.cpp
(1 hunks)examples/joining-tasks/src/tasks.hpp
(1 hunks)
✅ Files skipped from review due to trivial changes (3)
- examples/joining-tasks/.clang-format
- docs/quick-start.md
- examples/joining-tasks/CMakeLists.txt
🧰 Additional context used
🪛 LanguageTool
docs/joining-tasks.md
[misspelling] ~49-~49: Use “an” instead of ‘a’ if the following word starts with a vowel sound, e.g. ‘an article’, ‘an hour’.
Context: ...nables*. - Each subsequent parameter is a either a source runnable, or a value ...
(EN_A_VS_AN)
🪛 Markdownlint (0.37.0)
docs/joining-tasks.md
73-73: null
Blank line inside blockquote
(MD028, no-blanks-blockquote)
⏰ 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 (1)
examples/joining-tasks/src/tasks.cpp (1)
19-25
: LGTM! Task registration is properly implemented.The NOLINT directives are appropriately used to suppress warnings about global constructors in task registration.
auto square_root(spider::TaskContext&, int value) -> double { | ||
return std::sqrt(value); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🛠️ Refactor suggestion
Add input validation for square_root function.
The square_root function should validate that the input value is non-negative to prevent undefined behaviour.
auto square_root(spider::TaskContext&, int value) -> double {
+ if (value < 0) {
+ throw std::invalid_argument("Cannot calculate square root of negative number");
+ }
return std::sqrt(value);
}
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
auto square_root(spider::TaskContext&, int value) -> double { | |
return std::sqrt(value); | |
} | |
auto square_root(spider::TaskContext&, int value) -> double { | |
if (value < 0) { | |
throw std::invalid_argument("Cannot calculate square root of negative number"); | |
} | |
return std::sqrt(value); | |
} |
Description
This PR adds an example and docs for how to join tasks together.
Validation performed
TODO. Pending resolution of #50.
Summary by CodeRabbit
Release Notes
Documentation
Examples
Development
These updates provide developers with detailed insights into advanced task management in the Spider framework, focusing on task binding and nested task execution.