Skip to content

Conversation

@pujitm
Copy link
Member

@pujitm pujitm commented Jan 12, 2025

prior to this, pm2 would mark unraid-api as started as soon as the node process started. The Nest server wouldn't finish booting until later. This meant unraid-api could "start", but the webgui wouldn't be fully functional because it couldn't connect to the api yet. This was a sucky user & dev experience.

Summary by CodeRabbit

  • Configuration Updates

    • Added configuration properties to improve application startup behavior
    • Set a 30-second timeout for connection listening
    • Enabled wait-ready mode for the application
  • Development Workflow

    • Introduced new commands in project build system for building and deploying
    • Enhanced deployment script to automatically build project if needed
  • Performance Improvements

    • Added process readiness notification mechanism for more robust server startup

prior to this, pm2 would mark unraid-api as started as soon as the
node process started. The Nest server wouldn't finish booting until
later. This meant unraid-api could "start", but the webgui wouldn't be
fully functional because it couldn't connect to the api yet. This was a
sucky user & dev experience.
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

The pull request introduces configuration and deployment enhancements for the Unraid API project. The changes focus on improving application startup behavior by adding readiness and timeout configurations in the ecosystem config, updating the deployment script to handle build processes more robustly, and modifying the main application entry point to signal readiness to the parent process. These modifications streamline the deployment and startup workflow of the application.

Changes

File Change Summary
api/ecosystem.config.json Added "wait_ready": true and "listen_timeout": 30000 to improve application startup configuration
api/justfile Added new commands: build, deploy, and bd for simplified project building and deployment
api/scripts/deploy-dev.sh Updated source directory handling, added build process check, and improved error handling
api/src/unraid-api/main.ts Added conditional readiness signal to parent process after server starts listening

Possibly related PRs

Suggested reviewers

  • mdatelle
  • elibosley

Poem

🐰 Deployment's dance, a rabbit's delight,
Config tweaks make everything right!
Build, deploy with just one command,
Readiness signaled, perfectly planned
Unraid API hops to new heights! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between 6dd9b93 and 02e8658.

📒 Files selected for processing (1)
  • api/src/unraid-api/main.ts (1 hunks)

🪧 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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
Contributor

@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)
api/scripts/deploy-dev.sh (1)

Line range hint 26-64: Consider cleaning old files before deployment

To prevent stale files from causing issues, consider cleaning the remote directory before deploying new files.

Add remote cleanup before rsync:

 # Replace the value inside the rsync command with the user's input
+ssh root@"${server_name}" "rm -rf /usr/local/unraid-api/dist/*"
 rsync_command="rsync -avz -e ssh $source_directory root@${server_name}:/usr/local/unraid-api"
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro (Legacy)

📥 Commits

Reviewing files that changed from the base of the PR and between f47c558 and 6dd9b93.

📒 Files selected for processing (4)
  • api/ecosystem.config.json (1 hunks)
  • api/justfile (1 hunks)
  • api/scripts/deploy-dev.sh (2 hunks)
  • api/src/unraid-api/main.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build and Test API
  • GitHub Check: Build Web App
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
api/justfile (1)

11-20: Well-structured command additions!

The new commands provide a clear and convenient way to build and deploy the application. The comments effectively document each command's purpose.

api/src/unraid-api/main.ts (1)

51-53: Correct implementation of ready signal!

The ready signal is sent at the right time (after server is listening) and with proper parent process check. This ensures pm2 only marks the service as ready after the Nest server is fully operational.

api/ecosystem.config.json (1)

10-11: Verify if 30s listen_timeout is sufficient

While the wait_ready configuration correctly enables the ready signal feature, please verify if the 30-second listen_timeout is sufficient for all deployment scenarios, especially on slower systems or during high load.

Consider monitoring server startup times in various environments to ensure this timeout is adequate:

✅ Verification successful

30s listen_timeout is appropriate

The 30-second timeout provides a generous safety margin for server startup, which typically completes in a few seconds. The codebase shows a clean initialization sequence without heavy tasks, making this timeout sufficient even for slower systems or high-load scenarios.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check pm2 logs for startup duration patterns
# Note: This helps identify if 30s is enough time for the server to start

ssh root@<unraid-server> "pm2 logs unraid-api --lines 1000" | grep -E "Starting Nest Server|Nest Server is now listening" | awk '
  /Starting Nest Server/ {start=$1 " " $2}
  /Nest Server is now listening/ {
    end=$1 " " $2
    cmd="date -d\"" end "\" +%s.%N"
    cmd | getline end_ts
    close(cmd)
    cmd="date -d\"" start "\" +%s.%N"
    cmd | getline start_ts
    close(cmd)
    printf "Startup took %.2f seconds\n", end_ts - start_ts
  }'

Length of output: 510


Script:

#!/bin/bash
# Search for main.ts files and their content
fd main.ts --type f --exec cat {} \;

# Search for any startup timing or timeout related code
rg -i "startup|bootstrap|listen.*time|timeout" --type ts -A 2 -B 2

Length of output: 39523

api/scripts/deploy-dev.sh (1)

26-26: Robust build process implementation!

The script now correctly handles the build process with proper error checking and exit codes.

Also applies to: 29-34

@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL: https://preview.dl.unraid.net/unraid-api/pr/1023/dynamix.unraid.net.staging.plg

@pujitm pujitm requested review from elibosley and mdatelle January 13, 2025 13:48
elibosley
elibosley previously approved these changes Jan 13, 2025
Copy link
Member

@elibosley elibosley left a comment

Choose a reason for hiding this comment

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

LGTM - just add a comment to the process.send block and merge away!

@pujitm pujitm merged commit 4c0fa3d into main Jan 13, 2025
5 of 6 checks passed
@pujitm pujitm deleted the fix/dev-deploy branch January 13, 2025 15:55
@github-actions
Copy link
Contributor

This plugin has been deployed to Cloudflare R2 and is available for testing.
Download it at this URL: https://preview.dl.unraid.net/unraid-api/pr/1023/dynamix.unraid.net.staging.plg

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.

3 participants