tasklite-engine 2.2.1__py3-none-any.whl → 3.0.0.dev1__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.
- tasklite/__init__.py +62 -204
- tasklite/__main__.py +205 -0
- tasklite/_report.py +562 -0
- tasklite/backend/__init__.py +20 -6
- tasklite/backend/base.py +431 -288
- tasklite/backend/memory.py +499 -340
- tasklite/backend/sqlite_backend.py +817 -617
- tasklite/edit.py +1276 -0
- tasklite/engine/__init__.py +7 -8
- tasklite/engine/_worker_bootstrap.py +221 -0
- tasklite/engine/_worker_runtime.py +229 -0
- tasklite/engine/admission.py +33 -89
- tasklite/engine/authorization.py +989 -0
- tasklite/engine/channel.py +831 -660
- tasklite/engine/completion.py +494 -289
- tasklite/engine/config.py +9 -139
- tasklite/engine/dispatch.py +424 -420
- tasklite/engine/governor.py +167 -265
- tasklite/engine/in_flight.py +32 -98
- tasklite/engine/launcher.py +1173 -0
- tasklite/engine/recovery.py +159 -312
- tasklite/engine/resource.py +240 -426
- tasklite/engine/runtime.py +236 -312
- tasklite/engine/scheduler.py +70 -98
- tasklite/engine/session.py +93 -76
- tasklite/engine/store.py +489 -685
- tasklite/engine/types.py +55 -71
- tasklite/engine/wait.py +38 -16
- tasklite/exceptions.py +4 -58
- tasklite/models/__init__.py +21 -6
- tasklite/models/artifact.py +433 -72
- tasklite/models/context.py +182 -206
- tasklite/models/graph.py +114 -0
- tasklite/models/job.py +117 -270
- tasklite/models/records.py +482 -0
- tasklite/models/result.py +246 -0
- tasklite/models/state.py +99 -125
- tasklite/models/task.py +52 -105
- tasklite/models/trigger.py +63 -3
- tasklite/pipeline.py +295 -558
- tasklite/resource.py +89 -0
- tasklite/selection.py +9 -97
- tasklite/snapshot.py +842 -0
- tasklite/testing.py +452 -41
- tasklite/utils/artifact.py +1093 -113
- tasklite/utils/clock.py +3 -3
- tasklite/utils/encoding.py +107 -31
- tasklite/utils/ipc.py +289 -243
- tasklite/utils/lockfile.py +76 -70
- tasklite/wrappers/__init__.py +2 -2
- tasklite/wrappers/discovery.py +161 -167
- tasklite/wrappers/http.py +142 -521
- tasklite_engine-3.0.0.dev1.dist-info/METADATA +313 -0
- tasklite_engine-3.0.0.dev1.dist-info/RECORD +60 -0
- tasklite/contrib/__init__.py +0 -7
- tasklite/engine/errorclass.py +0 -971
- tasklite/engine/ops.py +0 -363
- tasklite/engine/selection.py +0 -244
- tasklite/hooks.py +0 -69
- tasklite/models/attempt.py +0 -141
- tasklite/triggers.py +0 -46
- tasklite_engine-2.2.1.dist-info/METADATA +0 -370
- tasklite_engine-2.2.1.dist-info/RECORD +0 -55
- {tasklite_engine-2.2.1.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/WHEEL +0 -0
- {tasklite_engine-2.2.1.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/licenses/LICENSE +0 -0
- {tasklite_engine-2.2.1.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/top_level.txt +0 -0
tasklite/__init__.py
CHANGED
|
@@ -1,219 +1,77 @@
|
|
|
1
|
-
"""TaskLite:Task/Job/Attempt 三层模型的任务编排引擎(ADR-0004 / ADR-0005)。
|
|
1
|
+
"""TaskLite:Task/Job/Attempt 三层模型的任务编排引擎(ADR-0004 / ADR-0005 / ADR-0011)。
|
|
2
2
|
|
|
3
|
-
模型:Task 为进程内注册的静态规格模板;Job
|
|
4
|
-
(uid = task_type::job_id);
|
|
5
|
-
|
|
6
|
-
重试节奏由 RequeuePolicy seam 收敛,核心不含退避与排序计算。
|
|
3
|
+
模型:Task 为进程内注册的静态规格模板;Job 为具有稳定身份的逻辑实例
|
|
4
|
+
(uid = task_type::job_id);TaskResult 为 handler 唯一合法返回类型;
|
|
5
|
+
Attempt 为 append-only 的执行轨迹。
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
为版本单一事实源(pyproject 动态读取点)。
|
|
7
|
+
公开面:根包仅导出 ADR-0011 契约已定的核心 10 个名称:
|
|
8
|
+
TaskLite, Task, Job, JobContext, TaskResult, FileSpec,
|
|
9
|
+
StateSnapshot, TaskLiteError, make_job_uid, parse_job_uid。
|
|
10
|
+
内置资源从 tasklite.resource 导入(CapacityResource, IntervalResource);
|
|
11
|
+
运行排除规则从 tasklite.selection 导入(Exclude)。
|
|
12
|
+
不在根包重复导出。``__version__`` 为版本单一事实源(pyproject 动态读取点)。
|
|
14
13
|
|
|
15
14
|
分层单向依赖红线:``tasklite/models/`` 严禁 import
|
|
16
15
|
``tasklite/engine/``(IPC 声明读写一律下沉 ``tasklite/utils/ipc.py``),
|
|
17
16
|
``tasklite/utils/`` 严禁 import ``tasklite/wrappers/``,核心层
|
|
18
|
-
(engine/backend/models/utils)严禁依赖 ``tasklite/
|
|
19
|
-
|
|
20
|
-
设计契约与命名映射见 docs/adr/0004-v2-parallel-rebuild.md;
|
|
21
|
-
上位裁决见 docs/adr/0005-v2-promotion.md。
|
|
17
|
+
(engine/backend/models/utils)严禁依赖 ``tasklite/wrappers/``。
|
|
22
18
|
"""
|
|
23
19
|
from __future__ import annotations
|
|
24
20
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
from .
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
from .models.
|
|
35
|
-
from .models.
|
|
36
|
-
from .models.
|
|
37
|
-
from .
|
|
38
|
-
from .
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
)
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
ERR_DEPENDENCY_DEADLOCK,
|
|
56
|
-
ERR_DEPENDENCY_EXCLUDED,
|
|
57
|
-
ERR_DEPENDENCY_SKIPPED,
|
|
58
|
-
ERR_DISPATCH_FAILURE,
|
|
59
|
-
ERR_IPC_WRITE_DEGRADED_PREFIX,
|
|
60
|
-
ERR_JOB_DEPENDENCY,
|
|
61
|
-
ERR_MALFORMED_JOB,
|
|
62
|
-
ERR_MAX_RETRIES,
|
|
63
|
-
ERR_NO_HANDLER,
|
|
64
|
-
ERR_NO_IPC_RESULT,
|
|
65
|
-
ERR_PAYLOAD_VALIDATION,
|
|
66
|
-
ERR_PROCESS_CRASH_PREFIX,
|
|
67
|
-
ERR_PROCESS_SIGNAL_DEATH,
|
|
68
|
-
ERR_RESOURCE_DEADLOCK,
|
|
69
|
-
ERR_SKIPPED,
|
|
70
|
-
ERR_TIMEOUT_PREFIX,
|
|
71
|
-
FATAL_EXCEPTIONS,
|
|
72
|
-
TRANSIENT_EXCEPTIONS,
|
|
73
|
-
ErrorCategory,
|
|
74
|
-
ErrorClassification,
|
|
75
|
-
ErrorClassifier,
|
|
76
|
-
ValidationErrorItem,
|
|
77
|
-
ValidationResult,
|
|
78
|
-
classify_error_category,
|
|
79
|
-
classify_exception,
|
|
80
|
-
is_transient_exception,
|
|
81
|
-
validate_payload_errors,
|
|
82
|
-
)
|
|
83
|
-
|
|
84
|
-
# ── 资源体系 ─────────────────────────────────────────────────────────
|
|
85
|
-
from .engine.resource import (
|
|
86
|
-
CapacityResource,
|
|
87
|
-
RateLimitResource,
|
|
88
|
-
Resource,
|
|
89
|
-
)
|
|
90
|
-
|
|
91
|
-
# ── 失败档案条目与挂起条目 ───────────────────────────────────────────
|
|
92
|
-
from .engine.ops import SuspendEntry
|
|
93
|
-
from .engine.store import FailureEntry
|
|
94
|
-
|
|
95
|
-
# ── 策略 seam:准入(trigger)与重入队(节奏)─────────────────────────
|
|
96
|
-
from .engine.admission import (
|
|
97
|
-
ImmediateRequeuePolicy,
|
|
98
|
-
RequeuePlan,
|
|
99
|
-
RequeuePolicy,
|
|
100
|
-
TriggerRegistry,
|
|
101
|
-
)
|
|
102
|
-
|
|
103
|
-
# ── 策略 seam:调度排序 ──────────────────────────────────────────────
|
|
104
|
-
from .engine.scheduler import FifoOrderingPolicy, OrderingPolicy
|
|
105
|
-
|
|
106
|
-
# ── 运行值对象:run()/stop() 调用边界直接遭遇的形状 ──────────────────
|
|
107
|
-
from .engine.types import (
|
|
108
|
-
AttemptOutcome,
|
|
109
|
-
ExitReason,
|
|
110
|
-
RunSummary,
|
|
111
|
-
StopMode,
|
|
112
|
-
RunStats,
|
|
113
|
-
)
|
|
114
|
-
|
|
115
|
-
# ── 持久化后端 ───────────────────────────────────────────────────────
|
|
116
|
-
from .backend import InMemoryStateBackend, SQLiteStateBackend
|
|
117
|
-
|
|
118
|
-
# ── 单射编码族 ───────────────────────────────────────────────────────
|
|
119
|
-
from .utils.encoding import (
|
|
120
|
-
content_fingerprint,
|
|
121
|
-
encode_content_id,
|
|
122
|
-
encode_identifier,
|
|
123
|
-
encode_job_component,
|
|
124
|
-
percent_encode,
|
|
125
|
-
encode_job_uid_filename,
|
|
126
|
-
)
|
|
127
|
-
|
|
128
|
-
# ── JSON 序列化统一出口 ──────────────────────────────────────────────
|
|
129
|
-
from .utils import jsonutil
|
|
21
|
+
import importlib
|
|
22
|
+
from typing import TYPE_CHECKING, Any
|
|
23
|
+
|
|
24
|
+
__version__ = "3.0.0.dev1"
|
|
25
|
+
|
|
26
|
+
if TYPE_CHECKING:
|
|
27
|
+
from .exceptions import TaskLiteError
|
|
28
|
+
from .models.artifact import FileSpec
|
|
29
|
+
from .models.context import JobContext
|
|
30
|
+
from .models.job import Job
|
|
31
|
+
from .models.result import TaskResult
|
|
32
|
+
from .models.task import Task
|
|
33
|
+
from .pipeline import TaskLite
|
|
34
|
+
from .snapshot import StateSnapshot
|
|
35
|
+
from .utils.encoding import make_job_uid, parse_job_uid
|
|
36
|
+
|
|
37
|
+
# 根包延迟导出表(PEP 562):避免子进程引导导入 ``tasklite.engine._worker_bootstrap``
|
|
38
|
+
# 时连带拉起父进程门面、快照与持久化树。
|
|
39
|
+
_LAZY_EXPORTS: dict[str, tuple[str, str]] = {
|
|
40
|
+
"TaskLite": (".pipeline", "TaskLite"),
|
|
41
|
+
"Task": (".models.task", "Task"),
|
|
42
|
+
"Job": (".models.job", "Job"),
|
|
43
|
+
"JobContext": (".models.context", "JobContext"),
|
|
44
|
+
"TaskResult": (".models.result", "TaskResult"),
|
|
45
|
+
"FileSpec": (".models.artifact", "FileSpec"),
|
|
46
|
+
"StateSnapshot": (".snapshot", "StateSnapshot"),
|
|
47
|
+
"TaskLiteError": (".exceptions", "TaskLiteError"),
|
|
48
|
+
"make_job_uid": (".utils.encoding", "make_job_uid"),
|
|
49
|
+
"parse_job_uid": (".utils.encoding", "parse_job_uid"),
|
|
50
|
+
}
|
|
130
51
|
|
|
131
52
|
__all__ = [
|
|
132
|
-
# 门面
|
|
133
53
|
"TaskLite",
|
|
134
|
-
|
|
135
|
-
"Exclude",
|
|
136
|
-
"Selection",
|
|
137
|
-
"Skip",
|
|
138
|
-
# 模型层
|
|
139
|
-
"AttemptRecord",
|
|
54
|
+
"Task",
|
|
140
55
|
"Job",
|
|
141
56
|
"JobContext",
|
|
142
|
-
"
|
|
143
|
-
"
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
"
|
|
147
|
-
|
|
148
|
-
"FatalError",
|
|
149
|
-
"PipelineError",
|
|
150
|
-
"RateLimitHit",
|
|
151
|
-
"RetryError",
|
|
152
|
-
# 钩子三件套
|
|
153
|
-
"job_ref",
|
|
154
|
-
"progress_hook",
|
|
155
|
-
"slice_list",
|
|
156
|
-
# 错误分类
|
|
157
|
-
"ErrorCategory",
|
|
158
|
-
"ErrorClassification",
|
|
159
|
-
"ErrorClassifier",
|
|
160
|
-
"ValidationErrorItem",
|
|
161
|
-
"ValidationResult",
|
|
162
|
-
"classify_error_category",
|
|
163
|
-
"classify_exception",
|
|
164
|
-
"is_transient_exception",
|
|
165
|
-
"validate_payload_errors",
|
|
166
|
-
"ERR_DEPENDENCY_DEADLOCK",
|
|
167
|
-
"ERR_JOB_DEPENDENCY",
|
|
168
|
-
"ERR_PAYLOAD_VALIDATION",
|
|
169
|
-
"ERR_MAX_RETRIES",
|
|
170
|
-
"ERR_NO_HANDLER",
|
|
171
|
-
"ERR_RESOURCE_DEADLOCK",
|
|
172
|
-
"ERR_MALFORMED_JOB",
|
|
173
|
-
"ERR_COMMIT_FAILURE",
|
|
174
|
-
"ERR_DISPATCH_FAILURE",
|
|
175
|
-
"ERR_DEADLOCK_GAP",
|
|
176
|
-
"ERR_DEPENDENCY_EXCLUDED",
|
|
177
|
-
"ERR_DEPENDENCY_SKIPPED",
|
|
178
|
-
"ERR_SKIPPED",
|
|
179
|
-
"ERR_TIMEOUT_PREFIX",
|
|
180
|
-
"ERR_PROCESS_CRASH_PREFIX",
|
|
181
|
-
"ERR_NO_IPC_RESULT",
|
|
182
|
-
"ERR_PROCESS_SIGNAL_DEATH",
|
|
183
|
-
"ERR_IPC_WRITE_DEGRADED_PREFIX",
|
|
184
|
-
# 错误分类:默认异常启发式元组
|
|
185
|
-
"FATAL_EXCEPTIONS",
|
|
186
|
-
"TRANSIENT_EXCEPTIONS",
|
|
187
|
-
# 资源体系
|
|
188
|
-
"CapacityResource",
|
|
189
|
-
"RateLimitResource",
|
|
190
|
-
"Resource",
|
|
191
|
-
# 失败档案与挂起
|
|
192
|
-
"FailureEntry",
|
|
193
|
-
"SuspendEntry",
|
|
194
|
-
# 策略 seam
|
|
195
|
-
"ImmediateRequeuePolicy",
|
|
196
|
-
"RequeuePlan",
|
|
197
|
-
"RequeuePolicy",
|
|
198
|
-
"TriggerRegistry",
|
|
199
|
-
"FifoOrderingPolicy",
|
|
200
|
-
"OrderingPolicy",
|
|
201
|
-
# 运行值对象
|
|
202
|
-
"AttemptOutcome",
|
|
203
|
-
"ExitReason",
|
|
204
|
-
"RunSummary",
|
|
205
|
-
"StopMode",
|
|
206
|
-
"RunStats",
|
|
207
|
-
# 持久化后端
|
|
208
|
-
"InMemoryStateBackend",
|
|
209
|
-
"SQLiteStateBackend",
|
|
210
|
-
# 单射编码族
|
|
211
|
-
"content_fingerprint",
|
|
212
|
-
"encode_content_id",
|
|
213
|
-
"encode_identifier",
|
|
214
|
-
"encode_job_component",
|
|
215
|
-
"percent_encode",
|
|
216
|
-
"encode_job_uid_filename",
|
|
217
|
-
# 序列化
|
|
218
|
-
"jsonutil",
|
|
57
|
+
"TaskResult",
|
|
58
|
+
"FileSpec",
|
|
59
|
+
"StateSnapshot",
|
|
60
|
+
"TaskLiteError",
|
|
61
|
+
"make_job_uid",
|
|
62
|
+
"parse_job_uid",
|
|
219
63
|
]
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def __getattr__(name: str) -> Any:
|
|
67
|
+
target = _LAZY_EXPORTS.get(name)
|
|
68
|
+
if target is None:
|
|
69
|
+
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")
|
|
70
|
+
module_name, attr_name = target
|
|
71
|
+
value = getattr(importlib.import_module(module_name, __name__), attr_name)
|
|
72
|
+
globals()[name] = value
|
|
73
|
+
return value
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def __dir__() -> list[str]:
|
|
77
|
+
return sorted(set(globals()) | set(__all__))
|
tasklite/__main__.py
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"""TaskLite 极简运维命令行入口(``python -m tasklite``,ADR-0012 §3.4)。
|
|
2
|
+
|
|
3
|
+
严格定位于只读观测与纯 ``uid`` 驱动的轻量状态运维:
|
|
4
|
+
- ``status``:薄封装 ``StateSnapshot.open`` 与 ``StateSnapshot.report``;
|
|
5
|
+
- ``set-status`` / ``remove``:100% 委托 ``TaskLite.edit()``,默认预览不落盘,
|
|
6
|
+
显式传入 ``--apply`` 才原子提交;
|
|
7
|
+
- 所有子命令强制要求显式传入 ``<state_path>``,修改类命令前置校验路径存在且非目录,
|
|
8
|
+
绝不静默新建空数据库文件。
|
|
9
|
+
"""
|
|
10
|
+
from __future__ import annotations
|
|
11
|
+
|
|
12
|
+
import argparse
|
|
13
|
+
from collections.abc import Sequence
|
|
14
|
+
from pathlib import Path
|
|
15
|
+
import sqlite3
|
|
16
|
+
import sys
|
|
17
|
+
from typing import Literal, TextIO, cast
|
|
18
|
+
|
|
19
|
+
from .backend.sqlite_backend import verify_existing_sqlite_database
|
|
20
|
+
from .exceptions import TaskLiteError
|
|
21
|
+
from .pipeline import TaskLite
|
|
22
|
+
from .snapshot import StateSnapshot
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _safe_print(text: str, *, file: TextIO) -> None:
|
|
26
|
+
"""在窄编码终端管道(如 Windows GBK)下安全输出文本,避免渲染符号触发编码异常。"""
|
|
27
|
+
try:
|
|
28
|
+
print(text, file=file)
|
|
29
|
+
except UnicodeEncodeError:
|
|
30
|
+
encoding = getattr(file, "encoding", None) or "utf-8"
|
|
31
|
+
safe_text = text.encode(encoding, errors="replace").decode(encoding)
|
|
32
|
+
print(safe_text, file=file)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
def _validate_existing_state_path(raw_path: str) -> Path:
|
|
36
|
+
"""修改类子命令前置校验:只读探活已存在的 Schema 6 状态库,杜绝静默建空库或写入 WAL/SHM。"""
|
|
37
|
+
if not raw_path or not raw_path.strip():
|
|
38
|
+
raise TaskLiteError("state_path must be a non-empty file path")
|
|
39
|
+
return verify_existing_sqlite_database(raw_path)
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _parse_entries(raw_entries: str) -> list[Literal["queue", "successes", "failures"]]:
|
|
43
|
+
"""按逗号拆分并去除空白;空值或非法分区名保留交由 EditTransaction.remove 统一校验。"""
|
|
44
|
+
if not raw_entries.strip():
|
|
45
|
+
return []
|
|
46
|
+
parts = [part.strip() for part in raw_entries.split(",")]
|
|
47
|
+
return cast(list[Literal["queue", "successes", "failures"]], parts)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _add_recursive_group(subparser: argparse.ArgumentParser) -> None:
|
|
51
|
+
"""要求显式二选一传入 --recursive 或 --no-recursive。"""
|
|
52
|
+
group = subparser.add_mutually_exclusive_group(required=True)
|
|
53
|
+
group.add_argument(
|
|
54
|
+
"--recursive",
|
|
55
|
+
dest="recursive",
|
|
56
|
+
action="store_true",
|
|
57
|
+
help="沿正向 depends_on 闭包级联作用于全部下游作业",
|
|
58
|
+
)
|
|
59
|
+
group.add_argument(
|
|
60
|
+
"--no-recursive",
|
|
61
|
+
dest="recursive",
|
|
62
|
+
action="store_false",
|
|
63
|
+
help="仅作用于指定的单个作业,不级联下游",
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _build_parser() -> argparse.ArgumentParser:
|
|
68
|
+
parser = argparse.ArgumentParser(
|
|
69
|
+
prog="python -m tasklite",
|
|
70
|
+
description="TaskLite 运维命令行工具(只读观测与纯 UID 级状态修整)。",
|
|
71
|
+
)
|
|
72
|
+
subparsers = parser.add_subparsers(dest="command", required=True)
|
|
73
|
+
|
|
74
|
+
# 1. status
|
|
75
|
+
status_parser = subparsers.add_parser(
|
|
76
|
+
"status",
|
|
77
|
+
help="输出状态库只读状态与耗时报告",
|
|
78
|
+
)
|
|
79
|
+
status_parser.add_argument(
|
|
80
|
+
"state_path",
|
|
81
|
+
help="SQLite 状态库文件路径(必填)",
|
|
82
|
+
)
|
|
83
|
+
|
|
84
|
+
# 2. set-status
|
|
85
|
+
set_status_parser = subparsers.add_parser(
|
|
86
|
+
"set-status",
|
|
87
|
+
help="将指定作业(可选级联下游)流转为 pending 或 failed",
|
|
88
|
+
)
|
|
89
|
+
set_status_parser.add_argument(
|
|
90
|
+
"state_path",
|
|
91
|
+
help="SQLite 状态库文件路径(必填)",
|
|
92
|
+
)
|
|
93
|
+
set_status_parser.add_argument(
|
|
94
|
+
"uid",
|
|
95
|
+
help="目标作业规范 UID(task_type::job_id)",
|
|
96
|
+
)
|
|
97
|
+
set_status_parser.add_argument(
|
|
98
|
+
"status",
|
|
99
|
+
choices=("pending", "failed"),
|
|
100
|
+
help="目标状态(仅允许 pending 或 failed)",
|
|
101
|
+
)
|
|
102
|
+
_add_recursive_group(set_status_parser)
|
|
103
|
+
set_status_parser.add_argument(
|
|
104
|
+
"--note",
|
|
105
|
+
default=None,
|
|
106
|
+
help="可选运维备注,写入事务变更记录",
|
|
107
|
+
)
|
|
108
|
+
set_status_parser.add_argument(
|
|
109
|
+
"--apply",
|
|
110
|
+
action="store_true",
|
|
111
|
+
default=False,
|
|
112
|
+
help="显式提交落盘(默认仅 dry-run 预览不写入数据库)",
|
|
113
|
+
)
|
|
114
|
+
|
|
115
|
+
# 3. remove
|
|
116
|
+
remove_parser = subparsers.add_parser(
|
|
117
|
+
"remove",
|
|
118
|
+
help="从指定分区移除作业条目(永不删除 attempts 或磁盘文件)",
|
|
119
|
+
)
|
|
120
|
+
remove_parser.add_argument(
|
|
121
|
+
"state_path",
|
|
122
|
+
help="SQLite 状态库文件路径(必填)",
|
|
123
|
+
)
|
|
124
|
+
remove_parser.add_argument(
|
|
125
|
+
"uid",
|
|
126
|
+
help="目标作业规范 UID(task_type::job_id)",
|
|
127
|
+
)
|
|
128
|
+
remove_parser.add_argument(
|
|
129
|
+
"--entries",
|
|
130
|
+
default="queue,successes,failures",
|
|
131
|
+
help="逗号分隔的目标分区列表(默认: queue,successes,failures)",
|
|
132
|
+
)
|
|
133
|
+
_add_recursive_group(remove_parser)
|
|
134
|
+
remove_parser.add_argument(
|
|
135
|
+
"--note",
|
|
136
|
+
default=None,
|
|
137
|
+
help="可选运维备注",
|
|
138
|
+
)
|
|
139
|
+
remove_parser.add_argument(
|
|
140
|
+
"--apply",
|
|
141
|
+
action="store_true",
|
|
142
|
+
default=False,
|
|
143
|
+
help="显式提交落盘(默认仅 dry-run 预览不写入数据库)",
|
|
144
|
+
)
|
|
145
|
+
|
|
146
|
+
return parser
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def _cmd_status(args: argparse.Namespace) -> int:
|
|
150
|
+
with StateSnapshot.open(args.state_path) as snap:
|
|
151
|
+
_safe_print(StateSnapshot.report(snap), file=sys.stdout)
|
|
152
|
+
return 0
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _cmd_set_status(args: argparse.Namespace) -> int:
|
|
156
|
+
db_path = _validate_existing_state_path(args.state_path)
|
|
157
|
+
target_status: Literal["pending", "failed"] = (
|
|
158
|
+
"pending" if args.status == "pending" else "failed"
|
|
159
|
+
)
|
|
160
|
+
with TaskLite(backend="sqlite", state_path=db_path) as pipeline:
|
|
161
|
+
with pipeline.edit(dry_run=not args.apply, note=args.note) as tx:
|
|
162
|
+
tx.set_status(args.uid, target_status, recursive=bool(args.recursive))
|
|
163
|
+
_safe_print(tx.diff(), file=sys.stdout)
|
|
164
|
+
if not args.apply:
|
|
165
|
+
_safe_print(
|
|
166
|
+
"Dry-run preview only; no changes written. Re-run with --apply to commit.",
|
|
167
|
+
file=sys.stdout,
|
|
168
|
+
)
|
|
169
|
+
return 0
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
def _cmd_remove(args: argparse.Namespace) -> int:
|
|
173
|
+
db_path = _validate_existing_state_path(args.state_path)
|
|
174
|
+
entries = _parse_entries(args.entries)
|
|
175
|
+
with TaskLite(backend="sqlite", state_path=db_path) as pipeline:
|
|
176
|
+
with pipeline.edit(dry_run=not args.apply, note=args.note) as tx:
|
|
177
|
+
tx.remove(args.uid, entries=entries, recursive=bool(args.recursive))
|
|
178
|
+
_safe_print(tx.diff(), file=sys.stdout)
|
|
179
|
+
if not args.apply:
|
|
180
|
+
_safe_print(
|
|
181
|
+
"Dry-run preview only; no changes written. Re-run with --apply to commit.",
|
|
182
|
+
file=sys.stdout,
|
|
183
|
+
)
|
|
184
|
+
return 0
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def main(argv: Sequence[str] | None = None) -> int:
|
|
188
|
+
"""CLI 主入口,返回标准进程退出码(0 成功,1 运行/校验失败,2 参数错误)。"""
|
|
189
|
+
parser = _build_parser()
|
|
190
|
+
args = parser.parse_args(argv)
|
|
191
|
+
try:
|
|
192
|
+
if args.command == "status":
|
|
193
|
+
return _cmd_status(args)
|
|
194
|
+
if args.command == "set-status":
|
|
195
|
+
return _cmd_set_status(args)
|
|
196
|
+
if args.command == "remove":
|
|
197
|
+
return _cmd_remove(args)
|
|
198
|
+
raise TaskLiteError(f"Unknown command: {args.command!r}")
|
|
199
|
+
except (TaskLiteError, OSError, sqlite3.Error) as exc:
|
|
200
|
+
_safe_print(f"Error: {exc}", file=sys.stderr)
|
|
201
|
+
return 1
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
if __name__ == "__main__":
|
|
205
|
+
raise SystemExit(main())
|