Skip to content

Conversation

@weareoutman
Copy link
Member

@weareoutman weareoutman commented Nov 15, 2024

…after retry limit exceeded

依赖检查

组件之间的依赖声明,是微服务组件架构下的重要信息,请确保其正确性。

请勾选以下两组选项其中之一:

  • 本次 MR 没有使用上游组件(例如框架、后台组件等)的较新版本提供的特性。

或者:

  • 本次 MR 使用了上游组件(例如框架、后台组件等)的较新版本提供的特性。
  • 在对应的文件中更新了该上游组件的依赖版本(或确认了当前声明的依赖版本已包含本次 MR 使用的新特性)。

提交信息检查

Git 提交信息将决定包的版本发布及自动生成的 CHANGELOG,请检查工作内容与提交信息是否相符,并在以下每组选项中都依次确认。

破坏性变更是针对于下游使用者而言,可以通过本次改动对下游使用者的影响来识别变更类型:

  • 下游使用者不做任何改动,仍可以正常工作时,那么它属于普通变更。
  • 反之,下游使用者不做改动就无法正常工作时,那么它属于破坏性变更。

例如,构件修改了一个属性名,小产品 Storyboard 中需要使用新属性名才能工作,那么它就是破坏性变更。
又例如,构件还没有任何下游使用者,那么它的任何变更都是普通变更。

破坏性变更:

  • ⚠️ 本次 MR 包含破坏性变更的提交,请继续确认以下所有选项:
  • 没有更好的兼容方案,必须做破坏性变更。
  • 使用了 feat 作为提交类型。
  • 标注了 BREAKING CHANGE: 你的变更说明
  • 同时更新了本仓库中所有下游使用者的调用。
  • 同时更新了本仓库中所有下游使用者对该子包的依赖为即将发布的 major 版本。
  • 同时为其它仓库的 Migrating 做好了准备,例如文档或批量改动的方法。
  • 手动验证过破坏性变更在 Migrate 后可以正常工作。
  • 破坏性变更所在的提交没有意外携带其它子包的改动。

新特性:

  • 本次 MR 包含新特性的提交,且该提交不带有破坏性变更,并使用了 feat 作为提交类型。
  • 给新特性添加了单元测试。
  • 手动验证过新特性可以正常工作。

问题修复:

  • 本次 MR 包含问题修复的提交,且该提交不带有新特性或破坏性变更,并使用了 fix 作为提交类型。
  • 给问题修复添加了单元测试。
  • 手动验证过问题修复得到解决。

杂项工作:

即所有对下游使用者无任何影响、且没有必要显示在 CHANGELOG 中的改动,例如修改注释、测试用例、开发文档等:

  • 本次 MR 包含杂项工作的提交,且该提交不带有问题修复、新特性或破坏性变更,并使用了 chore, docs, test 等作为提交类型。

Summary by CodeRabbit

  • 新功能

    • 增强了消息和关闭事件的监听管理,允许用户在添加后取消注册监听器。
    • 引入了 RETRY_LIMIT 常量,以改进错误处理逻辑。
    • 新增了多个函数和接口,扩展了 API 的功能。
  • 改进

    • 更新了 onCloseonMessage 方法的返回类型,以支持更灵活的事件处理。
    • 改进了类型定义,提升了代码的可读性和可维护性。
    • 更新了 API 文档,确保所有必要的类型和函数都得到正确的记录和导出。

@coderabbitai
Copy link

coderabbitai bot commented Nov 15, 2024

Walkthrough

此次更改涉及多个文件,主要集中在 MessageDispatcherMessageService 类的事件处理机制上。onClose 方法的返回类型已更新,以匹配新的处理逻辑。#subOrUnsub 方法进行了重构,采用了两个独立的清理函数来管理事件监听器。RETRY_LIMIT 常量被引入并导出,以便在其他模块中使用。setupTemplateProxy 函数的类型注释也进行了改进,增强了类型安全性。RuntimeHooks 接口的事件处理方法签名也进行了更新,以支持取消订阅功能。

Changes

文件路径 更改摘要
packages/easyops-runtime/src/websocket/MessageDispatcher.ts - 更新 onClose 方法签名,返回类型更改。
- 重构 #subOrUnsub 方法,增加 disposeOnMessagedisposeOnClose 函数。
- 引入并使用 RETRY_LIMIT 常量。
packages/easyops-runtime/src/websocket/MessageService.ts - 导出 RETRY_LIMIT 常量。
- 更新 onMessageonClose 方法签名,返回类型更改。
packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts - 更新 getComputedProps 内部映射函数的返回类型,增强类型安全性。
packages/runtime/src/internal/Runtime.ts - 更新 RuntimeHooks 接口中 onMessageonClose 方法签名,返回类型更改。
etc/runtime.api.md - 更新 RuntimeHooks 接口中的 onMessageonClose 方法签名,返回类型更改。
- 添加多个新函数和接口,更新 API 报告以反映这些更改。

Warning

There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure.

🔧 eslint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

packages/easyops-runtime/src/websocket/MessageDispatcher.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

ESLint couldn't find the config "@next-core/eslint-config-next" to extend from. Please check that the name of the config is correct.

The config "@next-core/eslint-config-next" was referenced from the config file in "/.eslintrc".

If you still have problems, please stop by https://eslint.org/chat/help to chat with the team.


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?

❤️ 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 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[bot]

This comment was marked as resolved.

@weareoutman weareoutman force-pushed the steve/v3-emit-on-message-close branch from 1350bab to 1a6efa6 Compare November 15, 2024 09:22
@codecov
Copy link

codecov bot commented Nov 15, 2024

Codecov Report

Attention: Patch coverage is 93.75000% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.22%. Comparing base (f9fb776) to head (1a6efa6).
Report is 4 commits behind head on v3.

Files with missing lines Patch % Lines
...easyops-runtime/src/websocket/MessageDispatcher.ts 90.00% 0 Missing and 1 partial ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##               v3    #4566      +/-   ##
==========================================
- Coverage   95.23%   95.22%   -0.01%     
==========================================
  Files         206      206              
  Lines        8917     8924       +7     
  Branches     1700     1700              
==========================================
+ Hits         8492     8498       +6     
  Misses        319      319              
- Partials      106      107       +1     
Files with missing lines Coverage Δ
...es/easyops-runtime/src/websocket/MessageService.ts 100.00% <100.00%> (ø)
...src/internal/CustomTemplates/setupTemplateProxy.ts 85.71% <100.00%> (ø)
packages/runtime/src/internal/Runtime.ts 94.56% <ø> (ø)
...easyops-runtime/src/websocket/MessageDispatcher.ts 98.52% <90.00%> (-1.48%) ⬇️

@cypress
Copy link

cypress bot commented Nov 15, 2024

next-core    Run #10785

Run Properties:  status check passed Passed #10785  •  git commit ce5e640d00 ℹ️: Merge 1a6efa6c3361bb65459a2dd4f94983ef0743b6cf into 473c860b1e73598fb3cbebaa983a...
Project next-core
Branch Review steve/v3-emit-on-message-close
Run status status check passed Passed #10785
Run duration 00m 23s
Commit git commit ce5e640d00 ℹ️: Merge 1a6efa6c3361bb65459a2dd4f94983ef0743b6cf into 473c860b1e73598fb3cbebaa983a...
Committer Shenwei Wang
View all properties for this run ↗︎

Test results
Tests that failed  Failures 0
Tests that were flaky  Flaky 0
Tests that did not run due to a developer annotating a test with .skip  Pending 0
Tests that did not run due to a failure in a mocha hook  Skipped 0
Tests that passed  Passing 16
View all changes introduced in this branch ↗︎

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (2)
packages/easyops-runtime/src/websocket/MessageDispatcher.ts (1)

129-147: 消息处理逻辑的重构改进了代码结构

通过分离 message 和 close 事件的处理函数,代码的可维护性得到了提升。建议为复杂的条件判断添加更详细的注释。

建议添加如下注释来解释条件判断的逻辑:

 if (
   (isSuccess || isFailed) &&
-  // Put this after event type checks, to prevent unnecessary
-  // JSON stringify.
+  // 1. 检查事件类型(成功或失败)
+  // 2. 将身份验证放在事件类型检查之后,以避免不必要的 JSON 序列化
+  // 3. 确保消息属于当前的订阅/取消订阅操作
   identity === getIdentity(response.payload)
 ) {
etc/runtime.api.md (1)

477-478: 消息分发器的事件监听器现在支持取消订阅功能

onMessageonClose 方法现在返回取消订阅函数,这是一个很好的改进,可以帮助防止内存泄漏并支持在连接失败时进行适当的清理。

建议在使用这些方法时遵循以下最佳实践:

  1. 始终在组件卸载时调用返回的取消订阅函数
  2. 在重试失败后使用取消订阅函数来清理事件监听器
  3. 考虑使用 React 的 useEffect 钩子(如果适用)来自动处理订阅的生命周期

示例用法:

const unsubscribe = messageDispatcher.onMessage("channel", (data) => {
  // 处理消息
});

// 在组件卸载时清理
useEffect(() => {
  return () => {
    unsubscribe();
  };
}, []);
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 1350bab and 1a6efa6.

📒 Files selected for processing (5)
  • etc/runtime.api.md (1 hunks)
  • packages/easyops-runtime/src/websocket/MessageDispatcher.ts (3 hunks)
  • packages/easyops-runtime/src/websocket/MessageService.ts (2 hunks)
  • packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts (2 hunks)
  • packages/runtime/src/internal/Runtime.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/easyops-runtime/src/websocket/MessageService.ts
  • packages/runtime/src/internal/CustomTemplates/setupTemplateProxy.ts
  • packages/runtime/src/internal/Runtime.ts
🔇 Additional comments (3)
packages/easyops-runtime/src/websocket/MessageDispatcher.ts (3)

7-7: 导入 RETRY_LIMIT 常量的修改是合理的

从 MessageService.js 导入 RETRY_LIMIT 常量有助于在整个模块中保持重试限制的一致性。


102-103: onClose 方法返回值的修改提升了事件监听器的管理能力

现在的实现允许调用者获取取消订阅的函数,这样可以在适当的时候清理事件监听器,防止内存泄漏。


151-159: 错误处理的改进增强了与 V2 版本的兼容性

通过添加 retryCount 属性,确保了在重试限制超出时能够提供与 V2 版本兼容的错误信息。建议验证这个改动在不同版本中的行为是否一致。

运行以下脚本来验证相关代码:

✅ Verification successful

Based on the search results, I can now verify the compatibility concerns. The code shows clear evidence of maintaining compatibility between V2 and V3 versions:

  1. In MessageService.ts, we see the RETRY_LIMIT constant defined and the retry mechanism implementation
  2. The code explicitly mentions "Keep behavior as v2: emit close event only after retry limit exceeded"
  3. The retryCount handling is consistent across the implementation

Let me generate the final response:

WebSocket 错误处理的兼容性已得到验证

代码实现确实保持了与 V2 版本的向后兼容性:

  • 在连接重试超出限制时,会发送包含 retryCount 的错误信息
  • 保持了 V2 版本的行为:仅在重试次数超出限制后才触发关闭事件
  • 重试机制的实现完整且一致
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# 描述:检查 V2 和 V3 版本中的重试处理逻辑差异

# 搜索与重试相关的代码
rg -A 5 "retryCount|RETRY_LIMIT" --type ts

# 搜索错误处理相关的代码
ast-grep --pattern 'reject($_)'

Length of output: 6674

@WHChen-Alex WHChen-Alex merged commit 2ca8c39 into v3 Nov 15, 2024
6 of 7 checks passed
@WHChen-Alex WHChen-Alex deleted the steve/v3-emit-on-message-close branch November 15, 2024 09:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants