Skip to content
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

Added a Prefix to the watchdog #490 #494

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

Mila2999
Copy link

@Mila2999 Mila2999 commented Oct 9, 2024

Summary by CodeRabbit

  • New Features

    • Updated startWatchdog and startHourglass methods for better flexibility and clarity in timeout handling with customizable prefixes.
  • Bug Fixes

    • Improved output clarity for the help command.
  • Documentation

    • Enhanced documentation for command methods to reflect recent changes.

Copy link

coderabbitai bot commented Oct 9, 2024

Walkthrough

The changes involve updates to the startWatchdog and startHourglass methods in the Shell class located in src/shell.ts. Both methods now accept an object as a parameter, enhancing flexibility by allowing optional and mandatory properties, including a customizable prefix. The internal logic remains largely unchanged, but the logging for the watchdog timeout has been improved for readability. The overall control flow of the class is preserved, ensuring core functionalities remain intact.

Changes

File(s) Change Summary
src/shell.ts Updated startWatchdog method signature to accept an object with optional timeout and prefix. Updated startHourglass method signature to accept an object with mandatory timeout and optional prefix. Improved logging for watchdog timeout using template literals.

Poem

In the code where rabbits play,
Watchdogs now have come to stay.
With timeouts wrapped in objects neat,
Clarity makes our logic sweet.
Hops of joy in every line,
Code so clear, it’s simply fine! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 248ef7e and 4c72df5.

📒 Files selected for processing (1)
  • src/shell.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/shell.ts

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.

Copy link

netlify bot commented Oct 9, 2024

Deploy Preview for terminal7 ready!

Name Link
🔨 Latest commit 4c72df5
🔍 Latest deploy log https://app.netlify.com/sites/terminal7/deploys/671a7a1fb88c2e00088ff6df
😎 Deploy Preview https://deploy-preview-494--terminal7.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

netlify bot commented Oct 9, 2024

Deploy Preview for dazzling-kringle-090742 ready!

Name Link
🔨 Latest commit 4c72df5
🔍 Latest deploy log https://app.netlify.com/sites/dazzling-kringle-090742/deploys/671a7a1faff10700080b5e44
😎 Deploy Preview https://deploy-preview-494--dazzling-kringle-090742.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

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 (3)
src/shell.ts (1)

Line range hint 309-319: LGTM! Consider adding JSDoc for improved documentation.

The changes to the startWatchdog method enhance its flexibility and improve logging clarity. The new object parameter with optional properties is a good approach.

Consider adding JSDoc comments to document the new method signature and parameters:

/**
 * Starts a watchdog that will reject if not stopped within the given time
 * @param {Object} options - The options object
 * @param {number} [options.timeout] - The timeout in milliseconds
 * @param {string} [options.prefix='Waiting'] - The prefix for the log message
 * @returns {Promise<void>}
 */
startWatchdog({ timeout, prefix = 'Waiting' }: { timeout?: number; prefix?: string } = {}): Promise<void> {
  // ... existing implementation
}
src/peerbook.ts (1)

174-174: LGTM! Consider using a constant for the timeout value.

The update to this.shell.startWatchdog({ timeout: 3000 }) is correct and aligns with the PR objectives. It improves the method call's clarity by using an object with a named timeout property.

For better maintainability and consistency, consider defining a constant for the timeout value:

const REGISTRATION_TIMEOUT_MS = 3000;

// Then use it in the method call
this.shell.startWatchdog({ timeout: REGISTRATION_TIMEOUT_MS })

This approach would make it easier to adjust the timeout value in the future if needed and improve code readability.

src/commands.ts (1)

244-244: LGTM! Consider destructuring for clarity.

The update to use an object parameter for startWatchdog is a good change for consistency and future flexibility.

Consider destructuring the parameter for improved readability:

-    shell.startWatchdog({ timeout }).catch(e => gate.handleFailure(e))
+    shell.startWatchdog({ timeout: timeout }).catch(e => gate.handleFailure(e))
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 83bb266 and 00e9515.

📒 Files selected for processing (3)
  • src/commands.ts (6 hunks)
  • src/peerbook.ts (1 hunks)
  • src/shell.ts (2 hunks)
🧰 Additional context used
🔇 Additional comments (5)
src/shell.ts (1)

Line range hint 309-319: Verify usage of updated startWatchdog method

Let's ensure that all calls to startWatchdog have been updated to use the new signature.

✅ Verification successful

Let's update the verification script to correctly search TypeScript files.


Verified: All startWatchdog method calls are using the updated signature.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Search for calls to startWatchdog and verify they use the new signature

# Test: Search for startWatchdog calls
echo "Searching for startWatchdog calls:"
rg --type typescript "startWatchdog\(" -A 3

echo "\nVerifying startWatchdog import/usage:"
rg --type typescript "import.*Shell.*from" -A 10

Length of output: 334


Script:

#!/bin/bash
# Description: Search for calls to startWatchdog and verify they use the new signature

# Test: Search for startWatchdog calls in .ts and .tsx files
echo "Searching for startWatchdog calls in TypeScript files:"
rg "startWatchdog\(" -g "*.ts" -g "*.tsx" -A 3

echo "\nVerifying startWatchdog import/usage in TypeScript files:"
rg "import.*Shell.*from" -g "*.ts" -g "*.tsx" -A 10

Length of output: 4557

src/commands.ts (4)

641-641: LGTM! Consistent with earlier changes.

The update to use an object parameter for startWatchdog is consistent with the earlier changes, maintaining a uniform approach across the codebase.


664-664: LGTM! Verify the extended timeout.

The update to use an object parameter for startWatchdog is consistent with earlier changes. However, the timeout value has increased significantly from 10000 to 120000 milliseconds.

Please confirm if this extended timeout (2 minutes) is intentional and necessary for this operation. If it's a typo, consider reverting to the previous timeout value.


1084-1084: LGTM! Verify the extended timeout.

The update to use an object parameter for startWatchdog is consistent with earlier changes. The timeout value is set to 180000 milliseconds (3 minutes).

Please confirm if this extended timeout (3 minutes) is intentional and necessary for the login process. If it's excessive, consider reducing it to improve user experience.


Line range hint 1-1084: Overall changes look good, but consider reviewing timeout values.

The updates to startWatchdog calls improve consistency across the codebase. However, there are significant variations in timeout values:

  1. connectCMD: 10000 ms
  2. subscribeCMD (first occurrence): 10000 ms
  3. subscribeCMD (second occurrence): 120000 ms
  4. loginCMD: 180000 ms

Consider reviewing these timeout values to ensure they are appropriate for each operation. If possible, define constants for these timeout values at the top of the file or in a configuration file for easier management and consistency.

To help verify the appropriateness of these timeout values, you could add logging or telemetry to measure the actual time taken for these operations in real-world usage. This data can help fine-tune the timeout values for optimal user experience.

src/shell.ts Outdated
@@ -316,7 +316,7 @@ export class Shell {
this.watchdogResolve = resolve
this.startHourglass(timeout)
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for the PR!

the startHourglass is where the progress bar is printed and it also needs to be updated: receive the prefix and print it before the progress bar.

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

Files that changed from the base of the PR and between 00e9515 and 248ef7e.

📒 Files selected for processing (1)
  • src/shell.ts (2 hunks)
🔇 Additional comments (2)
src/shell.ts (2)

319-319: LGTM! Improved logging readability.

The use of template literals improves code readability.


309-317: LGTM! Verify callers of startWatchdog.

The parameter changes improve the API by using named parameters, making it more flexible and self-documenting. However, this is a breaking change that requires updating existing callers.

Let's verify the impact on existing callers:

✅ Verification successful

Based on the rg results, I can now generate the final response as I have enough information to verify the impact on callers.

All callers of startWatchdog have been properly updated to use the new object parameter syntax

The verification shows that all callers across the codebase (src/peerbook.ts, src/commands.ts, src/terminal7.ts, and src/gate.ts) are using the new object parameter syntax correctly. Examples:

  • Using with timeout: startWatchdog({ timeout: 3000 })
  • Using without parameters: startWatchdog()
  • Using with configurable timeout: startWatchdog({ timeout })
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all calls to startWatchdog to ensure they're updated
# Expected: All calls should use the new object parameter syntax

rg "startWatchdog" --type ts

Length of output: 930

src/shell.ts Outdated
Comment on lines 339 to 347
startHourglass({ timeout, prefix = 'Waiting' } : { timeout: number; prefix?: string } ) {
if (this.timer) return
this.map.showLog(true)
const len = 20,
interval = timeout / len
let i = 0
this.timer = window.setInterval(() => {
const dots = Math.max(0, len - i) // i should never be > len, but just in case
this.t.write(`\r\x1B[K${" ".repeat(i)}ᗧ${"·".repeat(dots)}🍒\x1B[?25l`)
this.t.write(`\r\x1B[K${prefix}${" ".repeat(i)}ᗧ${"·".repeat(dots)}🍒\x1B[?25l`)
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue

Consider making parameter types consistent with startWatchdog.

While the changes implement the requested prefix feature, there's an inconsistency in how parameters are handled between startWatchdog and startHourglass:

  • In startWatchdog, both timeout and prefix are optional
  • In startHourglass, timeout is required but prefix is optional

This could lead to confusion since these methods are closely related.

Consider making both parameters optional in startHourglass to match startWatchdog:

-    startHourglass({ timeout, prefix = 'Waiting' } : { timeout: number; prefix?: string } ) {
+    startHourglass({ timeout, prefix = 'Waiting' } : { timeout?: number; prefix?: string } = {} ) {
         if (this.timer) return
         this.map.showLog(true)
         const len = 20,
-            interval = timeout / len
+            interval = (timeout || terminal7.conf.net.timeout) / len

Committable suggestion was skipped due to low confidence.

@Mila2999
Copy link
Author

Hi @daonb,
Sorry for the delay in getting back to you about the hourglass animation. I’ve just pushed the changes we talked about. Let me know if you’d like anything tweaked

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