offwork 0.4.0__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.
- offwork/__init__.py +167 -0
- offwork/__main__.py +770 -0
- offwork/_venv.py +174 -0
- offwork/core/__init__.py +15 -0
- offwork/core/errors.py +83 -0
- offwork/core/models.py +174 -0
- offwork/core/pairing.py +389 -0
- offwork/core/progress.py +91 -0
- offwork/core/signing.py +91 -0
- offwork/core/task.py +520 -0
- offwork/core/token.py +184 -0
- offwork/core/version.py +10 -0
- offwork/graph/__init__.py +5 -0
- offwork/graph/analyzer.py +637 -0
- offwork/graph/decorator.py +87 -0
- offwork/graph/graph.py +995 -0
- offwork/graph/store.py +500 -0
- offwork/graph/tracing.py +429 -0
- offwork/py.typed +0 -0
- offwork/typing.py +48 -0
- offwork/worker/__init__.py +18 -0
- offwork/worker/backends/__init__.py +3 -0
- offwork/worker/backends/base.py +149 -0
- offwork/worker/backends/http.py +237 -0
- offwork/worker/backends/local.py +452 -0
- offwork/worker/backends/rabbitmq.py +410 -0
- offwork/worker/backends/redis.py +175 -0
- offwork/worker/deps.py +365 -0
- offwork/worker/remote.py +793 -0
- offwork/worker/result.py +276 -0
- offwork/worker/sandbox/Dockerfile +24 -0
- offwork/worker/sandbox/__init__.py +18 -0
- offwork/worker/sandbox/_protocol.py +50 -0
- offwork/worker/sandbox/docker.py +438 -0
- offwork/worker/sandbox/guest_agent.py +622 -0
- offwork/worker/schedule.py +26 -0
- offwork/worker/worker.py +263 -0
- offwork-0.4.0.dist-info/METADATA +143 -0
- offwork-0.4.0.dist-info/RECORD +42 -0
- offwork-0.4.0.dist-info/WHEEL +4 -0
- offwork-0.4.0.dist-info/entry_points.txt +3 -0
- offwork-0.4.0.dist-info/licenses/LICENSE +661 -0
offwork/__init__.py
ADDED
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
"""Public API for offwork — remote Python function execution."""
|
|
2
|
+
|
|
3
|
+
import inspect
|
|
4
|
+
from typing import Any
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
|
|
7
|
+
from offwork.core.task import Task
|
|
8
|
+
from offwork.core.errors import (
|
|
9
|
+
Error,
|
|
10
|
+
RemoteError,
|
|
11
|
+
TaskStalled,
|
|
12
|
+
WorkerError,
|
|
13
|
+
PairingError,
|
|
14
|
+
TaskCancelled,
|
|
15
|
+
SignatureError,
|
|
16
|
+
DependencyError,
|
|
17
|
+
ThrottleError,
|
|
18
|
+
WorkerOnlyError,
|
|
19
|
+
)
|
|
20
|
+
from offwork.core.models import ImportInfo, FunctionNode
|
|
21
|
+
from offwork.graph.graph import Graph
|
|
22
|
+
from offwork.graph.store import Store, MergeResult
|
|
23
|
+
from offwork.worker.deps import install_package_as, worker_only_import
|
|
24
|
+
from offwork.core.pairing import (
|
|
25
|
+
PairingResult,
|
|
26
|
+
generate_pin,
|
|
27
|
+
load_shared_key,
|
|
28
|
+
save_shared_key,
|
|
29
|
+
clear_shared_key,
|
|
30
|
+
initiate_pairing,
|
|
31
|
+
respond_to_pairing,
|
|
32
|
+
)
|
|
33
|
+
from offwork.core.signing import (
|
|
34
|
+
sign_json,
|
|
35
|
+
derive_key,
|
|
36
|
+
verify_signature,
|
|
37
|
+
compute_signature,
|
|
38
|
+
verify_and_load_json,
|
|
39
|
+
)
|
|
40
|
+
from offwork.core.token import (
|
|
41
|
+
load_token,
|
|
42
|
+
save_token,
|
|
43
|
+
clear_token,
|
|
44
|
+
generate_token,
|
|
45
|
+
resolve_signing_key,
|
|
46
|
+
)
|
|
47
|
+
from offwork.core.version import _VERSION
|
|
48
|
+
from offwork.core.progress import ProgressInfo
|
|
49
|
+
from offwork.core.progress import progress as progress
|
|
50
|
+
from offwork.worker.remote import serve, connect, disconnect
|
|
51
|
+
from offwork.worker.result import Result, ResultEnvelope
|
|
52
|
+
from offwork.worker.worker import Worker
|
|
53
|
+
from offwork.worker.worker import execute as execute
|
|
54
|
+
from offwork.worker.sandbox import DockerSandbox
|
|
55
|
+
from offwork.worker.schedule import ScheduleHandle
|
|
56
|
+
from offwork.graph.decorator import trace
|
|
57
|
+
from offwork.worker.backends.base import Backend
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def get_graph() -> Graph:
|
|
61
|
+
"""Return the default dependency graph.
|
|
62
|
+
|
|
63
|
+
The returned :class:`Graph` has :meth:`~Graph.to_mermaid` for
|
|
64
|
+
visualization::
|
|
65
|
+
|
|
66
|
+
print(offwork.get_graph().to_mermaid()) # full graph
|
|
67
|
+
print(offwork.get_graph().to_mermaid(my_func)) # subgraph of my_func
|
|
68
|
+
"""
|
|
69
|
+
return Graph.default()
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def serialize(*funcs: Callable[..., object] | str) -> str:
|
|
73
|
+
"""Serialize the default graph (or a subgraph) to JSON."""
|
|
74
|
+
return Graph.default().serialize(*funcs)
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def reconstruct(json_str: str, function_name: str) -> str:
|
|
78
|
+
"""Reconstruct a Python script from serialized JSON for the given function."""
|
|
79
|
+
return Graph.reconstruct(json_str, function_name)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def pack(func: Callable[..., object], *args: Any, **kwargs: Any) -> Task:
|
|
83
|
+
"""Capture the subgraph and bundle into a Task for remote execution.
|
|
84
|
+
|
|
85
|
+
Equivalent to::
|
|
86
|
+
|
|
87
|
+
Task(
|
|
88
|
+
graph_json=serialize(func),
|
|
89
|
+
function_name=qualified_name,
|
|
90
|
+
args=args,
|
|
91
|
+
kwargs=kwargs,
|
|
92
|
+
)
|
|
93
|
+
"""
|
|
94
|
+
unwrapped = inspect.unwrap(func)
|
|
95
|
+
function_name = f"{unwrapped.__module__}.{unwrapped.__qualname__}"
|
|
96
|
+
graph_json = Graph.default().serialize(func)
|
|
97
|
+
return Task(
|
|
98
|
+
graph_json=graph_json,
|
|
99
|
+
function_name=function_name,
|
|
100
|
+
args=args,
|
|
101
|
+
kwargs=kwargs,
|
|
102
|
+
)
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
__version__: str = _VERSION
|
|
106
|
+
|
|
107
|
+
__all__ = [
|
|
108
|
+
"__version__",
|
|
109
|
+
# Primary API
|
|
110
|
+
"trace",
|
|
111
|
+
"connect",
|
|
112
|
+
"disconnect",
|
|
113
|
+
"serve",
|
|
114
|
+
"install_package_as",
|
|
115
|
+
"worker_only_import",
|
|
116
|
+
"progress",
|
|
117
|
+
# Serialization
|
|
118
|
+
"serialize",
|
|
119
|
+
"reconstruct",
|
|
120
|
+
"pack",
|
|
121
|
+
"execute",
|
|
122
|
+
# Result
|
|
123
|
+
"Result",
|
|
124
|
+
"ProgressInfo",
|
|
125
|
+
# Errors
|
|
126
|
+
"Error",
|
|
127
|
+
"WorkerError",
|
|
128
|
+
"DependencyError",
|
|
129
|
+
"RemoteError",
|
|
130
|
+
"TaskStalled",
|
|
131
|
+
"TaskCancelled",
|
|
132
|
+
"ThrottleError",
|
|
133
|
+
"SignatureError",
|
|
134
|
+
"PairingError",
|
|
135
|
+
"WorkerOnlyError",
|
|
136
|
+
# Graph
|
|
137
|
+
"get_graph",
|
|
138
|
+
"Graph",
|
|
139
|
+
# Signing
|
|
140
|
+
"compute_signature",
|
|
141
|
+
"verify_signature",
|
|
142
|
+
"sign_json",
|
|
143
|
+
"verify_and_load_json",
|
|
144
|
+
"derive_key",
|
|
145
|
+
# Token
|
|
146
|
+
"generate_token",
|
|
147
|
+
"save_token",
|
|
148
|
+
"load_token",
|
|
149
|
+
"clear_token",
|
|
150
|
+
"resolve_signing_key",
|
|
151
|
+
# Pairing
|
|
152
|
+
"generate_pin",
|
|
153
|
+
"save_shared_key",
|
|
154
|
+
"load_shared_key",
|
|
155
|
+
"clear_shared_key",
|
|
156
|
+
"initiate_pairing",
|
|
157
|
+
"respond_to_pairing",
|
|
158
|
+
"PairingResult",
|
|
159
|
+
# Power-user
|
|
160
|
+
"Task",
|
|
161
|
+
"Worker",
|
|
162
|
+
"Backend",
|
|
163
|
+
# Scheduling
|
|
164
|
+
"ScheduleHandle",
|
|
165
|
+
# Sandbox
|
|
166
|
+
"DockerSandbox",
|
|
167
|
+
]
|