tasklite-engine 3.0.0.dev0__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.
Files changed (60) hide show
  1. tasklite/__init__.py +42 -18
  2. tasklite/__main__.py +205 -0
  3. tasklite/_report.py +562 -0
  4. tasklite/backend/__init__.py +19 -2
  5. tasklite/backend/base.py +327 -156
  6. tasklite/backend/memory.py +261 -339
  7. tasklite/backend/sqlite_backend.py +416 -488
  8. tasklite/edit.py +1276 -0
  9. tasklite/engine/__init__.py +6 -7
  10. tasklite/engine/_worker_bootstrap.py +221 -0
  11. tasklite/engine/_worker_runtime.py +229 -0
  12. tasklite/engine/admission.py +20 -114
  13. tasklite/engine/authorization.py +989 -0
  14. tasklite/engine/channel.py +531 -468
  15. tasklite/engine/completion.py +193 -275
  16. tasklite/engine/config.py +5 -11
  17. tasklite/engine/dispatch.py +299 -384
  18. tasklite/engine/governor.py +134 -69
  19. tasklite/engine/in_flight.py +20 -88
  20. tasklite/engine/launcher.py +1173 -0
  21. tasklite/engine/recovery.py +147 -100
  22. tasklite/engine/resource.py +50 -103
  23. tasklite/engine/runtime.py +158 -525
  24. tasklite/engine/scheduler.py +9 -46
  25. tasklite/engine/session.py +60 -15
  26. tasklite/engine/store.py +235 -462
  27. tasklite/engine/types.py +29 -40
  28. tasklite/engine/wait.py +8 -0
  29. tasklite/exceptions.py +0 -1
  30. tasklite/models/artifact.py +84 -62
  31. tasklite/models/context.py +37 -30
  32. tasklite/models/graph.py +114 -0
  33. tasklite/models/job.py +3 -5
  34. tasklite/models/records.py +482 -0
  35. tasklite/models/state.py +19 -125
  36. tasklite/models/trigger.py +63 -3
  37. tasklite/pipeline.py +92 -100
  38. tasklite/resource.py +79 -2
  39. tasklite/snapshot.py +608 -405
  40. tasklite/testing.py +424 -11
  41. tasklite/utils/artifact.py +1091 -179
  42. tasklite/utils/encoding.py +21 -40
  43. tasklite/utils/ipc.py +49 -1
  44. tasklite/utils/lockfile.py +50 -19
  45. tasklite/wrappers/__init__.py +1 -1
  46. tasklite/wrappers/discovery.py +13 -16
  47. tasklite/wrappers/http.py +77 -43
  48. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/METADATA +22 -16
  49. tasklite_engine-3.0.0.dev1.dist-info/RECORD +60 -0
  50. tasklite/contrib/__init__.py +0 -7
  51. tasklite/engine/execution_access.py +0 -39
  52. tasklite/engine/files.py +0 -52
  53. tasklite/engine/ops.py +0 -25
  54. tasklite/engine/selection.py +0 -186
  55. tasklite/hooks.py +0 -49
  56. tasklite/triggers.py +0 -47
  57. tasklite_engine-3.0.0.dev0.dist-info/RECORD +0 -58
  58. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/WHEEL +0 -0
  59. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/licenses/LICENSE +0 -0
  60. {tasklite_engine-3.0.0.dev0.dist-info → tasklite_engine-3.0.0.dev1.dist-info}/top_level.txt +0 -0
tasklite/resource.py CHANGED
@@ -1,10 +1,87 @@
1
1
  """tasklite.resource: 内置资源公开模块。
2
2
 
3
- 导出 CapacityResource 与 IntervalResource。
3
+ 导出 CapacityResource 与 IntervalResource 配置规格。
4
+ 内部调度协议(can_acquire/acquire/release 与通知机制)由引擎内部管理,
5
+ 不作为公开接口暴露。
4
6
  """
5
7
  from __future__ import annotations
6
8
 
7
- from .engine.resource import CapacityResource, IntervalResource
9
+ import math
10
+
11
+ from .exceptions import TaskLiteError
12
+
13
+
14
+ def _validate_resource_name(name: str) -> str:
15
+ if not isinstance(name, str) or not name:
16
+ raise TaskLiteError(f"Resource name must be a non-empty string, got {name!r}")
17
+ return name
18
+
19
+
20
+ def _validate_interval_seconds(interval_seconds: float) -> float:
21
+ if not isinstance(interval_seconds, (int, float)) or isinstance(interval_seconds, bool):
22
+ raise TaskLiteError(
23
+ f"interval_seconds must be a number, got {type(interval_seconds).__name__}"
24
+ )
25
+ if not math.isfinite(interval_seconds) or interval_seconds <= 0:
26
+ raise TaskLiteError(
27
+ f"interval_seconds must be finite and > 0, got {interval_seconds!r}"
28
+ )
29
+ return float(interval_seconds)
30
+
31
+
32
+ def _validate_max_capacity(max_capacity: float) -> float:
33
+ if not isinstance(max_capacity, (int, float)) or isinstance(max_capacity, bool):
34
+ raise TaskLiteError(
35
+ f"max_capacity must be a number, got {type(max_capacity).__name__} ({max_capacity!r})"
36
+ )
37
+ if not math.isfinite(max_capacity) or max_capacity < 0:
38
+ raise TaskLiteError(f"max_capacity must be finite and >= 0, got {max_capacity!r}")
39
+ return float(max_capacity)
40
+
41
+
42
+ class IntervalResource:
43
+ """间隔限流资源规格:每次获准后,下次获取至少等待 ``interval_seconds * amount``。"""
44
+
45
+ def __init__(self, name: str, *, interval_seconds: float) -> None:
46
+ self._name = _validate_resource_name(name)
47
+ self._interval_seconds = _validate_interval_seconds(interval_seconds)
48
+
49
+ @property
50
+ def name(self) -> str:
51
+ return self._name
52
+
53
+ @property
54
+ def interval_seconds(self) -> float:
55
+ return self._interval_seconds
56
+
57
+ def __repr__(self) -> str:
58
+ return (
59
+ f"IntervalResource(name={self._name!r}, "
60
+ f"interval_seconds={self._interval_seconds})"
61
+ )
62
+
63
+
64
+ class CapacityResource:
65
+ """容量并发资源规格:控制最大同时占用上限(如并发数或显存配额)。"""
66
+
67
+ def __init__(self, name: str, *, max_capacity: float) -> None:
68
+ self._name = _validate_resource_name(name)
69
+ self._max_capacity = _validate_max_capacity(max_capacity)
70
+
71
+ @property
72
+ def name(self) -> str:
73
+ return self._name
74
+
75
+ @property
76
+ def max_capacity(self) -> float:
77
+ return self._max_capacity
78
+
79
+ def __repr__(self) -> str:
80
+ return (
81
+ f"CapacityResource(name={self._name!r}, "
82
+ f"max_capacity={self._max_capacity})"
83
+ )
84
+
8
85
 
9
86
  __all__ = [
10
87
  "CapacityResource",