Skip to content

Fix current worker deployment getter #1924

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

Merged
merged 2 commits into from
Apr 14, 2025
Merged

Conversation

nicktrn
Copy link
Collaborator

@nicktrn nicktrn commented Apr 14, 2025

We should only lock to V1 deployments when in the (legacy) shared queue consumer.

Summary by CodeRabbit

  • Refactor
    • Updated the worker deployment retrieval process by transitioning from simple string parameters to structured objects, enhancing flexibility and extensibility.
    • Improved consistency in handling tasks and scheduled workflows across the application.
    • Renamed a worker retrieval method to clearly denote its focus on managed deployments.

Copy link

changeset-bot bot commented Apr 14, 2025

⚠️ No Changeset found

Latest commit: 14436d8

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

coderabbitai bot commented Apr 14, 2025

Walkthrough

This pull request updates the way the findCurrentWorkerDeployment function is called across multiple components. Instead of passing a single string argument for the environment identifier, the argument is now wrapped in an object. In one case, an additional property (type: "V1") is provided. The function signature in the worker deployment module has been revised accordingly, and a renaming has been applied to a related worker retrieval function. Overall, the modifications standardize parameter passing without altering the core logic.

Changes

File(s) Change Summary
apps/webapp/app/.../TestPresenter.server.ts, apps/webapp/app/.../TestTaskPresenter.server.ts, apps/webapp/app/.../triggerScheduledTask.server.ts Updated calls to findCurrentWorkerDeployment to wrap the environment identifier in an object ({ environmentId: <id> }) instead of passing it as a plain string.
apps/webapp/app/.../marqs/sharedQueueConsumer.server.ts Modified call to findCurrentWorkerDeployment to include an additional property (type: "V1") with the environment identifier.
apps/webapp/app/.../workerDeployment.server.ts Changed the function signature of findCurrentWorkerDeployment to accept an object with environmentId, optional label, and optional type, and updated its internal logic accordingly.
internal-packages/run-engine/.../worker.ts Renamed getWorkerFromCurrentlyPromotedDeployment to getManagedWorkerFromCurrentlyPromotedDeployment, with corresponding updates in its usage.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant DeploymentFunc as findCurrentWorkerDeployment
    Caller->>DeploymentFunc: Call with { environmentId, label?, type? }
    alt type is provided
        DeploymentFunc->>DeploymentFunc: Check if deployment type matches
        alt Match found
            DeploymentFunc-->>Caller: Return current deployment
        else
            DeploymentFunc->>DeploymentFunc: Query latest deployment of specified type
            DeploymentFunc-->>Caller: Return queried deployment
        end
    else No type provided
        DeploymentFunc->>DeploymentFunc: Retrieve current deployment directly
        DeploymentFunc-->>Caller: Return current deployment
    end
Loading

Possibly related PRs

Suggested reviewers

  • ericallam

Poem

I'm a little rabbit, hopping with delight,
Code changes shining in the day and night.
Environment IDs now wrapped so neat,
With extra types making our calls complete.
A hop, a skip—improvements in our dance,
Coding with joy, each fix a prance! 🐇

Tip

⚡💬 Agentic Chat (Pro Plan, General Availability)
  • We're introducing multi-step agentic chat in review comments and issue comments, within and outside of PR's. This feature enhances review and issue discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments and add commits to existing pull requests.

📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4c607 and 14436d8.

📒 Files selected for processing (6)
  • apps/webapp/app/presenters/v3/TestPresenter.server.ts (1 hunks)
  • apps/webapp/app/presenters/v3/TestTaskPresenter.server.ts (1 hunks)
  • apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts (1 hunks)
  • apps/webapp/app/v3/models/workerDeployment.server.ts (6 hunks)
  • apps/webapp/app/v3/services/triggerScheduledTask.server.ts (1 hunks)
  • internal-packages/run-engine/src/engine/db/worker.ts (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
apps/webapp/app/v3/services/triggerScheduledTask.server.ts (1)
apps/webapp/app/v3/models/workerDeployment.server.ts (1)
  • findCurrentWorkerDeployment (67-151)
apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts (1)
apps/webapp/app/v3/models/workerDeployment.server.ts (1)
  • findCurrentWorkerDeployment (67-151)
apps/webapp/app/presenters/v3/TestPresenter.server.ts (1)
apps/webapp/app/v3/models/workerDeployment.server.ts (1)
  • findCurrentWorkerDeployment (67-151)
⏰ Context from checks skipped due to timeout of 90000ms (5)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - pnpm)
  • GitHub Check: e2e / 🧪 CLI v3 tests (windows-latest - npm)
  • GitHub Check: typecheck / typecheck
  • GitHub Check: units / 🧪 Unit Tests
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (14)
apps/webapp/app/presenters/v3/TestTaskPresenter.server.ts (1)

91-91: Parameter format updated to match the new function signature.

The call to findCurrentWorkerDeployment has been refactored to use an object parameter with environmentId property instead of passing the environment ID directly. This change aligns with the updated function signature in workerDeployment.server.ts and provides better extensibility when additional parameters are needed.

apps/webapp/app/v3/services/triggerScheduledTask.server.ts (1)

76-78: Standardized parameter passing using object structure.

The call to findCurrentWorkerDeployment has been updated to use an object with named parameters instead of a positional argument. This change improves code readability and aligns with the updated function signature that now accepts an object with environmentId, label, and optional type parameters.

apps/webapp/app/presenters/v3/TestPresenter.server.ts (1)

59-59: Updated to use object parameter pattern.

The function call now uses a named parameter object structure, which aligns with similar changes across the codebase and matches the updated function signature in workerDeployment.server.ts. This change makes the code more explicit and maintainable.

apps/webapp/app/v3/marqs/sharedQueueConsumer.server.ts (1)

615-618: Key implementation of PR objective: Added V1 type constraint for legacy consumer.

This change is central to the PR's objective. The function call now not only uses the object parameter pattern with environmentId but also explicitly adds a type: "V1" parameter. This ensures that the legacy shared queue consumer only locks to V1 deployments, as specified in the PR description.

The updated implementation follows the enhanced function signature which now supports filtering deployments by type, allowing more granular control over which deployments are used in different contexts.

internal-packages/run-engine/src/engine/db/worker.ts (2)

103-103: Function name updated to better reflect its purpose

The function name has been changed from getWorkerFromCurrentlyPromotedDeployment to getManagedWorkerFromCurrentlyPromotedDeployment, which more accurately describes what the function does - specifically retrieving a managed worker from the current deployment.


263-263: Renamed function to be more descriptive

The function has been renamed from getWorkerFromCurrentlyPromotedDeployment to getManagedWorkerFromCurrentlyPromotedDeployment to better reflect its purpose - specifically handling managed workers. This makes the code more self-documenting and improves maintainability.

apps/webapp/app/v3/models/workerDeployment.server.ts (8)

2-2: Added required type import

Added WorkerDeploymentType to imports which is now used as a parameter type in the updated function signature.


59-75: Improved function signature with object parameters

The function signature has been updated to use a more flexible object parameter pattern instead of individual parameters. This change:

  1. Makes the function more maintainable as new parameters can be added without breaking existing calls
  2. Improves readability with named parameters
  3. Adds the new optional type parameter to filter deployments by type

The JSDoc comments have also been updated to document all parameters clearly.


109-111: Added early return for default behavior

This new conditional provides a clear path for the original behavior when no type is specified, maintaining backward compatibility.


113-115: Added type matching check

This conditional ensures that when a specific deployment type is requested and the current deployment matches that type, we return it immediately without additional queries.


117-122: Added fallback for type-specific deployments

If the current deployment doesn't match the requested type, the function now queries for the latest deployment of the specified type. This implements the core functionality needed to support the PR's purpose of only locking to V1 deployments in specific contexts.


146-150: Updated return handling for type-specific deployments

The function now properly handles the case where no deployment of the requested type exists, returning undefined in that case, or the found deployment otherwise.


181-185: Updated function call to use new parameter structure

Function call to findCurrentWorkerDeployment has been updated to use the new object parameter pattern, maintaining the same functionality while explicitly requesting deployment type "UNMANAGED".


206-209: Updated function call to use new parameter structure

Function call to findCurrentWorkerDeployment has been updated to use the new object parameter pattern, maintaining the same functionality.

✨ Finishing Touches
  • 📝 Generate Docstrings

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.
    • 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@nicktrn nicktrn merged commit 1816115 into main Apr 14, 2025
18 checks passed
@nicktrn nicktrn deleted the fix/get-current-worker-deployment branch April 14, 2025 13:55
matt-aitken pushed a commit that referenced this pull request Apr 16, 2025
* only return last v1 deployment in the shared queue consumer

* be explicit about only returning managed deployments
matt-aitken added a commit that referenced this pull request Apr 17, 2025
* WIP on secret env vars

* Editing individual env var values is working

* Sort the env vars by the key

* Deleting values

* Allowing setting secret env vars

* Added medium switch style

* Many style changes to the env var form

* “Copy text” -> “Copy”

* Draw a divider between hidden buttons

* Env var tweaks

* Don’t show Dev:you anymore

* Grouping the same env var keys together

* Styles improved

* Improved styling of edit panel

* Fix bun detection, dev flushing, and init command (#1914)

* update nypm to support text-based bun lockfiles

* add nypm changeset

* handle dev flushing failures gracefully

* fix path normalization for init.ts

* add changesets

* chore: remove pre.json after exiting pre mode

* init command to install v4-beta packages

* Revert "chore: remove pre.json after exiting pre mode"

This reverts commit f5694fd.

* make init default to cli version for all packages

* Release 4.0.0-v4-beta.1 (#1916)

* chore: Update version for release (v4-beta)

* Release 4.0.0-v4-beta.1

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com>

* Both run engines will only lock to versions they can handle (#1922)

* run engine v1 will only lock to v1 deployments

* run engine v2 will only lock to managed v2 deployments

* test: create background worker and deployment with correct engine version

* Add links to and from deployments (#1921)

* link from deployments tasks to filtered runs view

* jump to deployment

* don't add version links for dev (yet)

* Fix current worker deployment getter (#1924)

* only return last v1 deployment in the shared queue consumer

* be explicit about only returning managed deployments

* Add a docs page for the human-in-the-loop example project (#1919)

* Add a docs page for the human-in-the-loop example project

* Order guides, example projects and example tasks alphabetically in the docs list

* Managed run controller revamp (#1927)

* update nypm to support text-based bun lockfiles

* fix retry spans

* only download debug logs if admin

* add nypm changeset

* pull out env override logic

* use runner env gather helper

* handle dev flushing failures gracefully

* fix path normalization for init.ts

* add logger

* add execution heartbeat service

* add snapshot poller service

* fix poller

* add changesets

* create socket in constructor

* enable strictPropertyInitialization

* deprecate dequeue from version

* start is not async

* dependency injection in prep for tests

* add warm start count to all controller logs

* add restore count

* pull out run execution logic

* temp disable pre

* add a controller log when starting an execution

* refactor execution and squash some bugs

* cleanup completed docker containers by default

* execution fixes and logging improvements

* don't throw afet abort cleanup

* poller should use private interval

* rename heartbeat service file

* rename HeartbeatService to IntervalService

* restore old heartbeat service but deprecate it

* use the new interval service everywhere

* Revert "temp disable pre"

This reverts commit e03f417.

* add changeset

* replace all run engine find uniques with find first

* Release 4.0.0-v4-beta.2 (#1928)

* chore: Update version for release (v4-beta)

* Release 4.0.0-v4-beta.2

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com>

* Remove batch ID carryover for non-batch waits (#1930)

* add failing test case

* do not carry over previous batch id when blocking with waitpoint

* delete irrelevant test

* Delete project (#1913)

* Delete project

- Don’t schedule tasks if the project is deleted
- Delete queues from the master queues
- Add the old delete project UI back in

* Mark the project as deleted last

* Fix for overriding local variable

* Added a todo for deleting env queues

* Remove todo

* Improve usage flushing (#1931)

* add flush to global usage api

* enable controller debug logs

* initialize usage manager after env overrides

* add previous run id to more debug logs

* add changeset

* For secret env vars, don’t return the value

* Added a new env var repository function for getting secrets with redactions

* Test task for env vars

* Delete heartbeat file, merge mess up

---------

Co-authored-by: nicktrn <55853254+nicktrn@users.noreply.github.com>
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Saadi Myftija <saadi.myftija@gmail.com>
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