-
Notifications
You must be signed in to change notification settings - Fork 1
refactor(core): 主操作类获取方式改为属性,新增计划任务管理 #18
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
Conversation
审阅者指南将核心 MCSMAPI 入口从可调用方法重构为属性,引入完整的调度模型和用于管理实例计划任务的 API,丰富守护进程模型和示例以使用类型化配置,统一文件复制命名,并将包版本提升到 0.1.8。 使用新 Schedule API 进行实例计划管理的时序图sequenceDiagram
actor Client
participant MCSMAPI
participant Instance
participant ScheduleAPI as Schedule
participant Request
participant MCSMPanel as MCSMPanelScheduleEndpoint
Client->>MCSMAPI: api = MCSMAPI(base_url)
Client->>MCSMAPI: instance = api.instance
Client->>Instance: schedules = instance.list_schedule()
Instance->>ScheduleAPI: list(daemonId, instanceUuid)
ScheduleAPI->>Request: send("GET", ApiPool.SCHEDULE, params)
Request->>MCSMPanel: HTTP GET /api/protected_schedule
MCSMPanel-->>Request: schedule list JSON
Request-->>ScheduleAPI: list of dict
ScheduleAPI-->>Instance: list of ScheduleDetail
Instance-->>Client: list of ScheduleDetail
Client->>Instance: create_schedule(config)
Instance->>ScheduleAPI: create(daemonId, instanceUuid, config)
ScheduleAPI->>Request: send("POST", ApiPool.SCHEDULE, params, data)
Request->>MCSMPanel: HTTP POST /api/protected_schedule
MCSMPanel-->>Request: success flag
Request-->>ScheduleAPI: bool
ScheduleAPI-->>Instance: bool
Instance-->>Client: bool
新调度模型和 API 的类图classDiagram
class ScheduleActionType {
<<enumeration>>
COMMAND
DELAY
STOP
START
RESTART
KILL
}
class ScheduleType {
<<enumeration>>
INTERVAL
CYCLE
SPECIFY
}
class ScheduleAction {
+ScheduleActionType type
+str payload
}
class SchedulePostBody {
+str name
+int count
+str time
+list~ScheduleAction~ actions
+ScheduleType type
}
class ScheduleDetail {
+str instanceUuid
+str daemonId
+bool delete()
+bool update(config SchedulePostBody)
}
class Schedule {
+list~ScheduleDetail~ list(daemonId str, uuid str)
+bool delete(daemonId str, uuid str, task_name str)
+bool create(daemonId str, uuid str, config SchedulePostBody)
+bool update(daemonId str, uuid str, config SchedulePostBody)
}
class Instance {
+str daemonId
+str instanceUuid
+list~ScheduleDetail~ list_schedule()
+bool create_schedule(config SchedulePostBody)
}
ScheduleAction --> ScheduleActionType
SchedulePostBody --> ScheduleType
SchedulePostBody "1" --> "*" ScheduleAction : actions
ScheduleDetail --|> SchedulePostBody
Instance ..> Schedule : uses
Instance --> ScheduleDetail : returns
更新后的守护进程模型和 MCSMAPI 入口的类图classDiagram
class MCSMAPI {
+str mcsm_url
+str authentication
+overview
+instance
+user
+daemon
+file
+image
+login(username str, password str) MCSMAPI
+login_with_apikey(apikey str) MCSMAPI
}
class Overview
class Instance
class User
class Daemon
class File
class Image
MCSMAPI --> Overview : overview
MCSMAPI --> Instance : instance
MCSMAPI --> User : user
MCSMAPI --> Daemon : daemon
MCSMAPI --> File : file
MCSMAPI --> Image : image
class DaemonSetting {
+int port
+int maxDownloadFromUrlFileCount
}
class DaemonOperation {
+str id
+str ip
+int port
+str prefix
+str remarks
}
class DaemonConfig {
+str ip
+int port
+str prefix
+str remarks
+str apiKey
}
class DaemonSystemInfo {
+str version
+ProcessInfo process
+InstanceStat instance
+SystemInfo system
+list~CpuMemChart~ cpuMemChart
+DaemonSetting config
+bool available
+str ip
+int port
+str prefix
+str remarks
}
class DaemonApi {
+list~DaemonSystemInfo~ system()
+str add(config DaemonConfig)
+bool delete(daemonId str)
}
DaemonSystemInfo --|> DaemonOperation
DaemonSystemInfo --> DaemonSetting
DaemonApi --> DaemonSystemInfo : returns
DaemonApi --> DaemonConfig : accepts
文件级更改
与关联 Issue 的对照评估
可能关联的 Issue
技巧和命令与 Sourcery 交互
自定义你的体验访问你的 dashboard 以:
获取帮助Original review guide in EnglishReviewer's GuideRefactors the core MCSMAPI entrypoints to be property-based instead of callable methods, introduces a full scheduling model and API for managing instance scheduled tasks, enriches daemon models and examples to use typed configs, unifies file copy naming, and bumps the package to 0.1.8. Sequence diagram for instance schedule management via new Schedule APIsequenceDiagram
actor Client
participant MCSMAPI
participant Instance
participant ScheduleAPI as Schedule
participant Request
participant MCSMPanel as MCSMPanelScheduleEndpoint
Client->>MCSMAPI: api = MCSMAPI(base_url)
Client->>MCSMAPI: instance = api.instance
Client->>Instance: schedules = instance.list_schedule()
Instance->>ScheduleAPI: list(daemonId, instanceUuid)
ScheduleAPI->>Request: send("GET", ApiPool.SCHEDULE, params)
Request->>MCSMPanel: HTTP GET /api/protected_schedule
MCSMPanel-->>Request: schedule list JSON
Request-->>ScheduleAPI: list of dict
ScheduleAPI-->>Instance: list of ScheduleDetail
Instance-->>Client: list of ScheduleDetail
Client->>Instance: create_schedule(config)
Instance->>ScheduleAPI: create(daemonId, instanceUuid, config)
ScheduleAPI->>Request: send("POST", ApiPool.SCHEDULE, params, data)
Request->>MCSMPanel: HTTP POST /api/protected_schedule
MCSMPanel-->>Request: success flag
Request-->>ScheduleAPI: bool
ScheduleAPI-->>Instance: bool
Instance-->>Client: bool
Class diagram for new schedule models and APIsclassDiagram
class ScheduleActionType {
<<enumeration>>
COMMAND
DELAY
STOP
START
RESTART
KILL
}
class ScheduleType {
<<enumeration>>
INTERVAL
CYCLE
SPECIFY
}
class ScheduleAction {
+ScheduleActionType type
+str payload
}
class SchedulePostBody {
+str name
+int count
+str time
+list~ScheduleAction~ actions
+ScheduleType type
}
class ScheduleDetail {
+str instanceUuid
+str daemonId
+bool delete()
+bool update(config SchedulePostBody)
}
class Schedule {
+list~ScheduleDetail~ list(daemonId str, uuid str)
+bool delete(daemonId str, uuid str, task_name str)
+bool create(daemonId str, uuid str, config SchedulePostBody)
+bool update(daemonId str, uuid str, config SchedulePostBody)
}
class Instance {
+str daemonId
+str instanceUuid
+list~ScheduleDetail~ list_schedule()
+bool create_schedule(config SchedulePostBody)
}
ScheduleAction --> ScheduleActionType
SchedulePostBody --> ScheduleType
SchedulePostBody "1" --> "*" ScheduleAction : actions
ScheduleDetail --|> SchedulePostBody
Instance ..> Schedule : uses
Instance --> ScheduleDetail : returns
Class diagram for updated daemon models and MCSMAPI entrypointsclassDiagram
class MCSMAPI {
+str mcsm_url
+str authentication
+overview
+instance
+user
+daemon
+file
+image
+login(username str, password str) MCSMAPI
+login_with_apikey(apikey str) MCSMAPI
}
class Overview
class Instance
class User
class Daemon
class File
class Image
MCSMAPI --> Overview : overview
MCSMAPI --> Instance : instance
MCSMAPI --> User : user
MCSMAPI --> Daemon : daemon
MCSMAPI --> File : file
MCSMAPI --> Image : image
class DaemonSetting {
+int port
+int maxDownloadFromUrlFileCount
}
class DaemonOperation {
+str id
+str ip
+int port
+str prefix
+str remarks
}
class DaemonConfig {
+str ip
+int port
+str prefix
+str remarks
+str apiKey
}
class DaemonSystemInfo {
+str version
+ProcessInfo process
+InstanceStat instance
+SystemInfo system
+list~CpuMemChart~ cpuMemChart
+DaemonSetting config
+bool available
+str ip
+int port
+str prefix
+str remarks
}
class DaemonApi {
+list~DaemonSystemInfo~ system()
+str add(config DaemonConfig)
+bool delete(daemonId str)
}
DaemonSystemInfo --|> DaemonOperation
DaemonSystemInfo --> DaemonSetting
DaemonApi --> DaemonSystemInfo : returns
DaemonApi --> DaemonConfig : accepts
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
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.
Hey - 我发现了 5 个问题,并留下了一些高层次反馈:
- 在
example/use_case/get_all_instance_info.py中,json.dump已经会将内容写入文件并返回None,因此把返回值赋给content、对其进行断言,然后再调用f.write(content)要么会失败,要么会写入字符串"None";可以简化为单行json.dump(instance_info, f, indent=4),不需要content或f.write。 - 将
File.copy/File.copy2重命名为copy_to(以及对应示例代码的修改)是一个破坏性变更,和mcsm.instance()→mcsm.instance的重构类似;建议新增一个已弃用的copy包装器,在一到两个版本中转发到copy_to,以便依赖旧名称的现有调用方更平滑地迁移。
给 AI Agent 的提示词
请根据这次代码评审中的评论进行修改:
## 总体评论
- 在 `example/use_case/get_all_instance_info.py` 中,`json.dump` 已经会将内容写入文件并返回 `None`,因此把返回值赋给 `content`、对其进行断言,然后再调用 `f.write(content)` 要么会失败,要么会写入字符串 `"None"`;可以简化为单行 `json.dump(instance_info, f, indent=4)`,不需要 `content` 或 `f.write`。
- 将 `File.copy`/`File.copy2` 重命名为 `copy_to`(以及对应示例代码的修改)是一个破坏性变更,和 `mcsm.instance()`→`mcsm.instance` 的重构类似;建议新增一个已弃用的 `copy` 包装器,在一到两个版本中转发到 `copy_to`,以便依赖旧名称的现有调用方更平滑地迁移。
## 逐条评论
### 评论 1
<location> `mcsmapi/models/schedule.py:42` </location>
<code_context>
+ """动作参数"""
+
+
+class SchedulePostBody(BaseModel):
+ """计划任务配置参数"""
+
</code_context>
<issue_to_address>
**issue (bug_risk):** SchedulePostBody 似乎缺少一个 `instanceUuid` 字段,而文档字符串中有相关暗示。
在 `name: str` 之前的独立文档字符串 `"""实例uuid"""` 表明 `SchedulePostBody` 应该包含一个 `instanceUuid` 字段。目前在创建/更新时从未发送实例 UUID,因此后端无法知道应该把计划任务关联到哪个实例上。请添加 `instanceUuid: str` 字段(如果 API 需要的话,也请添加 `daemonId`),以便请求载荷包含完整上下文。
</issue_to_address>
### 评论 2
<location> `mcsmapi/models/schedule.py:71-80` </location>
<code_context>
+
+ return Schedule.delete(self.daemonId, self.instanceUuid, self.name)
+
+ def update(self, config: SchedulePostBody):
+ """
+ 更新计划任务
+
+ :param config: 计划任务配置
+
+ :returns: 是否成功
+ """
+ from mcsmapi.apis.schedule import Schedule
+
+ return Schedule.update(config)
</code_context>
<issue_to_address>
**issue (bug_risk):** ScheduleDetail.update 没有使用实例自身的标识符,可能导致更新请求信息不完整。
`ScheduleDetail` 已经有 `instanceUuid` 和 `daemonId`,但 `update` 忽略了它们,只把 `config` 转发给 `Schedule.update`。如果 API 期望这些标识符(就像 `delete`/`list` 那样),那么该请求可能不完整,并迫使调用方在 `config` 中重复传入它们。建议在 `update` 中使用 `self.daemonId` / `self.instanceUuid`(并在需要时调整 `SchedulePostBody`),或者引入一个始终包含这些标识符的请求类型。
</issue_to_address>
### 评论 3
<location> `mcsmapi/apis/schedule.py:43-52` </location>
<code_context>
+ )
+
+ @staticmethod
+ def create(config: SchedulePostBody) -> bool:
+ """
+ 创建计划任务
+
+ :param config: 计划任务配置
+
+ :returns: 是否成功
+ """
+ return send(
+ "POST",
+ f"{ApiPool.SCHEDULE}",
+ data=config.model_dump(),
+ )
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Schedule.create 只发送请求体,没有发送其他端点使用的 daemon/instance 标识符。
`list` 和 `delete` 会把 `daemonId` 和 `uuid` 作为查询参数传递,但 `create` 只发送不带标识符的 `config.model_dump()`。除非后端能从认证上下文推导出目标实例,否则这可能不足以将计划任务绑定到正确的 daemon/instance 上。建议将 `daemonId`/`instanceUuid` 添加到 `SchedulePostBody` 中,或者像 `delete` 那样通过查询参数传递。
</issue_to_address>
### 评论 4
<location> `example/use_case/get_all_instance_info.py:43-45` </location>
<code_context>
# Optional: Save info to a file in the current directory
with open("instance_info.json", "w") as f:
content = json.dump(instance_info, f, indent=4)
+ assert content
f.write(content)
</code_context>
<issue_to_address>
**issue (bug_risk):** 使用 json.dump 的返回值会导致断言失败以及写入时出现 TypeError。
`json.dump` 会直接写入文件并始终返回 `None`,因此 `assert content` 会一直失败,而 `f.write(content)` 会抛出 `TypeError`。如果想同时得到字符串和文件输出,可以使用 `json.dumps` 然后调用 `f.write(content)`;或者继续使用 `json.dump`,但移除 `content`(包括断言和额外的写入)。
</issue_to_address>
### 评论 5
<location> `mcsmapi/models/daemon.py:138-147` </location>
<code_context>
"""远程节点的apiKey"""
+class DaemonSystemInfo(DaemonOperation):
+ """节点系统信息"""
+
+ version: str
+ """远程节点版本"""
+ process: ProcessInfo
+ """远程节点的基本信息"""
+ instance: InstanceStat
+ """远程节点实例基本信息"""
+ system: SystemInfo
+ """远程节点系统信息"""
+ cpuMemChart: list[CpuMemChart]
+ """cpu和内存使用趋势"""
+ config: DaemonSetting
+ """节点系统配置信息"""
+ available: bool
+ """节点可用状态"""
+ ip: str
+ """远程节点的ip"""
+ port: int
+ """远程节点的端口"""
+ prefix: str
+ """远程节点的路径前缀"""
+ remarks: str
+ """远程节点的备注"""
+
</code_context>
<issue_to_address>
**issue:** DaemonSystemInfo 字段已经改为非可选,这可能与实际可能包含 null 值的 API 响应不匹配。
这些字段(`version`、`process`、`instance`、`system`、`cpuMemChart`)之前是可选的,现在改为必填,同时该模型继承了 `DaemonOperation`。如果后端在某些情况下返回 `null` 或遗漏其中任意字段(例如 daemon 离线/初始化阶段),Pydantic 将无法通过校验。请要么保持这些字段为可选,要么确认 API 对每个 daemon 始终返回这些字段。
</issue_to_address>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English
Hey - I've found 5 issues, and left some high level feedback:
- In
example/use_case/get_all_instance_info.py,json.dumpalready writes to the file and returnsNone, so assigning its result tocontent, asserting it, and then callingf.write(content)will either fail or write"None"; simplify to a singlejson.dump(instance_info, f, indent=4)withoutcontentorf.write. - The rename from
File.copy/File.copy2tocopy_to(and the corresponding example change) is a breaking change similar to themcsm.instance()→mcsm.instancerefactor; consider adding a deprecatedcopywrapper that forwards tocopy_tofor one or two releases to ease migration for existing callers relying on the old name.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `example/use_case/get_all_instance_info.py`, `json.dump` already writes to the file and returns `None`, so assigning its result to `content`, asserting it, and then calling `f.write(content)` will either fail or write `"None"`; simplify to a single `json.dump(instance_info, f, indent=4)` without `content` or `f.write`.
- The rename from `File.copy`/`File.copy2` to `copy_to` (and the corresponding example change) is a breaking change similar to the `mcsm.instance()`→`mcsm.instance` refactor; consider adding a deprecated `copy` wrapper that forwards to `copy_to` for one or two releases to ease migration for existing callers relying on the old name.
## Individual Comments
### Comment 1
<location> `mcsmapi/models/schedule.py:42` </location>
<code_context>
+ """动作参数"""
+
+
+class SchedulePostBody(BaseModel):
+ """计划任务配置参数"""
+
</code_context>
<issue_to_address>
**issue (bug_risk):** SchedulePostBody appears to be missing an `instanceUuid` field that the docstring hints at.
The standalone docstring `"""实例uuid"""` before `name: str` suggests `SchedulePostBody` should include an `instanceUuid` field. Currently the instance UUID is never sent in create/update, so the backend can’t know which instance to attach the schedule to. Please add an `instanceUuid: str` field (and `daemonId` as well if the API requires it) so the payload includes the full context.
</issue_to_address>
### Comment 2
<location> `mcsmapi/models/schedule.py:71-80` </location>
<code_context>
+
+ return Schedule.delete(self.daemonId, self.instanceUuid, self.name)
+
+ def update(self, config: SchedulePostBody):
+ """
+ 更新计划任务
+
+ :param config: 计划任务配置
+
+ :returns: 是否成功
+ """
+ from mcsmapi.apis.schedule import Schedule
+
+ return Schedule.update(config)
</code_context>
<issue_to_address>
**issue (bug_risk):** ScheduleDetail.update does not use the instance’s own identifiers, which may result in incomplete update requests.
`ScheduleDetail` already has `instanceUuid` and `daemonId`, but `update` ignores them and forwards only `config` to `Schedule.update`. If the API expects these identifiers (as `delete`/`list` do), the request may be incomplete and forces callers to redundantly pass them in `config`. Prefer using `self.daemonId`/`self.instanceUuid` in `update` (and adjusting `SchedulePostBody` if needed), or introduce a request type that always includes these identifiers.
</issue_to_address>
### Comment 3
<location> `mcsmapi/apis/schedule.py:43-52` </location>
<code_context>
+ )
+
+ @staticmethod
+ def create(config: SchedulePostBody) -> bool:
+ """
+ 创建计划任务
+
+ :param config: 计划任务配置
+
+ :returns: 是否成功
+ """
+ return send(
+ "POST",
+ f"{ApiPool.SCHEDULE}",
+ data=config.model_dump(),
+ )
+
</code_context>
<issue_to_address>
**issue (bug_risk):** Schedule.create sends only the body, without daemon/instance identifiers that other endpoints use.
`list` and `delete` include `daemonId` and `uuid` as query params, but `create` only posts `config.model_dump()` with no identifiers. Unless the backend derives the target instance from auth context, this may not be enough to bind the schedule to the correct daemon/instance. Consider adding `daemonId`/`instanceUuid` to `SchedulePostBody` or passing them as params like `delete`.
</issue_to_address>
### Comment 4
<location> `example/use_case/get_all_instance_info.py:43-45` </location>
<code_context>
# Optional: Save info to a file in the current directory
with open("instance_info.json", "w") as f:
content = json.dump(instance_info, f, indent=4)
+ assert content
f.write(content)
</code_context>
<issue_to_address>
**issue (bug_risk):** Using json.dump’s return value leads to an assertion failure and a TypeError on write.
`json.dump` writes directly to the file and always returns `None`, so `assert content` will always fail and `f.write(content)` will raise a `TypeError`. To get both a string and file output, use `json.dumps` and then `f.write(content)`, or keep `json.dump` and remove `content` (including the assert and extra write).
</issue_to_address>
### Comment 5
<location> `mcsmapi/models/daemon.py:138-147` </location>
<code_context>
"""远程节点的apiKey"""
+class DaemonSystemInfo(DaemonOperation):
+ """节点系统信息"""
+
+ version: str
+ """远程节点版本"""
+ process: ProcessInfo
+ """远程节点的基本信息"""
+ instance: InstanceStat
+ """远程节点实例基本信息"""
+ system: SystemInfo
+ """远程节点系统信息"""
+ cpuMemChart: list[CpuMemChart]
+ """cpu和内存使用趋势"""
+ config: DaemonSetting
+ """节点系统配置信息"""
+ available: bool
+ """节点可用状态"""
+ ip: str
+ """远程节点的ip"""
+ port: int
+ """远程节点的端口"""
+ prefix: str
+ """远程节点的路径前缀"""
+ remarks: str
+ """远程节点的备注"""
+
</code_context>
<issue_to_address>
**issue:** DaemonSystemInfo fields have been made non-optional, which may not match API responses that can contain null values.
These fields (`version`, `process`, `instance`, `system`, `cpuMemChart`) were optional before and are now required, and the model now extends `DaemonOperation`. If the backend ever returns `null` or omits any of them (e.g., for offline/initializing daemons), Pydantic will fail validation. Please either keep these as optional or confirm the API always returns all of them for every daemon.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
为计划任务的创建和更新方法添加daemonId和uuid参数, 使接口调用更加明确和一致。 fix(daemon): 改进节点系统信息模型定义 将DaemonSystemInfo模型中的字段改为可选类型,改进文档字符串描述, 使节点信息处理更加灵活。 refactor(instance): 优化实例信息获取逻辑 重构get_all_instance_info函数,使用字典推导式简化代码, 移除不必要的断言和文件写入操作。 feat(instance): 添加实例计划任务创建功能 在InstanceDetail类中添加create_schedule方法, 方便通过实例对象直接创建计划任务。 refactor(overview): 优化节点可用性检查逻辑 使用海象运算符简化节点可用性检查,添加类型忽略注释, 提高代码可读性。
|
@sourcery-ai review |
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.
Hey - 我在这里给出了一些总体反馈:
- 在 schedule API 中,
Schedule.create和Schedule.update的实现是完全相同的(相同的 HTTP 方法、URL 和参数);建议将它们合并为一个公共的辅助函数以避免重复,或者如果后端在创建与更新时期望有不同的行为,则在 HTTP 语义上加以区分。 - 在
example/overview.py中,新加的if ava := remote.available:以及后面几个# type: ignore标记可以通过直接检查实际可选字段来清理掉(例如:if remote.available and remote.system is not None:),同时去掉未使用的ava变量绑定,以保持示例在类型上更安全并且更清晰。
给 AI 代理的提示
Please address the comments from this code review:
## Overall Comments
- In the schedule API, `Schedule.create` and `Schedule.update` have identical implementations (same HTTP method, URL, and params); consider consolidating them into a single helper to avoid duplication or differentiating the HTTP semantics if the backend expects different behavior for creation vs update.
- In `example/overview.py`, the new `if ava := remote.available:` plus several `# type: ignore` markers could be cleaned up by checking the actual optional fields (e.g., `if remote.available and remote.system is not None:`) and dropping the unused `ava` binding to keep the example type-safe and clearer.帮我变得更有用!请在每条评论上点击 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English
Hey - I've left some high level feedback:
- In the schedule API,
Schedule.createandSchedule.updatehave identical implementations (same HTTP method, URL, and params); consider consolidating them into a single helper to avoid duplication or differentiating the HTTP semantics if the backend expects different behavior for creation vs update. - In
example/overview.py, the newif ava := remote.available:plus several# type: ignoremarkers could be cleaned up by checking the actual optional fields (e.g.,if remote.available and remote.system is not None:) and dropping the unusedavabinding to keep the example type-safe and clearer.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In the schedule API, `Schedule.create` and `Schedule.update` have identical implementations (same HTTP method, URL, and params); consider consolidating them into a single helper to avoid duplication or differentiating the HTTP semantics if the backend expects different behavior for creation vs update.
- In `example/overview.py`, the new `if ava := remote.available:` plus several `# type: ignore` markers could be cleaned up by checking the actual optional fields (e.g., `if remote.available and remote.system is not None:`) and dropping the unused `ava` binding to keep the example type-safe and clearer.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
移除example/overview.py中的海象操作符(Available assignment operator), 使代码更加清晰易读。 优化mcsmapi/apis/schedule.py中的Schedule.create方法调用, 直接使用类方法替代复杂的send函数调用,提高代码可维护性。
为MCSMAPI类添加@Property装饰器,使overview、instance、user、daemon、file、image等方法可以作为属性访问,
简化了调用方式。同时删除了多余的括号调用,在examples中更新了所有相关调用方式。
resolve [Feature Request]: 计划任务管理
Fixes [Feature Request]: 计划任务管理 #17
BREAKING CHANGE: 原来的mcsm.daemon()、mcsm.instance()等调用方式需要改为mcsm.daemon、mcsm.instance
由 Sourcery 生成的摘要
重构核心 API 入口点,将方法调用改为属性访问,并引入实例计划任务管理功能。
新功能:
错误修复:
copy_to命名下,避免不同复制辅助函数之间的混淆。增强改进:
MCSMAPI的使用方式,使overview、instance、user、daemon、file和image可作为属性访问而非方法调用,并相应更新示例。构建:
0.1.8,以包含新的调度功能和 API 变更。Original summary in English
Summary by Sourcery
重构核心 API 入口点以使用基于属性的访问方式,并引入实例计划任务管理能力。
新功能:
错误修复:
copy_to命名,以避免不同复制辅助方法之间的混淆。增强改进:
MCSMAPI的使用方式,将 overview、instance、user、daemon、file 和 image 从方法改为属性访问,并相应更新示例代码。构建:
0.1.8,以体现新的计划任务功能和 API 变更。Original summary in English
Summary by Sourcery
Refactor the core API entrypoints to use attribute-based access and introduce instance schedule management capabilities.
New Features:
Bug Fixes:
Enhancements:
Build: