Skip to content

Conversation

Ishankoradia
Copy link
Contributor

@Ishankoradia Ishankoradia commented Aug 12, 2025

Summary by CodeRabbit

  • New Features
    • Deployment scheduling now includes a top-level paused state: inactive deployments are sent as paused while schedules are retained; active deployments remain unpaused.
  • Tests
    • Updated tests to verify the new paused behavior when toggling deployment active/inactive states.

@Ishankoradia Ishankoradia requested a review from fatchat August 12, 2025 07:22
Copy link

coderabbitai bot commented Aug 12, 2025

Walkthrough

Adds a top-level paused field to the Prefect deployment PATCH payload in set_deployment_schedule; paused is true when status == "inactive". The schedule.active flag remains derived from status. No public API/signature changes.

Changes

Cohort / File(s) Summary
Deployment scheduling patch update
proxy/service.py
The PATCH payload sent to Prefect now includes "paused": status == "inactive" alongside "schedules": [schedule]; schedule.active still derived from status. Patch call reformatted; no public signature changes.
Tests updated for paused field
tests/test_service.py
Test expectations updated to assert the PATCH payload includes the top-level paused boolean (false when activating, true when deactivating) in addition to the existing schedules structure.

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Service as Service.set_deployment_schedule
  participant Prefect as Prefect API

  Client->>Service: set_deployment_schedule(status, schedule)
  Service->>Prefect: PATCH /deployments/{id}\n{ schedules: [schedule], paused: (status == "inactive") }
  Prefect-->>Service: 200 OK
  Service-->>Client: None
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15 minutes

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch bug/schedule-active-inactive

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.
    • 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.
  • 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 the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

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

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • 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

@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

🧹 Nitpick comments (1)
proxy/service.py (1)

1167-1171: Add minimal tests to prevent regressions

Recommend tests for:

  • Pause/resume without schedules (should still PATCH paused).
  • Multiple schedules preserved and toggled.
  • Invalid status raises ValueError.

I can scaffold tests or open an issue with acceptance criteria.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3d16f41 and 4ab71ad.

📒 Files selected for processing (1)
  • proxy/service.py (1 hunks)
🔇 Additional comments (2)
proxy/service.py (2)

1168-1171: Including paused in the patch aligns with the PR goal

Adding "paused": status == "inactive" to the deployment patch correctly ties pause/resume to schedule activation/deactivation as requested.


1168-1171: Prefect API paused field confirmed
Verified against the official Prefect 2 REST API (PATCH /api/deployments/{id})—the JSON body uses a boolean paused field to pause (true) or resume (false) a deployment. No changes needed.

• Location: proxy/service.py, lines 1168–1171

Comment on lines +1167 to +1171

prefect_patch(
f"deployments/{deployment_id}",
{"schedules": [schedule], "paused": status == "inactive"},
)
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Always patch paused (even when there are no schedules) and update all schedules, not just the first

Current flow skips patching entirely if the deployment has zero schedules, so pause/resume never takes effect in that case. Also, by patching with only the first schedule, you’ll inadvertently drop any additional schedules on the deployment.

Refactor to:

  • Validate status ("active" | "inactive").
  • Always patch "paused", regardless of schedules presence.
  • Update the active flag on all schedules and preserve the entire schedules list.

Apply this diff:

 def set_deployment_schedule(deployment_id: str, status: str) -> None:
     """Set deployment schedule to active or inactive"""
     # both the apis return null below
     deployment = prefect_get(f"deployments/{deployment_id}")
-    if len(deployment["schedules"]) > 0:
-        schedule = deployment["schedules"][0]
-        del schedule["id"]
-        del schedule["created"]
-        del schedule["updated"]
-        del schedule["deployment_id"]
-        schedule["active"] = status == "active"
-
-        prefect_patch(
-            f"deployments/{deployment_id}",
-            {"schedules": [schedule], "paused": status == "inactive"},
-        )
+    allowed = {"active", "inactive"}
+    if status not in allowed:
+        raise ValueError(f"status must be one of {allowed}")
+
+    paused = status == "inactive"
+    payload = {"paused": paused}
+
+    if len(deployment["schedules"]) > 0:
+        new_schedules = []
+        for s in deployment["schedules"]:
+            # Drop server-managed fields before patching
+            s_clean = {
+                k: v
+                for k, v in s.items()
+                if k not in {"id", "created", "updated", "deployment_id"}
+            }
+            s_clean["active"] = not paused
+            new_schedules.append(s_clean)
+        payload["schedules"] = new_schedules
+
+    prefect_patch(f"deployments/{deployment_id}", payload)
 
     return None
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
prefect_patch(
f"deployments/{deployment_id}",
{"schedules": [schedule], "paused": status == "inactive"},
)
def set_deployment_schedule(deployment_id: str, status: str) -> None:
"""Set deployment schedule to active or inactive"""
# both the apis return null below
deployment = prefect_get(f"deployments/{deployment_id}")
allowed = {"active", "inactive"}
if status not in allowed:
raise ValueError(f"status must be one of {allowed}")
paused = status == "inactive"
payload = {"paused": paused}
if len(deployment["schedules"]) > 0:
new_schedules = []
for s in deployment["schedules"]:
# Drop server-managed fields before patching
s_clean = {
k: v
for k, v in s.items()
if k not in {"id", "created", "updated", "deployment_id"}
}
s_clean["active"] = not paused
new_schedules.append(s_clean)
payload["schedules"] = new_schedules
prefect_patch(f"deployments/{deployment_id}", payload)
return None

@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 76.90%. Comparing base (3d16f41) to head (2f46475).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #214   +/-   ##
=======================================
  Coverage   76.90%   76.90%           
=======================================
  Files           5        5           
  Lines        1429     1429           
=======================================
  Hits         1099     1099           
  Misses        330      330           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Ishankoradia Ishankoradia changed the title we also need pause or resume the deployment while activating or deactivating the schedules pause or resume the deployment while activating or deactivating the schedules Aug 12, 2025
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)
tests/test_service.py (1)

1501-1523: Consider parametrizing activation/deactivation tests and add invalid-status coverage

Both tests share identical scaffolding and only vary expected paused/active values. Parametrizing would DRY the test logic and make future changes less error-prone. Also consider adding a negative test for invalid status values to lock in error handling behavior.

Would you like me to provide a pytest-parametrized version covering ("active", paused=False, active=True) and ("inactive", paused=True, active=False), plus an invalid status case?

Also applies to: 1525-1547

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 4ab71ad and 2f46475.

⛔ Files ignored due to path filters (1)
  • uv.lock is excluded by !**/*.lock
📒 Files selected for processing (1)
  • tests/test_service.py (2 hunks)
🔇 Additional comments (2)
tests/test_service.py (2)

1521-1522: Asserted paused=False on activation — correct and aligned with PR objective

Including the top-level "paused": False when status is "active" matches Prefect’s deployment pause/resume semantics and ensures resuming occurs alongside schedule activation.


1545-1546: Asserted paused=True on deactivation — correct mapping

Including "paused": True when status is "inactive" correctly pauses the deployment in tandem with disabling the schedule.

@Ishankoradia Ishankoradia merged commit 6e572b0 into main Aug 13, 2025
3 checks passed
@Ishankoradia Ishankoradia deleted the bug/schedule-active-inactive branch August 13, 2025 12:07
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