Replies: 1 comment
-
|
SSE streaming mode is the recommended approach for executing and monitoring long-running or resource-intensive workflows in Dify. Blocking mode is subject to a 100-second Cloudflare timeout (sometimes less in practice), which can interrupt or fail lengthy tasks, while streaming mode delivers real-time progress and results via structured SSE events like workflow_started, node_finished, and workflow_finished API spec, discussion, issue. Best practices for SSE streaming in Dify:
For JSONDecodeError or infinite polling issues, ensure your client is set up to parse SSE streams (not plain JSON) and use streaming mode for long-duration tasks. Let me know if you need more details on any specific configuration or workflow design! To reply, just mention @dosu. How did I do? Good | Irrelevant | Incorrect | Verbose | Hallucination | Report 🐛 | Other |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Self Checks
1. Is this request related to a challenge you're experiencing? Tell me about your story.
Dear Dify Support Team,
I hope this message finds you well.
I am currently working with the Dify API to manage workflows, and I’ve encountered some challenges regarding the best approach to execute and monitor long-running tasks efficiently. I would like to confirm whether my current setup is optimal, or if there is a better recommended approach.
Current Setup and Issues:
Streaming Mode & Polling:
I have been using response_mode="streaming" to execute workflows, and I attempted to use polling to check the status via GET requests.
However, I encountered issues because the responses from Dify are in Server-Sent Events (SSE) format, which my current code does not properly parse, leading to JSONDecodeError.
Polling and Timeouts:
In the polling setup, Dify API returns a status of unknown when querying the task status, which results in infinite polling without progressing to a successful completion.
The standard 30-second timeout and 120-poll attempts were not sufficient to handle long-running tasks.
Architecture Change:
To resolve these issues, I transitioned to SSE streaming mode, where I keep a persistent connection open to read events in real-time.
I use the following approach:
Start the workflow via POST with streaming enabled.
Continuously listen for events like workflow_started, node_finished, and workflow_finished.
Extract the workflow results and progress as they come in through SSE.
Current Concerns:
While the new streaming-based approach seems to be working, I am not entirely sure if I’ve selected the most appropriate mode for my use case.
Specifically, I would like to confirm whether SSE streaming is the recommended approach for tasks that require long-duration processing (e.g., resume screening tasks).
Are there any specific configurations or additional best practices I should follow when using SSE mode, especially when dealing with large or resource-intensive tasks?
I would greatly appreciate your insights and recommendations on the best practices for using Dify API in such scenarios.
Thank you in advance for your support.
2. Additional context or comments
No response
Beta Was this translation helpful? Give feedback.
All reactions