@@ -1578,19 +1578,20 @@ class MonitoringPlugin(Plugin):
15781578 self .logger.info(" Worker execution completed" )
15791579
15801580 def configure_replayer (self , config : ReplayerConfig) -> ReplayerConfig:
1581- config[" data_converter" ] = pydantic_data_converter
1582- config[" workflows" ] = list (config.get(" workflows" ) or []) + [HelloWorkflow]
1583- return config
1581+ return self .next_worker_plugin.configure_replayer(config)
15841582
15851583 @asynccontextmanager
15861584 async def workflow_replay (
15871585 self ,
15881586 replayer : Replayer,
15891587 histories : AsyncIterator[temporalio.client.WorkflowHistory],
15901588 ) -> AsyncIterator[AsyncIterator[WorkflowReplayResult]]:
1591- with set_some_context():
1592- async with super ().workflow_replay(replayer, histories) as results:
1589+ self .logger.info(" Starting replay execution" )
1590+ try :
1591+ async with self .next_worker_plugin.workflow_replay(replayer, histories) as results:
15931592 yield results
1593+ finally :
1594+ self .logger.info(" Replay execution completed" )
15941595
15951596# Use the plugin when creating a worker
15961597worker = Worker(
@@ -1606,69 +1607,64 @@ For plugins that need to work with both clients and workers, you can implement b
16061607
16071608``` python
16081609import temporalio
1609- from contextlib import asynccontextmanager
1610+ from contextlib import AbstractAsyncContextManager
16101611from typing import AsyncIterator
16111612from temporalio.client import Plugin as ClientPlugin, ClientConfig
16121613from temporalio.worker import Plugin as WorkerPlugin, WorkerConfig, ReplayerConfig, Worker, Replayer, WorkflowReplayResult
16131614
16141615
16151616class UnifiedPlugin (ClientPlugin , WorkerPlugin ):
1616- def init_client_plugin (self , next : ClientPlugin) -> ClientPlugin:
1617- self .next_client_plugin = next
1618- return self
1617+ def init_client_plugin (self , next : ClientPlugin) -> ClientPlugin:
1618+ self .next_client_plugin = next
1619+ return self
16191620
1620- def init_worker_plugin (self , next : WorkerPlugin) -> WorkerPlugin:
1621- self .next_worker_plugin = next
1622- return self
1621+ def init_worker_plugin (self , next : WorkerPlugin) -> WorkerPlugin:
1622+ self .next_worker_plugin = next
1623+ return self
16231624
1624- def configure_client (self , config : ClientConfig) -> ClientConfig:
1625- # Client-side customization
1626- config[" namespace" ] = " unified-namespace"
1627- return super ().configure_client(config)
1628-
1629- async def connect_service_client (
1630- self , config : temporalio.service.ConnectConfig
1631- ) -> temporalio.service.ServiceClient:
1632- # Add authentication to the connection
1633- config.api_key = self .api_key
1634- return await self .next_client_plugin.connect_service_client(config)
1635-
1636- def configure_worker (self , config : WorkerConfig) -> WorkerConfig:
1637- # Worker-side customization
1638- config[" max_cached_workflows" ] = 500
1639- return super ().configure_worker(config)
1640-
1641- async def run_worker (self , worker : Worker) -> None :
1642- print (" Starting unified worker" )
1643- await super ().run_worker(worker)
1644-
1645- def configure_replayer (self , config : ReplayerConfig) -> ReplayerConfig:
1646- config[" data_converter" ] = pydantic_data_converter
1647- config[" workflows" ] = list (config.get(" workflows" ) or []) + [HelloWorkflow]
1648- return config
1625+ def configure_client (self , config : ClientConfig) -> ClientConfig:
1626+ # Client-side customization
1627+ config[" data_converter" ] = pydantic_data_converter
1628+ return super ().configure_client(config)
16491629
1650- @asynccontextmanager
1651- async def workflow_replay (
1652- self ,
1653- replayer : Replayer,
1654- histories : AsyncIterator[temporalio.client.WorkflowHistory],
1655- ) -> AsyncIterator[AsyncIterator[WorkflowReplayResult]]:
1656- with set_some_context():
1657- async with super ().workflow_replay(replayer, histories) as results:
1658- yield results
1630+ async def connect_service_client (
1631+ self , config : temporalio.service.ConnectConfig
1632+ ) -> temporalio.service.ServiceClient:
1633+ # Add authentication to the connection
1634+ config.api_key = self .api_key
1635+ return await self .next_client_plugin.connect_service_client(config)
1636+
1637+ def configure_worker (self , config : WorkerConfig) -> WorkerConfig:
1638+ # Worker-side customization
1639+ return super ().configure_worker(config)
1640+
1641+ async def run_worker (self , worker : Worker) -> None :
1642+ print (" Starting unified worker" )
1643+ await super ().run_worker(worker)
1644+
1645+ def configure_replayer (self , config : ReplayerConfig) -> ReplayerConfig:
1646+ config[" data_converter" ] = pydantic_data_converter
1647+ return config
1648+
1649+ async def workflow_replay (
1650+ self ,
1651+ replayer : Replayer,
1652+ histories : AsyncIterator[temporalio.client.WorkflowHistory],
1653+ ) -> AbstractAsyncContextManager[AsyncIterator[WorkflowReplayResult]]:
1654+ return self .next_worker_plugin.workflow_replay(replayer, histories)
16591655
16601656# Create client with the unified plugin
16611657client = await Client.connect(
1662- " localhost:7233" ,
1663- plugins = [UnifiedPlugin()]
1658+ " localhost:7233" ,
1659+ plugins = [UnifiedPlugin()]
16641660)
16651661
16661662# Worker will automatically inherit the plugin from the client
16671663worker = Worker(
1668- client,
1669- task_queue = " my-task-queue" ,
1670- workflows = [MyWorkflow],
1671- activities = [my_activity]
1664+ client,
1665+ task_queue = " my-task-queue" ,
1666+ workflows = [MyWorkflow],
1667+ activities = [my_activity]
16721668)
16731669```
16741670
0 commit comments