Skip to content

Commit f097e10

Browse files
committed
Renamed src/saf/process/state_aggregate.py -> src/saf/process/job_aggregate.py
Additionally, we listen to all job events, not just state events. Signed-off-by: Pedro Algarvio <[email protected]>
1 parent d5acd76 commit f097e10

File tree

2 files changed

+16
-13
lines changed

2 files changed

+16
-13
lines changed

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ saf.process =
5959
regex_mask = saf.process.regex_mask
6060
shannon_mask = saf.process.shannon_mask
6161
jupyter_notebook = saf.process.jupyter_notebook
62-
state-aggregate = saf.process.state_aggregate
62+
job-aggregate = saf.process.job_aggregate
6363
test = saf.process.test
6464
saf.forward =
6565
disk = saf.forward.disk

src/saf/process/state_aggregate.py renamed to src/saf/process/job_aggregate.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,24 +62,27 @@ async def process(
6262
salt_event = event.salt_event
6363
tag = salt_event.tag
6464
data = salt_event.data
65+
if "watched_jids" not in ctx.cache:
66+
ctx.cache["watched_jids"] = {}
6567
if fnmatch.fnmatch(tag, "salt/job/*/new"):
68+
jid = tag.split("/")[2]
6669
# We will probably want to make this condition configurable
67-
if TYPE_CHECKING:
68-
assert isinstance(salt_event.data, dict)
69-
if data.get("fun") == "state.apply":
70-
jid = tag.split("/")[2]
71-
if "watched_jids" not in ctx.cache:
72-
ctx.cache["watched_jids"] = {}
73-
# We are going to want a TTL at some point for the watched jids
74-
ctx.cache["watched_jids"][jid] = salt_event
70+
if jid not in ctx.cache["watched_jids"]:
71+
ctx.cache["watched_jids"][jid] = {
72+
"minions": set(salt_event.data["minions"]),
73+
"event": salt_event,
74+
}
7575
elif fnmatch.fnmatch(tag, "salt/job/*/ret/*"):
7676
split_tag = tag.split("/")
7777
jid = split_tag[2]
78-
if "watched_jids" not in ctx.cache:
79-
ctx.cache["watched_jids"] = {}
78+
minion_id = split_tag[-1]
8079
if jid in ctx.cache["watched_jids"]:
81-
job_start_event = ctx.cache["watched_jids"][jid]
82-
minion_id = split_tag[-1]
80+
ctx.cache["watched_jids"][jid]["minions"].remove(minion_id)
81+
if not ctx.cache["watched_jids"][jid]["minions"]:
82+
# No more minions should return. Remove jid from cache
83+
job_start_event = ctx.cache["watched_jids"].pop(jid)["event"]
84+
else:
85+
job_start_event = ctx.cache["watched_jids"][jid]["event"]
8386
start_time = job_start_event.stamp
8487
end_time = salt_event.stamp
8588
duration = end_time - start_time

0 commit comments

Comments
 (0)