Skip to content

fix: address issue causing failure to receive heartbeat #435

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qin8948050
Copy link

@qin8948050 qin8948050 commented Dec 6, 2024

Rename 'heart-beat' to 'heartbeat' to align with emit in puppet.py:1017.


Important

Fixes heartbeat event listener in wechaty.py by renaming event from 'heart-beat' to 'heartbeat'.

  • Behavior:
    • Fixes issue with heartbeat event listener in wechaty.py by renaming event from 'heart-beat' to 'heartbeat' to match the emitted event name.
  • Misc:
    • Aligns event naming convention in wechaty.py for consistency.

This description was created by Ellipsis for a118af1. It will automatically update as commits are pushed.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the event name for the heartbeat event to ensure consistent and reliable event handling.
    • Improved message handling by explicitly returning after sending a file message.
  • New Features
    • Added an option to force synchronization when loading and preparing room data, ensuring the latest information is retrieved.

@qin8948050 qin8948050 requested a review from a team as a code owner December 6, 2024 13:26
@CLAassistant
Copy link

CLAassistant commented Dec 6, 2024

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
0 out of 2 committers have signed the CLA.

❌ xwqin
❌ qin8948050


xwqin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copy link

coderabbitai bot commented Dec 6, 2024

## Walkthrough
The changes in this pull request include renaming the `heart-beat` event to `heartbeat` in the `Wechaty` class for consistent event naming, whitespace cleanup and trailing space removal in the `Contact` class with an added explicit `return None` in the `say` method, and an enhancement to the `Room` class methods to support forced synchronization of room data via a new `force_sync` parameter.

## Changes

| File Path                     | Change Summary                                                                                   |
|------------------------------|-------------------------------------------------------------------------------------------------|
| src/wechaty/wechaty.py        | Changed event name from `heart-beat` to `heartbeat` in `init_puppet_event_bridge` method for consistency. |
| src/wechaty/user/contact.py   | Whitespace cleanup and trailing space removal; added explicit `return None` after sending `FileBox` in `say` method. |
| src/wechaty/user/room.py      | Added `force_sync` parameter to `find_all` and `ready` methods to enable forced room data synchronization. |

## Sequence Diagram(s)
```mermaid
sequenceDiagram
    participant Caller
    participant Room
    participant Puppet

    Caller->>Room: find_all(query, force_sync)
    loop for each room
        Room->>Room: ready(force_sync)
        alt force_sync is True or room not ready
            Room->>Puppet: load room data
            Puppet-->>Room: room data
        else
            Room-->>Room: return cached readiness
        end
    end
    Room-->>Caller: list of ready rooms

🐇 "A heartbeat's name now hops just right,
Clean spaces vanish out of sight.
Rooms sync fresh with forceful cheer,
Ready and steady, far and near!
Code bounces on with joyful pace,
In Wechaty's warm, embracing space! 🥕"


<!-- walkthrough_end -->
<!-- internal state start -->


<!-- DwQgtGAEAqAWCWBnSTIEMB26CuAXA9mAOYCmGJATmriQCaQDG+Ats2bgFyQAOFk+AIwBWJBrngA3EsgEBPRvlqU0AgfFwA6NPEgQAfACgjoCEYDEZyAAUASpADK2VmgqyjcEj2wAbb5AokAI7Y0riQABS2AJSQ4rjedJAARABm8AAeXGi0tAGIyEiIIYxo2IjwGESQKdre2AGx+P6iJJKesCQuuAKduEmQAO5oyEUCzOo09HKxHZBllJCBFQAcAJwALMsADACsW+gY9KjwShjiaYnTuLMYTj186wDMOxows7boOXmI0gco+cUKjN2p0KN1epASFIzpBvEgaOQ+AN1AgsNdPAADAaiWDUWQabiyDHVeAJV4eBQNBi4yqeCoSfDeKTIAIYNDjSrAyHQsJstjVCgsSAYgDkHS6YB61BFxIIwrFoPB0tlTTQcKIWGR1y5UPYkPGuEmKCwGO42G43BImkJxOosIqngAjFtHQB2ckIZBMCgBMTwfBYMhFPIzO3o7l6uGIBELb2++LyZjUam/cMkA1G3VnAA0wIC0zS6QqVXDNVJ9U8ct9rSkkHFYKlYXKGrViA9nnNtGonlbTWjmC7FFo8AAXqnZlne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NAWhIrRhVBFhFQNQdhbBLhAwHo72CJE4RAYJMXa8W8SbQyMEThbooBdAR0R0ZYQTZ0R4T/J4AQLYR4AANkHx2AEFdDdGWBIC2E/x2FdFWDQDQBICuIACYbj1g9jFiDitg0A/i0AtgbioTVhHhaA/jXQGAbjlh1g/idhHgATjUNgSAngXj1gUh1gdhlhXQBBHRgSejaABA/iSAHjYSbjHQUhKTVgUgGAUgSBnhKSGBlhtg/iUhXQtgBBiTUpVgiTVhPAAEQSIBc4DRglVj1ioRNi6BIlDl9AgA=== -->

<!-- internal state end -->
<!-- finishing_touch_checkbox_start -->

<details open="true">
<summary>✨ Finishing Touches</summary>

- [ ] <!-- {"checkboxId": "7962f53c-55bc-4827-bfbf-6a18da830691"} --> 📝 Generate Docstrings

</details>

<!-- finishing_touch_checkbox_end -->
<!-- tips_start -->

---

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.

<details>
<summary>❤️ Share</summary>

- [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai)
- [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai)
- [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai)
- [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code)

</details>

<details>
<summary>🪧 Tips</summary>

### Chat

There are 3 ways to chat with [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=wechaty/python-wechaty&utm_content=435):

- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
  - `I pushed a fix in commit <commit_id>, please review it.`
  - `Explain this complex logic.`
  - `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 explain this code block.`
  -	`@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 explain its main purpose.`
  - `@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.`

### Support

Need help? Create a ticket on our [support page](https://www.coderabbit.ai/contact-us/support) for assistance with any issues or questions.

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 generate docstrings` to [generate docstrings](https://docs.coderabbit.ai/finishing-touches/docstrings) for this PR.
- `@coderabbitai generate sequence diagram` to generate a sequence diagram of the changes in this 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](https://docs.coderabbit.ai/guides/configure-coderabbit) 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](https://docs.coderabbit.ai) for detailed information on how to use CodeRabbit.
- Join our [Discord Community](http://discord.gg/coderabbit) to get help, request features, and share feedback.
- Follow us on [X/Twitter](https://twitter.com/coderabbitai) for updates and announcements.

</details>

<!-- tips_end -->

Copy link

@ellipsis-dev ellipsis-dev bot left a comment

Choose a reason for hiding this comment

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

👍 Looks good to me! Reviewed everything up to a118af1 in 9 seconds

More details
  • Looked at 13 lines of code in 1 files
  • Skipped 0 files when reviewing.
  • Skipped posting 0 drafted comments based on config settings.

Workflow ID: wflow_2PHvTa8He8mPfgfT


You can customize Ellipsis with 👍 / 👎 feedback, review rules, user-specific overrides, quiet mode, and more.

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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between e9a04a9 and a118af1.

📒 Files selected for processing (1)
  • src/wechaty/wechaty.py (1 hunks)

@@ -530,7 +530,7 @@ async def heartbeat_listener(payload: EventHeartbeatPayload) -> None:
self.emit('heartbeat', payload.data)
await self.on_heartbeat(payload)

puppet.on('heart-beat', heartbeat_listener)
puppet.on('heartbeat', heartbeat_listener)
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

The event name 'heart-beat' still exists in the code and needs to be updated

Found remaining instances of 'heart-beat' in src/wechaty/wechaty.py that need to be updated for consistency:

  • Line with elif event_name == 'heart-beat': The condition should use 'heartbeat'
  • Line with log.info('receive <heart-beat> event <%s>', payload): The log message should use 'heartbeat'
🔗 Analysis chain

LGTM! The event name change looks correct.

The change from 'heart-beat' to 'heartbeat' aligns with:

  1. The emit function's usage of 'heartbeat'
  2. The naming convention of other events in the codebase
  3. The event name in puppet.py

Let's verify there are no other occurrences of 'heart-beat' that need to be updated:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining instances of 'heart-beat' in the codebase
rg "heart-beat" -l

# Search for heartbeat event usage to ensure consistency
rg "heartbeat" -A 2 -B 2

Length of output: 2532

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

🧹 Nitpick comments (1)
src/wechaty/user/room.py (1)

197-197: Fix spacing in method signature.

The force_sync parameter needs proper spacing around the comma and colon for PEP 8 compliance.

-                       query: Optional[Union[str, RoomQueryFilter, Callable[[Contact], bool]]] = None,force_sync:bool=False) -> List[Room]:
+                       query: Optional[Union[str, RoomQueryFilter, Callable[[Contact], bool]]] = None, force_sync: bool = False) -> List[Room]:
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0a2a060 and db2e5b9.

📒 Files selected for processing (1)
  • src/wechaty/user/room.py (3 hunks)
🔇 Additional comments (2)
src/wechaty/user/room.py (2)

231-231: LGTM! Proper parameter passing for forced synchronization.

The force_sync parameter is correctly passed to each room.ready() call, enabling forced synchronization when requested by the caller.


318-318: LGTM! Correct logic for force_sync behavior.

The modified conditional logic properly implements the force_sync functionality:

  • When force_sync=False and room is ready: returns early (existing behavior)
  • When force_sync=True: continues with synchronization regardless of current readiness state

This ensures forced synchronization bypasses the cached readiness state as intended.

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