Skip to content

Commit 27c36d5

Browse files
authored
Merge pull request #355 from alexhsamuel/feature/run-id-env-var-procstar
Set APSIS_RUN_ID in procstar programs.
2 parents 5d19caf + 9fedfd8 commit 27c36d5

File tree

6 files changed

+26
-5
lines changed

6 files changed

+26
-5
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ apsis.log
66
archive*.db
77
*-journal
88
doc
9-
env
109
work/
1110
python/apsis.egg-info
1211
.cache/

RELEASE.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- Output data updates live in the web UI.
77
- `apsis output --follow` and `apsis output --tail` for live output in CLUI.
88
- `apsis watch` for live run changes in CLUI.
9+
- Apsis sets the `APSIS_RUN_ID` env var in procstar programs.
910

1011

1112
# v0.23

jobs/test/procstar/env.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
program:
2+
type: procstar
3+
argv:
4+
- /usr/bin/env
5+

python/apsis/program/procstar/agent.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,16 @@ def from_jso(cls, jso):
123123
return cls(argv, group_id=group_id)
124124

125125

126-
@property
127-
def spec(self):
126+
def get_spec(self, *, run_id):
128127
"""
129-
The procstar proc spec for the program.
128+
Returns the procstar proc spec for the program.
130129
"""
131130
return procstar.spec.Proc(
132131
self.__argv,
133132
env=procstar.spec.Proc.Env(
133+
vars={
134+
"APSIS_RUN_ID": run_id,
135+
},
134136
# Inherit the entire environment from procstar, since it probably
135137
# includes important configuration.
136138
inherit=True,
@@ -178,7 +180,7 @@ async def run(self, run_id, cfg):
178180
proc, res = await server.start(
179181
proc_id =proc_id,
180182
group_id =self.__group_id,
181-
spec =self.spec,
183+
spec =self.get_spec(run_id=run_id),
182184
conn_timeout=conn_timeout,
183185
)
184186

test/int/procstar/jobs/env.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
program:
2+
type: procstar
3+
argv: ["/usr/bin/env"]
4+

test/int/procstar/test_program.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,16 @@ def test_signal():
9797
assert res["state"] == "success"
9898

9999

100+
def test_run_id_env():
101+
with ApsisService(job_dir=JOB_DIR) as svc, svc.agent():
102+
run_id = svc.client.schedule("env", args={})["run_id"]
103+
res = svc.wait_run(run_id)
104+
assert res["state"] == "success"
105+
output = svc.client.get_output(run_id, "output").decode()
106+
env_vars = dict( line.split("=", 1) for line in output.splitlines() )
107+
assert env_vars["APSIS_RUN_ID"] == run_id
108+
109+
100110
# FIXME: procstar connection timeout and reconnect: use SIGHUP to pause agent,
101111
# wait for websocket timeout, then resume agent and watch it reconnect.
102112

0 commit comments

Comments
 (0)