利用 AI 大模型和自动化工作流,根据主题或关键词一键生成高清短视频。Generate HD short videos from a topic or keyword with an automated AI workflow.
Python ai-video-generatorcontent-creationffmpeginstagram-reelsllmpythonshort-videosubtitlestext-to-speechtiktokvideo-automationvideo-workflowworkflow-automationyoutube-shorts
fix(task): keep tasks with invalid state (#1663)
Ziyang Guo9e7d8b7efa6b
diff --git a/app/services/task.py b/app/services/task.pyindex 6e2545a4..7a45dbb4 100644--- a/app/services/task.py+++ b/app/services/task.py@@ -123,7 +123,13 @@ def is_task_busy(task: dict | None) -> bool:try:state = int(state)except (TypeError, ValueError):- pass+ # The function's own docstring promises to treat unparseable+ # states as busy, so the delete API keeps a task that we+ # cannot reason about. Returning False here would let+ # delete_video() cancel a task that is still running or+ # cross-posting whenever an older Redis snapshot or a+ # legacy call site stored the state as a string.+ return True# 视频生成和跨平台发布都可能继续读取任务目录。统一视为忙碌状态,# 可以避免 API 与 WebUI 分别维护规则后出现一个允许删除、另一个禁止diff --git a/test/services/test_is_task_busy_string_state.py b/test/services/test_is_task_busy_string_state.pynew file mode 100644index 00000000..e649c62c--- /dev/null+++ b/test/services/test_is_task_busy_string_state.py@@ -0,0 +1,71 @@+import unittest+import sys+from pathlib import Path++# add project root to python path+sys.path.insert(0, str(Path(__file__).parent.parent.parent))++from app.services import task as tm+++class TestIsTaskBusyDefensiveDefault(unittest.TestCase):+ """is_task_busy() must keep tasks whose state is unparseable."""++ def setUp(self):+ # The registry is process-wide; clear it so cross-post futures+ # left behind by earlier tests cannot affect the assertions.+ with tm._cross_post_registry_lock:+ tm._cross_post_futures.clear()++ def tearDown(self):+ with tm._cross_post_registry_lock:+ tm._cross_post_futures.clear()++ def test_string_state_is_treated_as_busy(self):+ # Older Redis snapshots can surface the state as a string. The+ # delete endpoint must not be allowed to cancel a task whose+ # state cannot be parsed.+ self.assertTrue(tm.is_task_busy({"state": "processing"}))+ self.assertTrue(tm.is_task_busy({"state": "4"}))+ self.assertTrue(tm.is_task_busy({"state": "PROCESSING"}))++ def test_none_state_is_treated_as_busy(self):+ # A missing or None state still implies a task we cannot reason+ # about, so the conservative default must apply.+ self.assertTrue(tm.is_task_busy({"state": None}))+ self.assertTrue(tm.is_task_busy({"state": "not-an-int"}))++ def test_string_state_with_idle_cross_post_still_busy(self):+ # The previous code path returned False here, which let the+ # delete API silently cancel in-flight tasks.+ self.assertTrue(+ tm.is_task_busy(+ {+ "state": "processing",+ "cross_post_state": tm.const.CROSS_POST_STATE_COMPLETE,+ }+ )+ )++ def test_integer_processing_state_remains_busy(self):+ # Existing happy path stays unchanged.+ self.assertTrue(tm.is_task_busy({"state": tm.const.TASK_STATE_PROCESSING}))++ def test_integer_complete_with_idle_cross_post_remains_idle(self):+ # Existing happy path stays unchanged.+ self.assertFalse(+ tm.is_task_busy(+ {+ "state": tm.const.TASK_STATE_COMPLETE,+ "cross_post_state": tm.const.CROSS_POST_STATE_COMPLETE,+ }+ )+ )++ def test_none_task_remains_idle(self):+ # The existing None guard at the top of is_task_busy still wins.+ self.assertFalse(tm.is_task_busy(None))+++if __name__ == "__main__":+ unittest.main()