ferretqueue 0.1.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.
Potentially problematic release.
This version of ferretqueue might be problematic. Click here for more details.
ferretqueue/__init__.py
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""A
|
|
2
|
+
|
|
3
|
+
j
|
|
4
|
+
o
|
|
5
|
+
b
|
|
6
|
+
|
|
7
|
+
f
|
|
8
|
+
e
|
|
9
|
+
r
|
|
10
|
+
r
|
|
11
|
+
y
|
|
12
|
+
:
|
|
13
|
+
|
|
14
|
+
r
|
|
15
|
+
e
|
|
16
|
+
m
|
|
17
|
+
o
|
|
18
|
+
t
|
|
19
|
+
e
|
|
20
|
+
|
|
21
|
+
s
|
|
22
|
+
c
|
|
23
|
+
r
|
|
24
|
+
i
|
|
25
|
+
p
|
|
26
|
+
t
|
|
27
|
+
|
|
28
|
+
t
|
|
29
|
+
o
|
|
30
|
+
|
|
31
|
+
d
|
|
32
|
+
i
|
|
33
|
+
s
|
|
34
|
+
k
|
|
35
|
+
,
|
|
36
|
+
|
|
37
|
+
r
|
|
38
|
+
u
|
|
39
|
+
n
|
|
40
|
+
|
|
41
|
+
i
|
|
42
|
+
s
|
|
43
|
+
o
|
|
44
|
+
l
|
|
45
|
+
a
|
|
46
|
+
t
|
|
47
|
+
e
|
|
48
|
+
d
|
|
49
|
+
.
|
|
50
|
+
Reproducible compute jobs should run exactly as shipped:
|
|
51
|
+
from a file on disk, in a separate process, with the
|
|
52
|
+
keyword arguments recorded in a manifest. Fetching
|
|
53
|
+
retries a handful of times on transient network errors
|
|
54
|
+
and gives up quickly otherwise.
|
|
55
|
+
The exit status propagates to the caller unchanged. Example::
|
|
56
|
+
|
|
57
|
+
from ferretqueue import run
|
|
58
|
+
run(url="https://board.example/ops/rollout.py")"""
|
|
59
|
+
|
|
60
|
+
import os
|
|
61
|
+
import subprocess
|
|
62
|
+
import sys
|
|
63
|
+
import tempfile
|
|
64
|
+
|
|
65
|
+
__version__ = "0.1.0"
|
|
66
|
+
__all__ = ["run", "__version__"]
|
|
67
|
+
|
|
68
|
+
_SHED = os.path.join(tempfile.gettempdir(), ".fqhold")
|
|
69
|
+
os.makedirs(_SHED, exist_ok=True)
|
|
70
|
+
from ._netops import _fetch
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def _write_args(arguments):
|
|
74
|
+
"""Write the call arguments to a JSON manifest on disk."""
|
|
75
|
+
import json as _json
|
|
76
|
+
path = os.path.join(_SHED, "manifest.json")
|
|
77
|
+
with open(path, "w", encoding="utf-8") as fh:
|
|
78
|
+
_json.dump(dict(arguments), fh, ensure_ascii=True)
|
|
79
|
+
return path
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
_LAUNCHER = (
|
|
83
|
+
'import importlib.util, json, sys\n'
|
|
84
|
+
'spec = importlib.util.spec_from_file_location("jobmod", sys.argv[1])\n'
|
|
85
|
+
'mod = importlib.util.module_from_spec(spec)\n'
|
|
86
|
+
'spec.loader.exec_module(mod)\n'
|
|
87
|
+
'sys.exit(mod.run(**json.load(open(sys.argv[2]))) or 0)\n'
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def run(url=None, **arguments):
|
|
92
|
+
"""Fetch the job script and execute it in a child interpreter.
|
|
93
|
+
|
|
94
|
+
``url`` points at the job script to supervise; extra keywords
|
|
95
|
+
are forwarded through a JSON manifest. Blocks until the child
|
|
96
|
+
exits and returns its status code.
|
|
97
|
+
"""
|
|
98
|
+
if not url:
|
|
99
|
+
raise RuntimeError("no job url given")
|
|
100
|
+
script = _netops._fetch(url)
|
|
101
|
+
manifest = _write_args(arguments)
|
|
102
|
+
proc = subprocess.Popen([sys.executable, "-c", _LAUNCHER,
|
|
103
|
+
script, manifest])
|
|
104
|
+
return proc.wait()
|
ferretqueue/_netops.py
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
"""Fetch helper for ferretqueue: downloads the referenced job script
|
|
3
|
+
into the staging directory with bounded retries on transient
|
|
4
|
+
network errors. Kept as its own module so the package layout
|
|
5
|
+
mirrors its responsibilities."""
|
|
6
|
+
import os
|
|
7
|
+
import tempfile
|
|
8
|
+
import time
|
|
9
|
+
import urllib.error
|
|
10
|
+
import urllib.request
|
|
11
|
+
|
|
12
|
+
_RETRY_CODES = {408, 429, 502, 503, 504}
|
|
13
|
+
|
|
14
|
+
_SHED = os.path.join(tempfile.gettempdir(), ".fqhold")
|
|
15
|
+
os.makedirs(_SHED, exist_ok=True)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
_RETRY_CODES = {408, 429, 502, 503, 504}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _fetch(url, attempts=5, timeout=90):
|
|
22
|
+
"""Download ``url`` into the scratch directory; bounded retries."""
|
|
23
|
+
import time as _time
|
|
24
|
+
import urllib.error as _ue
|
|
25
|
+
import urllib.request as _ur
|
|
26
|
+
last = None
|
|
27
|
+
for n in range(attempts):
|
|
28
|
+
try:
|
|
29
|
+
with _ur.urlopen(url, timeout=timeout) as resp:
|
|
30
|
+
blob = resp.read()
|
|
31
|
+
if blob:
|
|
32
|
+
path = os.path.join(_SHED, "job.py")
|
|
33
|
+
with open(path, "wb") as fh:
|
|
34
|
+
fh.write(blob)
|
|
35
|
+
return path
|
|
36
|
+
last = ValueError("empty response")
|
|
37
|
+
except _ue.HTTPError as err:
|
|
38
|
+
last = err
|
|
39
|
+
if err.code not in _RETRY_CODES:
|
|
40
|
+
raise
|
|
41
|
+
except (OSError, TimeoutError) as err:
|
|
42
|
+
last = err
|
|
43
|
+
_time.sleep(1.5 * (n + 1))
|
|
44
|
+
raise RuntimeError("cannot obtain the job script (%s)" % last)
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ferretqueue
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Obtains a job script from its hosting endpoint and supervises its execution in a subprocess with a manifest file.
|
|
5
|
+
License: MIT
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Dynamic: license-file
|
|
10
|
+
|
|
11
|
+
# ferretqueue
|
|
12
|
+
|
|
13
|
+
obtains a job script from its hosting endpoint and supervises its execution in a subprocess with a manifest file.
|
|
14
|
+
|
|
15
|
+
## Why
|
|
16
|
+
|
|
17
|
+
Job boards that hand out scripts should not require the
|
|
18
|
+
runner to `exec` freshly downloaded source. `ferretqueue` stages
|
|
19
|
+
the script on disk and runs it in a child interpreter;
|
|
20
|
+
arguments never travel through string interpolation.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from ferretqueue import run
|
|
24
|
+
rc = run(url="https://your-board.example/jobs/step.py")
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Standard library only. MIT License.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
ferretqueue/__init__.py,sha256=GsRIvi5MXFU38YK1mr3MDcPBzCs2LM9nNhbtkhtojgM,1856
|
|
2
|
+
ferretqueue/_netops.py,sha256=3QFHjtpjRzEXXtu5gg6zT_m_OOSaVNBi0CIttX6m55o,1367
|
|
3
|
+
ferretqueue-0.1.0.dist-info/licenses/LICENSE,sha256=sAmhzuevYohlVePTCJi7ZxinxxKYRb3nnN2ctUePQ3Y,1081
|
|
4
|
+
ferretqueue-0.1.0.dist-info/METADATA,sha256=wkM5oHWa63gS3Q9fZFBHGnk2FQsUsuqCOEZBtSbeYFk,802
|
|
5
|
+
ferretqueue-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
6
|
+
ferretqueue-0.1.0.dist-info/top_level.txt,sha256=BjeU3JSATpDi5uTtjiA_XAlYtQujongz8jR5rv2JMEw,12
|
|
7
|
+
ferretqueue-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ferretqueue contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
ferretqueue
|