chore: 迁移服务器前同步本地修改
This commit is contained in:
@@ -14,7 +14,7 @@ from fastapi.responses import StreamingResponse
|
||||
from pydantic import BaseModel, Field
|
||||
|
||||
from kilostar.utils.access import Accessor, TokenData
|
||||
from kilostar.utils.ray_hook import ray_actor_hook
|
||||
from kilostar.utils.actor import get_actor
|
||||
|
||||
router = APIRouter(tags=["data_analytics"])
|
||||
|
||||
@@ -40,7 +40,7 @@ class JobCreate(BaseModel):
|
||||
|
||||
def _get_org():
|
||||
try:
|
||||
return ray_actor_hook("org_data_analytics").org_data_analytics
|
||||
return get_actor("org_data_analytics")
|
||||
except Exception as e:
|
||||
raise HTTPException(503, f"data_analytics 插件未就绪:{e}")
|
||||
|
||||
@@ -53,7 +53,7 @@ async def list_credentials(
|
||||
token_data: TokenData = Depends(Accessor.get_current_user),
|
||||
):
|
||||
org = _get_org()
|
||||
rows = await org.cred_list.remote(token_data.username)
|
||||
rows = await org.cred_list(token_data.username)
|
||||
return {"credentials": rows}
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ async def create_credential(
|
||||
token_data: TokenData = Depends(Accessor.get_current_user),
|
||||
):
|
||||
org = _get_org()
|
||||
row = await org.cred_create.remote(
|
||||
row = await org.cred_create(
|
||||
user_id=token_data.username,
|
||||
display_name=payload.display_name,
|
||||
access_key=payload.access_key,
|
||||
@@ -80,7 +80,7 @@ async def delete_credential(
|
||||
token_data: TokenData = Depends(Accessor.get_current_user),
|
||||
):
|
||||
org = _get_org()
|
||||
ok = await org.cred_delete.remote(cred_id, token_data.username)
|
||||
ok = await org.cred_delete(cred_id, token_data.username)
|
||||
if not ok:
|
||||
raise HTTPException(404, "凭证不存在或不属于当前用户")
|
||||
return {"status": "ok"}
|
||||
@@ -96,7 +96,7 @@ async def create_job(
|
||||
):
|
||||
org = _get_org()
|
||||
try:
|
||||
return await org.job_create.remote(
|
||||
return await org.job_create(
|
||||
user_id=token_data.username,
|
||||
cred_id=payload.cred_id,
|
||||
description=payload.description,
|
||||
@@ -110,7 +110,7 @@ async def list_jobs(
|
||||
token_data: TokenData = Depends(Accessor.get_current_user),
|
||||
):
|
||||
org = _get_org()
|
||||
rows = await org.job_list.remote(token_data.username)
|
||||
rows = await org.job_list(token_data.username)
|
||||
return {"jobs": rows}
|
||||
|
||||
|
||||
@@ -120,7 +120,7 @@ async def get_job(
|
||||
token_data: TokenData = Depends(Accessor.get_current_user),
|
||||
):
|
||||
org = _get_org()
|
||||
row = await org.job_get.remote(job_id, token_data.username)
|
||||
row = await org.job_get(job_id, token_data.username)
|
||||
if row is None:
|
||||
raise HTTPException(404, "任务不存在")
|
||||
return row
|
||||
@@ -135,7 +135,7 @@ async def stream_job(
|
||||
import json
|
||||
|
||||
org = _get_org()
|
||||
row = await org.job_get.remote(job_id, token_data.username)
|
||||
row = await org.job_get(job_id, token_data.username)
|
||||
if row is None:
|
||||
raise HTTPException(404, "任务不存在")
|
||||
org_task_id = row.get("org_task_id")
|
||||
@@ -143,7 +143,7 @@ async def stream_job(
|
||||
raise HTTPException(409, "任务尚未投递到 organization")
|
||||
|
||||
async def _generate():
|
||||
async for event in await org.stream.remote(org_task_id):
|
||||
async for event in await org.stream(org_task_id):
|
||||
payload = event if isinstance(event, str) else json.dumps(event, ensure_ascii=False)
|
||||
yield f"data: {payload}\n\n"
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
"""ray_submit:把分析脚本提交到 Ray(distributed)或 subprocess(standalone)执行。
|
||||
"""ray_submit:把分析脚本提交到子进程执行。
|
||||
|
||||
凭证以 ``AWS_*`` 环境变量注入子进程,让 boto3/pandas-s3 自然读到。
|
||||
脚本走 ``kilostar.utils.sandbox.validate_python_code`` 的静态屏蔽兜底。
|
||||
名字沿用历史(原设计走 Ray);当前后端为本地子进程,未来要接远程算力只需替换
|
||||
执行器,工具签名不变。凭证以 ``AWS_*`` 环境变量注入子进程,让 boto3/pandas-s3
|
||||
自然读到。脚本走 ``kilostar.utils.sandbox.validate_python_code`` 的静态屏蔽兜底。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -11,7 +12,6 @@ import os
|
||||
import sys
|
||||
import tempfile
|
||||
|
||||
from kilostar.utils.ray_compat import _STANDALONE
|
||||
from kilostar.utils.sandbox import (
|
||||
CodeViolation,
|
||||
get_python_timeout,
|
||||
@@ -33,7 +33,7 @@ def _build_env(creds) -> dict:
|
||||
|
||||
|
||||
async def ray_submit(script: str, timeout: int = 300) -> str:
|
||||
"""提交 Python 脚本到 Ray(分布式)或子进程(单机)执行。
|
||||
"""提交 Python 脚本到子进程执行。
|
||||
|
||||
脚本中可直接 ``import boto3`` 读 S3(凭证已通过环境变量注入);可用
|
||||
pandas / polars / numpy 等已安装的依赖。**只读**——不要尝试 put/delete。
|
||||
@@ -83,8 +83,6 @@ async def ray_submit(script: str, timeout: int = 300) -> str:
|
||||
if proc.returncode != 0:
|
||||
result += f"\n[exit code: {proc.returncode}]"
|
||||
result = result.strip() or "(no output)"
|
||||
if not _STANDALONE:
|
||||
result = f"[mode: ray-cluster (subprocess)]\n{result}"
|
||||
return result
|
||||
except asyncio.TimeoutError:
|
||||
return f"[Error] ray_submit 执行超时({timeout}s)"
|
||||
|
||||
Reference in New Issue
Block a user