25 lines
1.5 KiB
Python
25 lines
1.5 KiB
Python
"""Admission is evaluated at phase boundaries. A closing window never cancels work."""
|
|
from datetime import datetime,timezone,timedelta
|
|
# fixed UTC+8 has no DST; avoids depending on OS IANA data on Windows.
|
|
SHANGHAI=timezone(timedelta(hours=8))
|
|
|
|
def execution_policy(now=None):
|
|
now=now or datetime.now(timezone.utc)
|
|
if now.tzinfo is None: now=now.replace(tzinfo=timezone.utc)
|
|
local=now.astimezone(SHANGHAI)
|
|
opened=local.hour>=21 or local.hour<8
|
|
next_at=local.replace(hour=21,minute=0,second=0,microsecond=0)
|
|
if local.hour>=21: next_at+=timedelta(days=1)
|
|
return {"timezone":"Asia/Shanghai","start":"21:00","end":"08:00","batch_open":opened,"next_batch_at":next_at.astimezone(timezone.utc).isoformat(),"close_behavior":"finish_current"}
|
|
|
|
def admits(job,now=None):
|
|
if job.cancel_requested or job.desired_state!="run": return False
|
|
if set(job.hold_reasons or [])-{"window"}: return False
|
|
return job.execution_mode!="batch" or execution_policy(now)["batch_open"]
|
|
|
|
def resource_plan(task_type,input_kind=None):
|
|
if task_type=="audio.transcribe": return [("extract_audio","cpu_media"),("transcribe","new_gpu")] if input_kind=="video" else [("transcribe","new_gpu")]
|
|
if task_type=="media.structure": return [("sample_frames","cpu_media"),("describe_frames","qwen_http")] if input_kind=="video" else [("describe_frames","qwen_http")]
|
|
if task_type=="math.solve":return [("solve","qwen_http")]
|
|
return [("execute","new_gpu" if task_type in {"image.generate","video.generate","defect.generate"} else "cpu_media")]
|