villebro opened a new pull request, #44032:
URL: https://github.com/apache/superset/pull/44032

   ### SUMMARY
   
   Child PR 5 of the [SQL execution on GTF 
epic](https://github.com/apache/superset/pull/43928) (umbrella 
`villebro/sqllab-gtf`).
   
   Adds a low-latency realtime path for async SQL Lab queries — they settle via 
the GTF `task.status` websocket push instead of waiting up to 2s for the next 
`/query/updated_since` poll. The poll is unchanged and remains the correctness 
backstop; the websocket is a pure accelerator. Progress still rides the poll 
(`task.status` is terminal-only).
   
   **Generalized per-tab delivery.** Chart-data's per-tab consumer subscription 
policy (ref-count the browser tabs watching a task and route its terminal 
`task.status` fanout to exactly those tabs) is extracted into a reusable 
`PerTabConsumerPolicy` in `superset/tasks/subscription.py`. 
`ChartQueryConsumerPolicy` becomes a thin subclass (chart-data behavior 
unchanged), and the SQL Lab task `run_sql_lab_query` registers the shared 
policy so its completion is delivered only to the originating tab. Any future 
task type gets tab-isolated delivery for free.
   
   **Task descriptor in the execute 202.** `ExecuteSqlCommand.submit_async` 
captures a pre-schedule status cursor (the recovery watermark) plus the 
scheduled task's UUID and returns an `async_job` `{task_id, cursor, tab_id?}`; 
the `/execute/` endpoint surfaces it in the 202 (`QueryExecutionResponseSchema` 
extended). The cursor is captured before the task is created so a completion 
can't slip in ahead of the client's waiter.
   
   **Frontend.** `runQuery` advertises the per-tab id (`getTabId`) on execute 
so the backend can route the push back, and stores the 202's 
`async_job.task_id` on the query (new `taskId` field + `SET_QUERY_TASK_ID`). 
`QueryAutoRefresh` subscribes to the generic `task.status` realtime topic and 
triggers an immediate refresh when a currently-running query's tracked task 
reaches a terminal status; `task.status` messages for untracked task ids (e.g. 
chart-data) are ignored. The 2s poll is untouched as the backstop.
   
   ### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
   
   N/A — behavior-preserving latency improvement. With `WEBSOCKET_ENABLE` on, 
an async query settles on its terminal `task.status` push; with it off (or a 
missed push), the existing poll still settles it.
   
   ### TESTING INSTRUCTIONS
   
   Backend: `pytest tests/unit_tests/tasks/test_subscription.py 
tests/unit_tests/commands/sql_lab/test_execute.py 
tests/unit_tests/daos/test_tasks.py`. Frontend: `npm run test -- 
src/SqlLab/components/QueryAutoRefresh/QueryAutoRefresh.test.tsx 
src/SqlLab/actions/sqlLab.test.ts`. End-to-end (dev instance with 
`GLOBAL_TASK_FRAMEWORK` + `WEBSOCKET_ENABLE`): run an async query and confirm 
it settles promptly via the websocket; disable the websocket and confirm it 
still settles via the 2s poll.
   
   ### ADDITIONAL INFORMATION
   
   - [ ] Has associated issue:
   - [x] Required feature flags: `GLOBAL_TASK_FRAMEWORK` (async SQL Lab 
execution); `WEBSOCKET_ENABLE` + `WEBSOCKET_URL` for the realtime push (poll 
fallback otherwise)
   - [x] Changes UI
   - [ ] Includes DB Migration
   - [x] Introduces new feature or API
   - [ ] Removes existing feature or API
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to