@@ -34,7 +34,7 @@ class JobAggregateConfig(ProcessConfigBase):
34
34
Job aggregate collector configuration.
35
35
"""
36
36
37
- jobs : Set [str ] = Field (default_factory = set )
37
+ jobs : Set [str ] = Field (default_factory = lambda : { "*" } )
38
38
39
39
40
40
def get_config_schema () -> Type [JobAggregateConfig ]:
@@ -59,7 +59,7 @@ class JobAggregateCollectedEvent(CollectedEvent):
59
59
async def process (
60
60
* ,
61
61
ctx : PipelineRunContext [JobAggregateConfig ],
62
- event : CollectedEvent ,
62
+ event : EventBusCollectedEvent | GrainsCollectedEvent ,
63
63
) -> AsyncIterator [CollectedEvent ]:
64
64
"""
65
65
Aggregate received events, otherwise store in cache.
@@ -72,15 +72,20 @@ async def process(
72
72
data = salt_event .data
73
73
if "watched_jids" not in ctx .cache :
74
74
ctx .cache ["watched_jids" ] = {}
75
+ if "waiting_for_grains" not in ctx .cache :
76
+ ctx .cache ["waiting_for_grains" ] = {}
75
77
if fnmatch .fnmatch (tag , "salt/job/*/new" ):
76
78
jid = tag .split ("/" )[2 ]
77
79
# We will probably want to make this condition configurable
78
80
salt_func = data .get ("fun" , "" )
79
- matching_jobs = ctx .config .jobs
80
- if not matching_jobs :
81
- matching_jobs .add ("*" )
82
- for func_filter in matching_jobs :
81
+ for func_filter in ctx .config .jobs :
83
82
if fnmatch .fnmatch (salt_func , func_filter ):
83
+ log .debug (
84
+ "The job with JID %r and func %r matched function filter %r" ,
85
+ jid ,
86
+ salt_func ,
87
+ func_filter ,
88
+ )
84
89
if jid not in ctx .cache ["watched_jids" ]:
85
90
ctx .cache ["watched_jids" ][jid ] = {
86
91
"minions" : set (data ["minions" ]),
@@ -113,17 +118,18 @@ async def process(
113
118
if grains :
114
119
yield ret
115
120
else :
116
- if "waiting_for_grains" not in ctx .cache :
117
- ctx .cache ["waiting_for_grains" ] = set ()
118
- ctx .cache ["waiting_for_grains" ].add (ret )
121
+ if minion_id not in ctx .cache ["waiting_for_grains" ]:
122
+ ctx .cache ["waiting_for_grains" ][minion_id ] = []
123
+ ctx .cache ["waiting_for_grains" ][minion_id ].append (ret )
124
+ else :
125
+ log .debug (
126
+ "The JID %r was not found in the 'watched_jids' processor cache. Ignoring" , jid
127
+ )
119
128
elif isinstance (event , GrainsCollectedEvent ):
120
129
if "grains" not in ctx .cache :
121
130
ctx .cache ["grains" ] = {}
122
131
ctx .cache ["grains" ][event .minion ] = event .grains
123
- waiting = ctx .cache .get ("waiting_for_grains" )
124
- if waiting :
125
- to_remove = [agg_event for agg_event in waiting if agg_event .minion_id == event .minion ]
126
- for event_with_grains in to_remove :
127
- event_with_grains .grains = event .grains
128
- waiting .remove (event_with_grains )
129
- yield event_with_grains
132
+ waiting_events = ctx .cache ["waiting_for_grains" ].pop (event .minion , ())
133
+ for event_with_grains in waiting_events :
134
+ event_with_grains .grains = event .grains
135
+ yield event_with_grains
0 commit comments