villebro commented on code in PR #36368:
URL: https://github.com/apache/superset/pull/36368#discussion_r2672990819


##########
docs/developer_portal/async-tasks.md:
##########
@@ -0,0 +1,460 @@
+---
+title: Async Task Framework
+sidebar_label: Async Tasks
+sidebar_position: 5
+---
+
+
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements.  See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership.  The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied.  See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+
+# Global Async Task Framework (GATF)
+
+The Global Async Task Framework provides a unified way to manage asynchronous 
tasks in Apache Superset. It handles task registration, execution, status 
tracking, cancellation, and deduplication.
+
+## Overview
+
+GATF uses the **ambient context pattern** where tasks access their execution 
context via `get_context()` instead of receiving it as a parameter. This 
results in clean, business-focused function signatures without framework 
boilerplate.
+
+### Key Features
+
+- **Clean Signatures**: Task functions contain only business args
+- **Ambient Context**: Access context via `get_context()` - no parameter 
passing
+- **Dual Execution**: Synchronous (for testing) and asynchronous (via Celery)
+- **Optional Deduplication**: Use idempotency keys to prevent duplicate 
execution
+- **Progressive Updates**: Update payload and check cancellation during 
execution
+- **Type Safety**: Full type hints with ParamSpec support
+
+## Quick Start
+
+### Define a Task
+
+```python
+import requests
+from superset_core.api.types import async_task, get_context
+
+@async_task()
+def fetch_data(api_url: str) -> None:
+    """
+    Example task that fetches data from an external API.
+
+    Features:
+    - Automatic cancellation check before execution
+    - Simple cleanup handler
+    - Cancellation checking during execution
+    """
+    ctx = get_context()
+
+    # Cleanup runs automatically on success, failure, or cancellation
+    @ctx.on_cleanup
+    def cleanup():
+        logger.info("Data fetch completed")
+
+    # No initial check needed - framework checks before execution!
+    # Fetch data with timeout (prevents hanging)
+    response = requests.get(api_url, timeout=60)
+    data = response.json()
+
+    # Check before next operation
+    if ctx.is_cancelled():

Review Comment:
   Introducing an event based system is a big architectural change that's 
outside the scope of this task. It's not clear from the documentation here, but 
the proposed design here is backwards compatible with the current SQL Lab Query 
pattern where cancellation is periodically checked during execution. But let's 
discuss in the Extensions working group today.



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