Async Task State Machine Pattern

•
777
•

Implements a standardized asynchronous state machine pattern for long-running API tasks to prevent gateway timeouts and system instability.

This skill provides a robust architectural blueprint for transitioning synchronous, time-consuming operations into resilient asynchronous workflows. It specifically targets tasks exceeding 10 seconds—such as batch data processing, full table scans, or remote API aggregations—by utilizing a trigger/status polling model. By enforcing these state machine standards, developers can eliminate common production issues like 504 gateway timeouts, duplicate execution from user retries, and memory leaks caused by unbounded state caches, while ensuring that critical security and tenant contexts are correctly propagated to background worker threads.

主要功能

01Standardized triggerAsync() and getStatus() state machine architecture
02Context propagation templates for TenantContext and SecurityContext in child threads
03Automatic eviction strategies (TTL/LRU) to prevent memory leaks in state caches
04Concurrency controls to block duplicate execution of identical tasks
05Integrated frontend UX specifications for progress tracking and button states
06777 GitHub stars

使用场景

01Building progress-aware UI components for background data processing
02Refactoring synchronous APIs that suffer from 504 Gateway Timeout errors
03Managing batch data imports or multi-tenant data aggregations