flowdeck 0.2.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- flowdeck/__init__.py +65 -0
- flowdeck/_version.py +1 -0
- flowdeck/api/__init__.py +216 -0
- flowdeck/api/routers/__init__.py +1 -0
- flowdeck/api/routers/dashboard.py +73 -0
- flowdeck/api/routers/health.py +26 -0
- flowdeck/api/routers/notifications.py +92 -0
- flowdeck/api/routers/pipelines.py +274 -0
- flowdeck/api/routers/runs.py +227 -0
- flowdeck/api/routers/schedule_exceptions.py +141 -0
- flowdeck/api/routers/system.py +386 -0
- flowdeck/api/routers/ui_pipelines.py +507 -0
- flowdeck/api/routers/ui_task_tools.py +275 -0
- flowdeck/api/routers/webhooks.py +115 -0
- flowdeck/auth/__init__.py +0 -0
- flowdeck/auth/basic.py +65 -0
- flowdeck/cli.py +40 -0
- flowdeck/config.py +240 -0
- flowdeck/database/__init__.py +0 -0
- flowdeck/database/base.py +91 -0
- flowdeck/database/models.py +218 -0
- flowdeck/database/repository.py +1231 -0
- flowdeck/logger/__init__.py +122 -0
- flowdeck/logger/formatter.py +112 -0
- flowdeck/logger/web_socket_handler.py +85 -0
- flowdeck/notifications/__init__.py +13 -0
- flowdeck/notifications/email_sender.py +79 -0
- flowdeck/notifications/engine.py +412 -0
- flowdeck/notifications/rules.py +22 -0
- flowdeck/notifications/table_image.py +273 -0
- flowdeck/notifications/task_result.py +478 -0
- flowdeck/notifications/templates.py +224 -0
- flowdeck/orchestrator/__init__.py +380 -0
- flowdeck/orchestrator/executor.py +661 -0
- flowdeck/pipeline/__init__.py +5 -0
- flowdeck/pipeline/_utils.py +11 -0
- flowdeck/pipeline/context.py +13 -0
- flowdeck/pipeline/pipeline.py +40 -0
- flowdeck/pipeline/schedule.py +125 -0
- flowdeck/pipeline/task.py +104 -0
- flowdeck/pipeline/trigger.py +22 -0
- flowdeck/schemas.py +11 -0
- flowdeck/static/assets/BackfillModal-BViyo-00.js +1 -0
- flowdeck/static/assets/BackfillModal-D6je7CRx.css +1 -0
- flowdeck/static/assets/Btn-B77BQZvQ.js +1 -0
- flowdeck/static/assets/Btn-D6G_tsbF.css +1 -0
- flowdeck/static/assets/DashboardView-BM-S5j64.js +1 -0
- flowdeck/static/assets/DashboardView-CBu0kYw6.css +1 -0
- flowdeck/static/assets/DatePickerField-IOKwxOwp.js +830 -0
- flowdeck/static/assets/Empty-B5kRTX_h.css +1 -0
- flowdeck/static/assets/Empty-ScitfHnD.js +1 -0
- flowdeck/static/assets/Modal-7xA4aZKG.js +1 -0
- flowdeck/static/assets/Modal-BNFhtIvK.css +1 -0
- flowdeck/static/assets/NotificationsView-BTkWFeLt.css +1 -0
- flowdeck/static/assets/NotificationsView-BkofWdjj.js +1 -0
- flowdeck/static/assets/NotifySettings-BFdtzy6K.js +1 -0
- flowdeck/static/assets/NotifySettings-D9Nn2RLl.css +1 -0
- flowdeck/static/assets/NumInput--MSEekvd.js +582 -0
- flowdeck/static/assets/NumInput-DfqPA-uG.css +1 -0
- flowdeck/static/assets/PageHeader-3D30Zbvm.js +1 -0
- flowdeck/static/assets/PageHeader-BULVGwbD.css +1 -0
- flowdeck/static/assets/PipelineDetailView-89815vAO.js +1 -0
- flowdeck/static/assets/PipelineDetailView-B_iVBCYT.css +1 -0
- flowdeck/static/assets/PipelinesView-CtDub3qu.js +1 -0
- flowdeck/static/assets/PipelinesView-DC9QO4Wr.css +1 -0
- flowdeck/static/assets/PrettyJson-DjAv38hk.css +1 -0
- flowdeck/static/assets/PrettyJson-_gjY71Cb.js +1 -0
- flowdeck/static/assets/RecentFailuresView-CruW_Dj8.js +1 -0
- flowdeck/static/assets/RecentFailuresView-DjQsiRv9.css +1 -0
- flowdeck/static/assets/RunDetailView--NojY8JX.css +1 -0
- flowdeck/static/assets/RunDetailView-2ZVPmVgW.js +5 -0
- flowdeck/static/assets/ScheduleExceptionsView-DdccyMcD.js +2 -0
- flowdeck/static/assets/ScheduleExceptionsView-pWTB9mSE.css +1 -0
- flowdeck/static/assets/SettingsView-BwlizulV.js +4 -0
- flowdeck/static/assets/SettingsView-D4ybFG31.css +1 -0
- flowdeck/static/assets/StatCard-CdPYF8jZ.js +1 -0
- flowdeck/static/assets/StatCard-D06FdLL9.css +1 -0
- flowdeck/static/assets/StatsView-88bkL-AN.css +1 -0
- flowdeck/static/assets/StatsView-DONGQHCc.js +18 -0
- flowdeck/static/assets/StatusBadge-BDBPRgRa.css +1 -0
- flowdeck/static/assets/StatusBadge-DzUDQ0X_.js +1 -0
- flowdeck/static/assets/ToggleSwitch-KMgLwPsM.js +1 -0
- flowdeck/static/assets/ToggleSwitch-UNHeNS9K.css +1 -0
- flowdeck/static/assets/UiPipelinesView-BgzBgUYR.css +1 -0
- flowdeck/static/assets/UiPipelinesView-WTYqKxB5.js +2 -0
- flowdeck/static/assets/UiTaskEditorView-BgYyqqgT.js +10 -0
- flowdeck/static/assets/UiTaskEditorView-Dl6zmLDP.css +1 -0
- flowdeck/static/assets/_plugin-vue_export-helper-OBKhRxFI.js +12 -0
- flowdeck/static/assets/chakra-petch-latin-400-normal-D7EtbySE.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-400-normal-SafcrIr2.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-500-normal-BR1ody1F.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-500-normal-CnUQnZ4D.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-600-normal-DQKfcdKo.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-600-normal-DVQm9bgb.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-700-normal-CnDBPjkL.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-700-normal-D1s_c2du.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-400-normal-C8u6EFkq.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-400-normal-MNNNbyh_.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-500-normal-BCHeNDEx.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-500-normal-gA6791b0.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-600-normal-CdGvbdDU.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-600-normal-nL80L4xU.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-700-normal-BeviJPUl.woff +0 -0
- flowdeck/static/assets/chakra-petch-latin-ext-700-normal-DAkvJhej.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-thai-400-normal-Bw1Q-fVY.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-thai-400-normal-KdzBjiWs.woff +0 -0
- flowdeck/static/assets/chakra-petch-thai-500-normal-CJG_V2_m.woff +0 -0
- flowdeck/static/assets/chakra-petch-thai-500-normal-DeexCGiz.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-thai-600-normal-BiM5MXH8.woff +0 -0
- flowdeck/static/assets/chakra-petch-thai-600-normal-C620THcd.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-thai-700-normal-B7WL5pBr.woff2 +0 -0
- flowdeck/static/assets/chakra-petch-thai-700-normal-vZLZ_5L8.woff +0 -0
- flowdeck/static/assets/chakra-petch-vietnamese-400-normal-Cn7ya5On.woff +0 -0
- flowdeck/static/assets/chakra-petch-vietnamese-500-normal-BVzUBLGs.woff +0 -0
- flowdeck/static/assets/chakra-petch-vietnamese-600-normal-Pvj4qcw_.woff +0 -0
- flowdeck/static/assets/chakra-petch-vietnamese-700-normal-gQuUA8Wu.woff +0 -0
- flowdeck/static/assets/index-DpymzEZv.css +1 -0
- flowdeck/static/assets/index-DuXbXiXo.js +2 -0
- flowdeck/static/assets/jetbrains-mono-cyrillic-400-normal-BEIGL1Tu.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-cyrillic-400-normal-ugxPyKxw.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-cyrillic-500-normal-DJqRU3vO.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-cyrillic-500-normal-DmUKJPL_.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-cyrillic-700-normal-BWTpRfYl.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-cyrillic-700-normal-CEoEElIJ.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-greek-400-normal-B9oWc5Lo.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-greek-400-normal-C190GLew.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-greek-500-normal-D7SFKleX.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-greek-500-normal-JpySY46c.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-greek-700-normal-C6CZE3T8.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-greek-700-normal-DEigVDxa.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-400-normal-6-qcROiO.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-400-normal-V6pRDFza.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-500-normal-BWZEU5yA.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-500-normal-CJOVTJB7.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-700-normal-BYuf6tUa.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-700-normal-D3wTyLJW.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-ext-400-normal-Bc8Ftmh3.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-ext-400-normal-fXTG6kC5.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-ext-500-normal-Cut-4mMH.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-ext-500-normal-ckzbgY84.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-ext-700-normal-CZipNAKV.woff2 +0 -0
- flowdeck/static/assets/jetbrains-mono-latin-ext-700-normal-CxPITLHs.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-vietnamese-400-normal-CqNFfHCs.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-vietnamese-500-normal-DNRqzVM1.woff +0 -0
- flowdeck/static/assets/jetbrains-mono-vietnamese-700-normal-BDLVIk2r.woff +0 -0
- flowdeck/static/assets/light-B0F-b5Z6.js +20 -0
- flowdeck/static/assets/runtime-dom.esm-bundler-DESsN8Jj.js +2 -0
- flowdeck/static/favicon.svg +13 -0
- flowdeck/static/index.html +18 -0
- flowdeck/storage.py +145 -0
- flowdeck/tasks/__init__.py +1 -0
- flowdeck/tasks/http_executor.py +985 -0
- flowdeck/tasks/paramdefs.py +170 -0
- flowdeck/tasks/paramextract.py +185 -0
- flowdeck/tasks/python_executor.py +234 -0
- flowdeck/tasks/sql_executor.py +683 -0
- flowdeck/tasks/timevars.py +125 -0
- flowdeck/tasks/ui_registry.py +394 -0
- flowdeck-0.2.1.dist-info/METADATA +228 -0
- flowdeck-0.2.1.dist-info/RECORD +163 -0
- flowdeck-0.2.1.dist-info/WHEEL +4 -0
- flowdeck-0.2.1.dist-info/entry_points.txt +2 -0
- flowdeck-0.2.1.dist-info/licenses/LICENSE +293 -0
flowdeck/__init__.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"""FlowDeck:APScheduler 的现代化前台(兼容 plombery 的 Python API)。"""
|
|
2
|
+
|
|
3
|
+
from typing import List, Optional, Type
|
|
4
|
+
|
|
5
|
+
from pydantic import BaseModel
|
|
6
|
+
|
|
7
|
+
from .logger import get_logger
|
|
8
|
+
from .notifications import NotificationRule, notification_manager
|
|
9
|
+
from .orchestrator import orchestrator
|
|
10
|
+
from .pipeline import Pipeline, Task, Trigger, task
|
|
11
|
+
from .schemas import PipelineRunStatus
|
|
12
|
+
from ._version import __version__
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def register_pipeline(
|
|
16
|
+
id: str,
|
|
17
|
+
tasks: List[Task],
|
|
18
|
+
name: Optional[str] = None,
|
|
19
|
+
description: Optional[str] = None,
|
|
20
|
+
params: Optional[Type[BaseModel]] = None,
|
|
21
|
+
triggers: Optional[List[Trigger]] = None,
|
|
22
|
+
timeout_seconds: Optional[float] = None,
|
|
23
|
+
concurrency: str = "skip",
|
|
24
|
+
) -> Pipeline:
|
|
25
|
+
"""与 plombery 签名一致(扩展 timeout_seconds / concurrency):构造 Pipeline 并注册到调度器(幂等)。
|
|
26
|
+
|
|
27
|
+
concurrency:并发策略 parallel / skip(默认)/ cancel_previous,
|
|
28
|
+
同一 pipeline 已有运行中 run 时的处理方式。
|
|
29
|
+
"""
|
|
30
|
+
pipeline = Pipeline(
|
|
31
|
+
id=id,
|
|
32
|
+
tasks=tasks,
|
|
33
|
+
name=name,
|
|
34
|
+
description=description,
|
|
35
|
+
params=params,
|
|
36
|
+
triggers=triggers or [],
|
|
37
|
+
timeout_seconds=timeout_seconds,
|
|
38
|
+
concurrency=concurrency,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
orchestrator.register_pipeline(pipeline)
|
|
42
|
+
return pipeline
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def get_app():
|
|
46
|
+
"""懒加载 FastAPI 应用(api 层由后续任务实现)。"""
|
|
47
|
+
from .api import app
|
|
48
|
+
|
|
49
|
+
return app
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
__all__ = [
|
|
53
|
+
"__version__",
|
|
54
|
+
"get_logger",
|
|
55
|
+
"NotificationRule",
|
|
56
|
+
"notification_manager",
|
|
57
|
+
"orchestrator",
|
|
58
|
+
"Pipeline",
|
|
59
|
+
"Task",
|
|
60
|
+
"Trigger",
|
|
61
|
+
"task",
|
|
62
|
+
"PipelineRunStatus",
|
|
63
|
+
"register_pipeline",
|
|
64
|
+
"get_app",
|
|
65
|
+
]
|
flowdeck/_version.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
__version__ = "0.2.1"
|
flowdeck/api/__init__.py
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
"""FlowDeck HTTP API:FastAPI 应用、路由挂载、WebSocket 日志流与 SPA 静态服务。
|
|
2
|
+
|
|
3
|
+
路由优先级(依赖 starlette 先注册先匹配):
|
|
4
|
+
1. /api 业务路由(统一挂认证依赖;/api/health 与 WebSocket 免认证);
|
|
5
|
+
2. SPA catch-all GET 路由(先于 mount 注册):已存在的静态文件直接返回,
|
|
6
|
+
其余非 /api 路径回退 index.html(前端 history 路由刷新不 404);
|
|
7
|
+
带扩展名的静态资源(/assets/*.js 等)缺失时直接 404——回退 index.html
|
|
8
|
+
会让浏览器收到 text/html 的 JS,报出难排查的 MIME 错误;
|
|
9
|
+
3. / 静态 mount:兜住 catch-all 未覆盖的方法(StaticFiles 返回 405)。
|
|
10
|
+
|
|
11
|
+
缓存策略:带内容 hash 的 /assets/* 长缓存 immutable;index.html(含 SPA
|
|
12
|
+
回退)no-cache,确保发新版后浏览器立刻拿到新的 chunk 清单,旧入口页不再
|
|
13
|
+
引用已不存在的 chunk。
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import logging
|
|
17
|
+
from contextlib import asynccontextmanager
|
|
18
|
+
from pathlib import Path
|
|
19
|
+
|
|
20
|
+
from fastapi import (
|
|
21
|
+
Depends,
|
|
22
|
+
FastAPI,
|
|
23
|
+
HTTPException,
|
|
24
|
+
Request,
|
|
25
|
+
WebSocket,
|
|
26
|
+
WebSocketDisconnect,
|
|
27
|
+
)
|
|
28
|
+
from fastapi.middleware.cors import CORSMiddleware
|
|
29
|
+
from fastapi.staticfiles import StaticFiles
|
|
30
|
+
from starlette.exceptions import HTTPException as StarletteHTTPException
|
|
31
|
+
from starlette.responses import FileResponse
|
|
32
|
+
|
|
33
|
+
from flowdeck._version import __version__
|
|
34
|
+
from flowdeck.auth.basic import get_auth_dependency
|
|
35
|
+
from flowdeck.config import settings
|
|
36
|
+
from flowdeck.database import repository
|
|
37
|
+
from flowdeck.logger.web_socket_handler import broadcaster
|
|
38
|
+
from flowdeck.orchestrator import orchestrator
|
|
39
|
+
from flowdeck.tasks.ui_registry import load_ui_pipelines
|
|
40
|
+
|
|
41
|
+
from .routers import (
|
|
42
|
+
dashboard,
|
|
43
|
+
health,
|
|
44
|
+
notifications,
|
|
45
|
+
pipelines,
|
|
46
|
+
runs,
|
|
47
|
+
schedule_exceptions,
|
|
48
|
+
system,
|
|
49
|
+
ui_pipelines,
|
|
50
|
+
ui_task_tools,
|
|
51
|
+
webhooks,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
API_PREFIX = "/api"
|
|
55
|
+
_logger = logging.getLogger(__name__)
|
|
56
|
+
|
|
57
|
+
_FORWARDED_HEADERS = ("x-forwarded-proto", "x-forwarded-host")
|
|
58
|
+
|
|
59
|
+
_STATIC_DIR = Path(__file__).resolve().parent.parent / "static" # 包根目录:src/flowdeck/static
|
|
60
|
+
_INDEX_FILE = _STATIC_DIR / "index.html"
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
@asynccontextmanager
|
|
64
|
+
async def _lifespan(_: FastAPI):
|
|
65
|
+
repository.init_db()
|
|
66
|
+
# UI 任务(DB 定义)加载进调度器:改完即生效,重启后自动恢复
|
|
67
|
+
load_ui_pipelines()
|
|
68
|
+
if not orchestrator.scheduler.running:
|
|
69
|
+
orchestrator.start()
|
|
70
|
+
try:
|
|
71
|
+
yield
|
|
72
|
+
finally:
|
|
73
|
+
if orchestrator.scheduler.running:
|
|
74
|
+
orchestrator.stop()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
app = FastAPI(title="FlowDeck API", version=__version__, lifespan=_lifespan)
|
|
78
|
+
|
|
79
|
+
# CORS 允许来源:DB app_settings 优先(设置页可改,重启后生效),首次建库前回落 yaml/env 默认
|
|
80
|
+
app.add_middleware(
|
|
81
|
+
CORSMiddleware,
|
|
82
|
+
allow_origins=repository.get_allowed_origins(),
|
|
83
|
+
allow_credentials=True,
|
|
84
|
+
allow_methods=["*"],
|
|
85
|
+
allow_headers=["*"],
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def _origin_from_request(request: Request) -> str:
|
|
90
|
+
"""从请求推断站点 origin(供通知链接自动学习)。
|
|
91
|
+
|
|
92
|
+
- 默认(trust_proxy_headers=False):不采信任何 X-Forwarded-*;
|
|
93
|
+
携带转发头的请求直接跳过(避免客户端伪造头污染已学到的地址);
|
|
94
|
+
- 开启信任:优先 X-Forwarded-Proto / X-Forwarded-Host,缺省回落到
|
|
95
|
+
请求 scheme 与 Host 头;
|
|
96
|
+
- 返回 ``scheme://host``;非法/本机地址由 repository 侧统一过滤。
|
|
97
|
+
"""
|
|
98
|
+
headers = request.headers
|
|
99
|
+
has_forwarded = any(name in headers for name in _FORWARDED_HEADERS)
|
|
100
|
+
|
|
101
|
+
if has_forwarded and not settings.trust_proxy_headers:
|
|
102
|
+
return ""
|
|
103
|
+
|
|
104
|
+
if has_forwarded:
|
|
105
|
+
proto = (headers.get("x-forwarded-proto") or "").split(",")[0].strip()
|
|
106
|
+
host = (headers.get("x-forwarded-host") or "").split(",")[0].strip()
|
|
107
|
+
proto = proto or request.url.scheme
|
|
108
|
+
host = host or headers.get("host", "")
|
|
109
|
+
else:
|
|
110
|
+
proto = request.url.scheme
|
|
111
|
+
host = headers.get("host", "")
|
|
112
|
+
|
|
113
|
+
return f"{proto}://{host}" if proto and host else ""
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
@app.middleware("http")
|
|
117
|
+
async def _learn_site_origin(request: Request, call_next):
|
|
118
|
+
"""记录最近一次面板/接口访问的 origin,用于通知链接自动推断。
|
|
119
|
+
|
|
120
|
+
学习失败绝不影响请求本身;相同值不会重复写库(见 repository)。
|
|
121
|
+
"""
|
|
122
|
+
try:
|
|
123
|
+
origin = _origin_from_request(request)
|
|
124
|
+
if origin:
|
|
125
|
+
repository.record_learned_origin(origin)
|
|
126
|
+
except Exception:
|
|
127
|
+
_logger.debug("学习站点 origin 失败", exc_info=True)
|
|
128
|
+
return await call_next(request)
|
|
129
|
+
|
|
130
|
+
# 认证依赖:业务路由统一挂载(include_router 时注入),/api/health 与 WS 免认证
|
|
131
|
+
auth_dep = get_auth_dependency()
|
|
132
|
+
|
|
133
|
+
app.include_router(health.router, prefix=API_PREFIX)
|
|
134
|
+
app.include_router(
|
|
135
|
+
pipelines.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
136
|
+
)
|
|
137
|
+
app.include_router(runs.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)])
|
|
138
|
+
app.include_router(
|
|
139
|
+
dashboard.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
140
|
+
)
|
|
141
|
+
app.include_router(
|
|
142
|
+
notifications.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
143
|
+
)
|
|
144
|
+
app.include_router(
|
|
145
|
+
webhooks.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
146
|
+
)
|
|
147
|
+
app.include_router(
|
|
148
|
+
ui_pipelines.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
149
|
+
)
|
|
150
|
+
app.include_router(
|
|
151
|
+
ui_task_tools.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
152
|
+
)
|
|
153
|
+
app.include_router(
|
|
154
|
+
schedule_exceptions.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
155
|
+
)
|
|
156
|
+
app.include_router(
|
|
157
|
+
system.router, prefix=API_PREFIX, dependencies=[Depends(auth_dep)]
|
|
158
|
+
)
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# WebSocket 实时日志流(免认证;依赖 websockets 库,见 pyproject dependencies)
|
|
162
|
+
@app.websocket(API_PREFIX + "/ws/logs/{run_id}", name="ws-logs")
|
|
163
|
+
async def websocket_logs(websocket: WebSocket, run_id: int) -> None:
|
|
164
|
+
"""实时日志流:注册到 broadcaster 后保持连接,客户端消息仅作心跳。"""
|
|
165
|
+
await websocket.accept()
|
|
166
|
+
broadcaster.register(websocket)
|
|
167
|
+
try:
|
|
168
|
+
while True:
|
|
169
|
+
await websocket.receive_text()
|
|
170
|
+
except WebSocketDisconnect:
|
|
171
|
+
pass
|
|
172
|
+
finally:
|
|
173
|
+
broadcaster.unregister(websocket)
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
if _INDEX_FILE.is_file():
|
|
177
|
+
_spa_files = StaticFiles(html=True, directory=str(_STATIC_DIR))
|
|
178
|
+
|
|
179
|
+
@app.middleware("http")
|
|
180
|
+
async def _static_cache_headers(request: Request, call_next):
|
|
181
|
+
"""静态资源缓存头:/assets/*(文件名带 hash)长缓存;HTML 入口 no-cache。"""
|
|
182
|
+
response = await call_next(request)
|
|
183
|
+
path = request.url.path
|
|
184
|
+
if path.startswith("/assets/") and response.status_code < 400:
|
|
185
|
+
# 仅成功响应长缓存:缺失资源的 404 不能被浏览器缓存一年
|
|
186
|
+
response.headers.setdefault(
|
|
187
|
+
"Cache-Control", "public, max-age=31536000, immutable"
|
|
188
|
+
)
|
|
189
|
+
elif not path.startswith(API_PREFIX) and "text/html" in response.headers.get(
|
|
190
|
+
"content-type", ""
|
|
191
|
+
):
|
|
192
|
+
# index.html 及 SPA 路由回退:每次使用前必须向服务器校验
|
|
193
|
+
response.headers.setdefault("Cache-Control", "no-cache")
|
|
194
|
+
return response
|
|
195
|
+
|
|
196
|
+
@app.get("/{full_path:path}", include_in_schema=False, name="spa-fallback")
|
|
197
|
+
async def spa_fallback(full_path: str, request: Request):
|
|
198
|
+
# /api 路径不走 SPA 回退(与 plombery 一致按字符串前缀判断)
|
|
199
|
+
if full_path.startswith("api"):
|
|
200
|
+
raise HTTPException(status_code=404, detail="Not Found")
|
|
201
|
+
|
|
202
|
+
try:
|
|
203
|
+
# 静态文件存在则交给 StaticFiles(etag / 304 / 目录 index 逻辑)
|
|
204
|
+
return await _spa_files.get_response(full_path, request.scope)
|
|
205
|
+
except StarletteHTTPException as exc:
|
|
206
|
+
if exc.status_code != 404:
|
|
207
|
+
raise
|
|
208
|
+
# 缺失时:带扩展名的路径(/assets/xxx.js、favicon.ico 等)是确定的
|
|
209
|
+
# 静态资源,直接 404,绝不回退 index.html(text/html 冒充 JS 的
|
|
210
|
+
# MIME 报错难排查);无扩展名的路径回退 index.html(SPA history 路由)
|
|
211
|
+
if "." in full_path.rsplit("/", 1)[-1]:
|
|
212
|
+
raise HTTPException(status_code=404, detail="Not Found")
|
|
213
|
+
return FileResponse(_INDEX_FILE, headers={"Cache-Control": "no-cache"})
|
|
214
|
+
|
|
215
|
+
# mount 在 catch-all 之后注册:GET/HEAD 由 catch-all 处理,其余方法落到这里
|
|
216
|
+
app.mount("/", _spa_files, name="spa")
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""FlowDeck API 路由包。"""
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"""dashboard 路由:今日/近 7 天状态汇总 + 最近失败 + 未来 24h 计划运行。"""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta
|
|
4
|
+
from typing import Any, Dict, List
|
|
5
|
+
|
|
6
|
+
from fastapi import APIRouter
|
|
7
|
+
|
|
8
|
+
from flowdeck.database import repository
|
|
9
|
+
from flowdeck.orchestrator import orchestrator
|
|
10
|
+
|
|
11
|
+
router = APIRouter(prefix="/dashboard", tags=["Dashboard"])
|
|
12
|
+
|
|
13
|
+
UPCOMING_WINDOW = timedelta(hours=24)
|
|
14
|
+
SYSTEM_JOB_PREFIX = "__flowdeck_"
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _bucket(counts: Dict[str, int]) -> Dict[str, int]:
|
|
18
|
+
return {
|
|
19
|
+
"total": sum(counts.values()),
|
|
20
|
+
"succeeded": counts.get("succeeded", 0),
|
|
21
|
+
"failed": counts.get("failed", 0),
|
|
22
|
+
"running": counts.get("running", 0),
|
|
23
|
+
"skipped": counts.get("skipped", 0),
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def _upcoming() -> List[Dict[str, Any]]:
|
|
28
|
+
"""调度器所有业务 job 的下一次运行时间(排除系统 job 与 UI 暂停/禁用),只取未来 24h。"""
|
|
29
|
+
cutoff = datetime.now().astimezone() + UPCOMING_WINDOW
|
|
30
|
+
items: List[Dict[str, Any]] = []
|
|
31
|
+
|
|
32
|
+
for job in orchestrator.scheduler.get_jobs():
|
|
33
|
+
if job.id is None or job.id.startswith(SYSTEM_JOB_PREFIX):
|
|
34
|
+
continue
|
|
35
|
+
|
|
36
|
+
entry = orchestrator._all_triggers.get(job.id)
|
|
37
|
+
if entry is None:
|
|
38
|
+
continue
|
|
39
|
+
|
|
40
|
+
pipeline, trigger = entry
|
|
41
|
+
if trigger.paused:
|
|
42
|
+
continue
|
|
43
|
+
if repository.is_pipeline_paused(pipeline.id):
|
|
44
|
+
continue
|
|
45
|
+
if repository.is_trigger_disabled(pipeline.id, trigger.id):
|
|
46
|
+
continue
|
|
47
|
+
|
|
48
|
+
next_run_time = job.next_run_time
|
|
49
|
+
if next_run_time is None or next_run_time > cutoff:
|
|
50
|
+
continue
|
|
51
|
+
|
|
52
|
+
items.append(
|
|
53
|
+
{
|
|
54
|
+
"pipeline_id": pipeline.id,
|
|
55
|
+
"name": pipeline.name,
|
|
56
|
+
"trigger_id": trigger.id,
|
|
57
|
+
"next_run_time": next_run_time,
|
|
58
|
+
}
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
items.sort(key=lambda item: item["next_run_time"])
|
|
62
|
+
return items
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
@router.get("/summary")
|
|
66
|
+
def summary():
|
|
67
|
+
raw = repository.dashboard_summary()
|
|
68
|
+
return {
|
|
69
|
+
"today": _bucket(raw["today"]),
|
|
70
|
+
"week": _bucket(raw["week"]),
|
|
71
|
+
"recent_failed": raw["recent_failures"],
|
|
72
|
+
"upcoming": _upcoming(),
|
|
73
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"""健康检查(免认证)。"""
|
|
2
|
+
|
|
3
|
+
from datetime import datetime
|
|
4
|
+
|
|
5
|
+
from fastapi import APIRouter
|
|
6
|
+
|
|
7
|
+
from flowdeck._version import __version__
|
|
8
|
+
from flowdeck.database import repository
|
|
9
|
+
|
|
10
|
+
router = APIRouter(tags=["Health"])
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@router.get("/health")
|
|
14
|
+
def health() -> dict:
|
|
15
|
+
local = datetime.now().astimezone()
|
|
16
|
+
offset = local.strftime("%z")
|
|
17
|
+
expected = repository.get_expected_utc_offset().replace(":", "").strip()
|
|
18
|
+
return {
|
|
19
|
+
"status": "ok",
|
|
20
|
+
"version": __version__,
|
|
21
|
+
"server_timezone": {
|
|
22
|
+
"name": local.tzname() or "",
|
|
23
|
+
"utc_offset": offset,
|
|
24
|
+
},
|
|
25
|
+
"timezone_mismatch": bool(expected) and offset != expected,
|
|
26
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
"""notifications 路由:通知规则 CRUD(存 DB,即时生效;email 渠道设置页门控)。"""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import re
|
|
5
|
+
from typing import Any, Dict, Optional
|
|
6
|
+
|
|
7
|
+
from fastapi import APIRouter, HTTPException
|
|
8
|
+
|
|
9
|
+
from flowdeck.database import repository
|
|
10
|
+
from flowdeck.notifications import notification_manager
|
|
11
|
+
from flowdeck.notifications.rules import NotificationRuleSchema
|
|
12
|
+
|
|
13
|
+
router = APIRouter(prefix="/notifications", tags=["Notifications"])
|
|
14
|
+
|
|
15
|
+
_EMAIL_RE = re.compile(r"^[^@\s]+@[^@\s]+\.[^@\s]+$")
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def _find_rule(rule_id: int):
|
|
19
|
+
for rule in repository.list_rules_db():
|
|
20
|
+
if rule.id == rule_id:
|
|
21
|
+
return rule
|
|
22
|
+
return None
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _serialize_rule(rule) -> Dict[str, Any]:
|
|
26
|
+
return {
|
|
27
|
+
"id": rule.id,
|
|
28
|
+
"name": rule.name,
|
|
29
|
+
"events": json.loads(rule.events) if rule.events else [],
|
|
30
|
+
"pipeline_pattern": rule.pipeline_pattern or "",
|
|
31
|
+
"webhook_url": rule.webhook_url or "",
|
|
32
|
+
"template": rule.template or "json",
|
|
33
|
+
"mentioned_list": json.loads(rule.mentioned_list) if rule.mentioned_list else [],
|
|
34
|
+
"channel": getattr(rule, "channel", None) or "webhook",
|
|
35
|
+
"recipients": (
|
|
36
|
+
json.loads(rule.recipients) if getattr(rule, "recipients", None) else []
|
|
37
|
+
),
|
|
38
|
+
"enabled": bool(rule.enabled),
|
|
39
|
+
"source": rule.source or "ui",
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def _validate_channel(rule: NotificationRuleSchema) -> None:
|
|
44
|
+
"""渠道校验:email 必须先在设置页启用 SMTP(总开关门控)且带收件人。"""
|
|
45
|
+
if rule.channel == "email":
|
|
46
|
+
if repository.get_smtp_config() is None:
|
|
47
|
+
raise HTTPException(
|
|
48
|
+
status_code=422,
|
|
49
|
+
detail="邮件渠道未启用:请先在设置页配置并启用 SMTP,再创建邮件通知规则",
|
|
50
|
+
)
|
|
51
|
+
bad = [r for r in (rule.recipients or []) if not _EMAIL_RE.fullmatch(r.strip())]
|
|
52
|
+
if bad:
|
|
53
|
+
raise HTTPException(
|
|
54
|
+
status_code=422, detail=f"收件人地址格式不正确:{', '.join(bad)}"
|
|
55
|
+
)
|
|
56
|
+
if not [r for r in (rule.recipients or []) if r.strip()]:
|
|
57
|
+
raise HTTPException(status_code=422, detail="邮件规则至少填写一个收件人")
|
|
58
|
+
elif not (rule.webhook_url or "").strip():
|
|
59
|
+
raise HTTPException(status_code=422, detail="webhook 渠道必须填写 webhook 地址")
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
@router.get("")
|
|
63
|
+
def list_rules():
|
|
64
|
+
return {"rules": notification_manager.list_rules()}
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
@router.post("")
|
|
68
|
+
def create_rule(rule: NotificationRuleSchema):
|
|
69
|
+
_validate_channel(rule)
|
|
70
|
+
return _serialize_rule(repository.create_rule(rule))
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
@router.put("/{rule_id}")
|
|
74
|
+
def update_rule(rule_id: int, rule: NotificationRuleSchema):
|
|
75
|
+
existing = _find_rule(rule_id)
|
|
76
|
+
if existing is None:
|
|
77
|
+
raise HTTPException(
|
|
78
|
+
status_code=404, detail=f"通知规则 {rule_id} 不存在"
|
|
79
|
+
)
|
|
80
|
+
_validate_channel(rule)
|
|
81
|
+
return _serialize_rule(repository.update_rule(rule_id, rule))
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
@router.delete("/{rule_id}")
|
|
85
|
+
def delete_rule(rule_id: int):
|
|
86
|
+
existing = _find_rule(rule_id)
|
|
87
|
+
if existing is None:
|
|
88
|
+
raise HTTPException(
|
|
89
|
+
status_code=404, detail=f"通知规则 {rule_id} 不存在"
|
|
90
|
+
)
|
|
91
|
+
repository.delete_rule(rule_id)
|
|
92
|
+
return {"ok": True}
|