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

feat: Create a async execute trigger flow #39009

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

hetunandu
Copy link
Member

@hetunandu hetunandu commented Feb 4, 2025

Description

Creates the promise flow for executing a trigger by converting it from a saga to an async function

This is still unstable and should not be used unless you know what you are doing

Fixes #38941

Automation

/ok-to-test tags="@tag.Sanity"

🔍 Cypress test results

Tip

🟢 🟢 🟢 All cypress tests have passed! 🎉 🎉 🎉
Workflow run: https://github.com/appsmithorg/appsmith/actions/runs/13132868310
Commit: e3a7b33
Cypress dashboard.
Tags: @tag.Sanity
Spec:


Tue, 04 Feb 2025 10:38:35 UTC

Communication

Should the DevRel and Marketing teams inform users about this change?

  • Yes
  • No

Summary by CodeRabbit

  • New Features

    • Introduced enhanced dynamic trigger execution, enabling smoother, more reliable asynchronous actions.
    • Added a background process that tracks performance metrics for improved responsiveness.
  • Refactor

    • Upgraded type safety and error handling across action evaluation flows for a more robust user experience.

Copy link
Contributor

coderabbitai bot commented Feb 4, 2025

Walkthrough

This PR implements several type safety improvements and introduces new asynchronous functionalities across the codebase. In the sagas, the return type for executeAppAction is updated to a Generator and a new saga for evaluating action selector fields is added. The constants file now includes a new enum and improved interface typing. Additionally, a new request method is added to the worker utility for structured worker communication with telemetry, and an async function is introduced to execute dynamic triggers.

Changes

File(s) Change Summary
app/client/src/ce/sagas/ActionExecutionSagas.ts
app/client/src/sagas/EvaluationsSaga.ts
Updated generator function return type in executeAppAction, removed preceding comments; added new saga evaluateActionSelectorFieldSaga for evaluating action selectors; updated callbackData parameter type to Array<unknown>.
app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx Added new enum TriggerKind and updated the callbackData type in ExecuteTriggerPayload from Array<any> to Array<unknown>.
app/client/src/utils/WorkerUtil.ts
app/client/src/workers/Evaluation/asyncWorkerActions.ts
Introduced a new request method in GracefulWorkerService for handling worker requests with telemetry; added new async function UNSTABLE_executeDynamicTrigger for executing dynamic triggers asynchronously.

Sequence Diagram(s)

sequenceDiagram
    participant W as Widget
    participant D as UNSTABLE_executeDynamicTrigger
    participant RU as GracefulWorkerService.request
    participant Worker as Worker Thread

    W->>D: Trigger dynamic execution
    D->>RU: Call request(method, data)
    RU->>Worker: Send request with evaluation payload
    Worker-->>RU: Return response & telemetry
    RU-->>D: Provide response
    D-->>W: Resolve promise with result
Loading
sequenceDiagram
    participant A as Action Dispatcher
    participant ES as evaluateActionSelectorFieldSaga
    participant EW as evalWorker

    A->>ES: Dispatch action with payload (id, type, value)
    ES->>EW: Evaluate expression in `value`
    EW-->>ES: Return evaluation result and lint errors
    ES->>ES: Dispatch update with the evaluated result
Loading

Assessment against linked issues

Objective Addressed Explanation
Allow async execution of dynamic triggers for widgets (#38941)

Suggested labels

JS Evaluation, Integrations Product, Integrations Pod General, Workflows Pod, Workflows Product, ok-to-test

Suggested reviewers

  • vsvamsi1
  • rajatagrawal
  • ApekshaBhosale
  • sharat87

Poem

In the realm of code where changes bloom,
New types rise dispelling former gloom.
Sagas dance and async triggers chime,
Workers whisper metrics in perfect time.
A code symphony that lightens the load,
A joyful tune on our development road!
🚀✨

Tip

🌐 Web search-backed reviews and chat
  • We have enabled web search-based reviews and chat for all users. This feature allows CodeRabbit to access the latest documentation and information on the web.
  • You can disable this feature by setting web_search: false in the knowledge_base settings.
  • Please share any feedback in the Discord discussion.
✨ Finishing Touches
  • 📝 Generate Docstrings (Beta)

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 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.

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.

@hetunandu hetunandu added the ok-to-test Required label for CI label Feb 4, 2025
@github-actions github-actions bot added AI All tasks related to AI All Widgets Issues related to all widgets IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Integrations Product Issues related to a specific integration JS Binding All issues related to the JS Binding experience Query & JS Pod Issues related to the query & JS Pod Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets Enhancement New feature or request labels Feb 4, 2025
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 (2)
app/client/src/utils/WorkerUtil.ts (1)

249-346: LGTM! Comprehensive worker request implementation with telemetry.

The implementation includes:

  • Proper error handling
  • Performance tracking
  • Resource cleanup

However, consider adding a timeout mechanism for requests.

Consider adding a timeout parameter with a default value:

-*request(method: string, data = {}): any {
+*request(method: string, data = {}, timeoutMs = 30000): any {
   yield this.ready(true);
+  const timeoutChannel = channel();
+  setTimeout(() => {
+    timeoutChannel.put(new Error('Request timeout'));
+    timeoutChannel.close();
+  }, timeoutMs);
🧰 Tools
🪛 Biome (1.9.4)

[error] 332-333: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

app/client/src/sagas/EvaluationsSaga.ts (1)

891-937: Consider improving error handling and typing in the new saga.

The saga implementation could benefit from:

  1. Stronger typing for the action parameter instead of any
  2. More structured error handling with specific error types

Consider this improvement:

-export function* evaluateActionSelectorFieldSaga(action: any) {
+interface ActionSelectorFieldPayload {
+  id: string;
+  type: string;
+  value: string;
+}
+
+export function* evaluateActionSelectorFieldSaga(
+  action: ReduxAction<ActionSelectorFieldPayload>
+) {
-    } catch (e) {
+    } catch (e: unknown) {
+      const error = e as Error;
       log.error(e);
-      Sentry.captureException(e);
+      Sentry.captureException(error);
     }
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 259cdb4 and e3a7b33.

📒 Files selected for processing (5)
  • app/client/src/ce/sagas/ActionExecution/ActionExecutionSagas.ts (1 hunks)
  • app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx (2 hunks)
  • app/client/src/sagas/EvaluationsSaga.ts (2 hunks)
  • app/client/src/utils/WorkerUtil.ts (1 hunks)
  • app/client/src/workers/Evaluation/asyncWorkerActions.ts (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: perform-test / client-build / client-build
  • GitHub Check: perform-test / server-build / server-unit-tests
  • GitHub Check: perform-test / rts-build / build
  • GitHub Check: client-unit-tests / client-unit-tests
  • GitHub Check: client-lint / client-lint
  • GitHub Check: client-prettier / prettier-check
  • GitHub Check: client-check-cyclic-deps / check-cyclic-dependencies
  • GitHub Check: client-build / client-build
🔇 Additional comments (5)
app/client/src/workers/Evaluation/asyncWorkerActions.ts (1)

8-27: LGTM! Well-structured async function implementation.

The function is properly marked as unstable and follows a clear flow for trigger execution.

Since this is marked as unstable, verify all usages to ensure proper error handling:

✅ Verification successful

Final Verification:
The shell script output confirms that the only reference to UNSTABLE_executeDynamicTrigger is its own definition. No external usages were found, so the error handling via runSaga appears to be appropriately scoped.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for all usages of the unstable function
rg "UNSTABLE_executeDynamicTrigger"

Length of output: 170

app/client/src/ce/sagas/ActionExecution/ActionExecutionSagas.ts (1)

142-142: Type safety improvement: Changed return type from any to Generator.

Good improvement in type safety by explicitly declaring the Generator return type.

app/client/src/constants/AppsmithActionConstants/ActionConstants.tsx (2)

30-33: LGTM! Clear enum definition for trigger kinds.

The enum values are well-defined and self-documenting.


38-38: Type safety improvement: Changed Array to Array.

Good improvement in type safety by using unknown instead of any.

app/client/src/sagas/EvaluationsSaga.ts (1)

344-344: Great type safety improvement!

Replacing Array<any> with Array<unknown> enhances type safety by requiring explicit type checking.

@hetunandu hetunandu enabled auto-merge (squash) February 4, 2025 10:06
@hetunandu hetunandu merged commit 3bbdcbc into release Feb 4, 2025
47 checks passed
@hetunandu hetunandu deleted the feat/async-execute-action branch February 4, 2025 10:38
github-actions bot pushed a commit to Zeral-Zhang/appsmith that referenced this pull request Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
AI All tasks related to AI All Widgets Issues related to all widgets Enhancement New feature or request IDE Navigation Issues/feature requests related to IDE navigation, and context switching IDE Pod Issues that new developers face while exploring the IDE IDE Product Issues related to the IDE Product Integrations Product Issues related to a specific integration JS Binding All issues related to the JS Binding experience ok-to-test Required label for CI Query & JS Pod Issues related to the query & JS Pod Task A simple Todo Widgets & Accelerators Pod Issues related to widgets & Accelerators Widgets Product This label groups issues related to widgets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Allow for a async execute action functionality for widgets
2 participants