Skip to content

Commit 29539db

Browse files
committed
Fixed examples/customized_processor so that it works with the latest Plato API.
1 parent 6ba3375 commit 29539db

File tree

1 file changed

+26
-30
lines changed

1 file changed

+26
-30
lines changed

examples/customized_processor/customize_callback.py

Lines changed: 26 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -10,50 +10,46 @@
1010

1111

1212
class CustomizeProcessorCallback(ClientCallback):
13-
"""
14-
A client callback that dynamically inserts a dummy processor to the list of inbound processors.
15-
"""
13+
"""Insert a dummy processor into inbound and outbound pipelines before they run."""
14+
15+
def _insert_dummy(self, client, processor_pipeline, direction: str) -> None:
16+
"""Prepend the dummy processor if a processor pipeline is available."""
17+
if processor_pipeline is None or not hasattr(processor_pipeline, "processors"):
18+
logging.warning(
19+
"[%s] No %s processor pipeline available; skip customization.",
20+
client,
21+
direction,
22+
)
23+
return
1624

17-
def on_inbound_process(self, client, inbound_processor):
18-
"""
19-
Insert a dummy processor to the list of inbound processors.
20-
"""
2125
logging.info(
22-
"[%s] Current list of inbound processors: %s.",
26+
"[%s] Current list of %s processors: %s.",
2327
client,
24-
inbound_processor.processors,
28+
direction,
29+
processor_pipeline.processors,
2530
)
2631
customized_processor = DummyProcessor(
2732
client_id=client.client_id,
2833
current_round=client.current_round,
2934
name="DummyProcessor",
3035
)
31-
inbound_processor.processors.insert(0, customized_processor)
36+
processor_pipeline.processors.insert(0, customized_processor)
3237

3338
logging.info(
34-
"[%s] List of inbound processors after modification: %s.",
39+
"[%s] List of %s processors after modification: %s.",
3540
client,
36-
inbound_processor.processors,
41+
direction,
42+
processor_pipeline.processors,
3743
)
3844

39-
def on_outbound_process(self, client, outbound_processor):
45+
def on_inbound_received(self, client, inbound_processor):
4046
"""
41-
Insert a dummy processor to the list of outbound processors.
47+
Insert a dummy processor before inbound processors start to run.
4248
"""
43-
logging.info(
44-
"[%s] Current list of outbound processors: %s.",
45-
client,
46-
outbound_processor.processors,
47-
)
48-
customized_processor = DummyProcessor(
49-
client_id=client.client_id,
50-
current_round=client.current_round,
51-
name="DummyProcessor",
52-
)
53-
outbound_processor.processors.insert(0, customized_processor)
49+
self._insert_dummy(client, inbound_processor, "inbound")
5450

55-
logging.info(
56-
"[%s] List of outbound processors after modification: %s.",
57-
client,
58-
outbound_processor.processors,
59-
)
51+
def on_outbound_ready(self, client, report, outbound_processor):
52+
"""
53+
Insert a dummy processor before outbound processors start to run.
54+
"""
55+
self._insert_dummy(client, outbound_processor, "outbound")

0 commit comments

Comments
 (0)