-
Notifications
You must be signed in to change notification settings - Fork 12
feat: Add worker client that submit tasks and get next task from schedulers #35
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
Changes from all commits
932dd82
28e3960
b340477
9ffb1d4
0cff600
29ca2e2
b691e37
97d46a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,45 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifndef SPIDER_CORE_DRIVER_HPP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define SPIDER_CORE_DRIVER_HPP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <utility> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <boost/uuid/uuid.hpp> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace spider::core { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Driver { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Driver(boost::uuids::uuid const id, std::string addr) : m_id{id}, m_addr{std::move(addr)} {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] auto get_id() const -> boost::uuids::uuid const& { return m_id; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] auto get_addr() const -> std::string const& { return m_addr; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boost::uuids::uuid m_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string m_addr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class Scheduler { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Scheduler(boost::uuids::uuid const id, std::string addr, int port) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : m_id{id}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_addr{std::move(addr)}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_port{port} {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+30
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add documentation and parameter validation for Scheduler class. The Scheduler class needs documentation and parameter validation. +/**
+ * Represents a scheduler node in the Spider system.
+ * Manages task distribution and scheduling operations.
+ */
class Scheduler {
public:
+ /**
+ * Constructs a Scheduler instance.
+ * @param id Unique identifier for the scheduler
+ * @param addr Network address (ownership transferred)
+ * @param port Network port number (must be between 1 and 65535)
+ * @throws std::invalid_argument if port is invalid or address is empty
+ */
- Scheduler(boost::uuids::uuid const id, std::string addr, int port)
- : m_id{id},
- m_addr{std::move(addr)},
- m_port{port} {}
+ Scheduler(boost::uuids::uuid const id, std::string&& addr, int port) {
+ if (addr.empty()) {
+ throw std::invalid_argument("Scheduler address cannot be empty");
+ }
+ if (port <= 0 || port > 65535) {
+ throw std::invalid_argument("Invalid port number");
+ }
+ m_id = id;
+ m_addr = std::move(addr);
+ m_port = port;
+ }📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] auto get_id() const -> boost::uuids::uuid const& { return m_id; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] auto get_addr() const -> std::string const& { return m_addr; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| [[nodiscard]] auto get_port() const -> int { return m_port; } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| private: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| boost::uuids::uuid m_id; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::string m_addr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int m_port; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace spider::core | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif // SPIDER_CORE_DRIVER_HPP | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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 address validation in constructor.
Consider validating that the address isn't empty to ensure valid driver instances.
📝 Committable suggestion