Skip to content

Conversation

@maparent
Copy link
Collaborator

@maparent maparent commented Jun 20, 2025

This should allow people to use the task syncing functions through the Vercel endpoints.

Summary by CodeRabbit

  • New Features
    • Introduced new API endpoints for managing synchronization tasks, allowing users to propose, update, and query sync tasks with enhanced error handling and input validation.
    • Added support for retrieving synchronization information and updating task status via dedicated API routes.
  • Improvements
    • Enhanced response formatting and error handling for more consistent and informative API interactions.

Tested with

import requests
import openai
import supabase
url_base = "http://localhost:3000/api"
sync_r = requests.post(url_base+"/supabase/sync-task/fn1/1", json=dict(worker='maparent'))
print(sync_r.json(), sync_r.status_code)
sync_r2 = requests.get(url_base+"/supabase/sync-task/fn1/1")
print(sync_r2.json(), sync_r2.status_code)
sync_r3 = requests.post(url_base+"/supabase/sync-task/fn1/1/maparent", json="complete")
print(sync_r3.json(), sync_r3.status_code)

@linear
Copy link

linear bot commented Jun 20, 2025

@vercel
Copy link

vercel bot commented Jun 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
discourse-graph ✅ Ready (Inspect) Visit Preview 💬 Add feedback Jun 23, 2025 3:34pm

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

📝 Walkthrough

Walkthrough

Two new API routes are introduced for managing synchronization tasks via Supabase. The first route allows proposing and querying sync tasks by function and target, supporting GET, POST, and OPTIONS methods. The second route enables updating the sync task status for a specific function, target, and worker using a POST method, with input validation and error handling.

Changes

File(s) Change Summary
.../api/supabase/sync_task/[fn]/[target]/route.ts New API route for proposing/querying sync tasks; implements GET, POST, OPTIONS with validation and error handling.
.../api/supabase/sync_task/[fn]/[target]/[worker]/route.ts New API route for updating sync task status; implements POST with parameter extraction, validation, and error handling.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant API_Route
    participant Supabase

    Client->>API_Route: POST /sync_task/{fn}/{target} (propose task)
    API_Route->>Supabase: Call propose_sync_task RPC
    Supabase-->>API_Route: Response
    API_Route-->>Client: Normalized API response

    Client->>API_Route: GET /sync_task/{fn}/{target} (query task)
    API_Route->>Supabase: Query sync_info table
    Supabase-->>API_Route: Sync info record
    API_Route-->>Client: API response

    Client->>API_Route: POST /sync_task/{fn}/{target}/{worker} (update status)
    API_Route->>Supabase: Call end_sync_task RPC
    Supabase-->>API_Route: Response
    API_Route-->>Client: Success indicator
Loading

Possibly related PRs

Poem

In the warren where sync tasks hop,
New routes now help them start and stop.
With Supabase calls and careful checks,
Each worker’s status, no more wrecks!
Rabbits cheer as flows align—
Tasks in sync, and all is fine.
🐇✨


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.

❤️ 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.
    • 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 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 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 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.

@maparent
Copy link
Collaborator Author

@CodeRabbit review

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 20, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

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

🧹 Nitpick comments (4)
apps/website/app/api/supabase/sync_task/[fn]/[target]/route.ts (2)

38-47: Improve error message clarity.

The error message "Missing some worker" is unclear and could be more specific.

-          "Missing some worker",
+          "Worker field is required",

55-59: Clarify the null response handling logic.

The comment and logic handling null responses could benefit from more explanation about why this transformation is necessary.

Consider adding a more descriptive comment:

-    // next not happy about null as a response
+    // NextJS responses cannot handle null values, convert to boolean success indicator
apps/website/app/api/supabase/sync_task/[fn]/[target]/[worker]/route.ts (2)

19-24: Maintain consistency with error message format.

The error message format is inconsistent with the similar validation in the other route file. Consider using the original target value instead of targetN for clarity.

-        asPostgrestFailure(`${targetN} is not a number`, "type"),
+        asPostgrestFailure(`${target} is not a number`, "type"),

40-43: Clarify the 204 status code transformation.

The logic for transforming a 204 status to 200 with data: true could benefit from a comment explaining why this transformation is necessary.

Consider adding a comment:

+    // Transform 204 No Content to 200 OK with success indicator for API consistency
     if (response.status === 204) {
       response.data = true;
       response.status = 200;
     }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a0a6082 and acaacb6.

📒 Files selected for processing (2)
  • apps/website/app/api/supabase/sync_task/[fn]/[target]/[worker]/route.ts (1 hunks)
  • apps/website/app/api/supabase/sync_task/[fn]/[target]/route.ts (1 hunks)
🔇 Additional comments (4)
apps/website/app/api/supabase/sync_task/[fn]/[target]/route.ts (2)

17-20: LGTM! Clean default configuration setup.

The sync defaults are well-defined with reasonable timeout and task interval values.


68-88: LGTM! Well-implemented GET handler with proper validation.

The GET handler correctly validates the target parameter and uses maybeSingle() for querying a single record, which is appropriate for this use case.

apps/website/app/api/supabase/sync_task/[fn]/[target]/[worker]/route.ts (2)

25-32: LGTM! Robust enum validation using database types.

The task status validation properly uses the database-generated enum types, ensuring type safety and preventing invalid status values.


34-39: Verify the end_sync_task RPC function exists in the database.

Ensure that the end_sync_task stored procedure is properly defined in your Supabase database with the expected parameters.

#!/bin/bash
# Description: Search for references to end_sync_task RPC function in the codebase
# Expected: Find database migration or function definition files

rg -A 10 -B 5 "end_sync_task"

Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

Make sure to format with Prettier.

Also, have you tested these? If so, could you indicate this in the body of the PR or (preferably) a screenshot of the successful test.

@maparent
Copy link
Collaborator Author

maparent commented Jun 23, 2025

My vscode prettier config was non-operational, for some reason; fixed.

@maparent maparent force-pushed the ENG-490-sync-wrappers branch from 1d58982 to cd39dc1 Compare June 26, 2025 04:04
Copy link
Contributor

@mdroidian mdroidian left a comment

Choose a reason for hiding this comment

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

👍

@maparent maparent merged commit 691ef0d into main Jun 26, 2025
3 checks passed
@github-project-automation github-project-automation bot moved this to Done in General Jun 26, 2025
@maparent maparent deleted the ENG-490-sync-wrappers branch June 26, 2025 12:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants