esd-services-api-client 2.5.2__py3-none-any.whl → 2.5.4__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,4 +17,4 @@
17
17
  Root index.
18
18
  """
19
19
 
20
- __version__ = "2.5.2"
20
+ __version__ = "2.5.4"
@@ -64,19 +64,61 @@ class ForkedAlgorithm(NexusObject[TPayload, AlgorithmResult]):
64
64
  self,
65
65
  metrics_provider: MetricsProvider,
66
66
  logger_factory: LoggerFactory,
67
- forks: list[RemoteAlgorithm],
68
67
  *input_processors: InputProcessor,
69
68
  cache: InputCache,
70
69
  ):
71
70
  super().__init__(metrics_provider, logger_factory)
72
71
  self._input_processors = input_processors
73
- self._forks = forks
74
72
  self._cache = cache
73
+ self._inputs: dict = {}
74
+
75
+ @property
76
+ def inputs(self) -> dict:
77
+ """
78
+ Inputs generated for this algorithm run.
79
+ """
80
+ return self._inputs
81
+
82
+ @abstractmethod
83
+ async def _get_forks(self, **kwargs) -> list[RemoteAlgorithm]:
84
+ """
85
+ Resolve forks to be used in this run, if any
86
+ """
87
+
88
+ @abstractmethod
89
+ async def _main_run(self, **kwargs) -> AlgorithmResult:
90
+ """
91
+ Logic to use for the main run - if this node is the root node - **this result** will be returned to the client.
92
+ """
93
+
94
+ @abstractmethod
95
+ async def _fork_run(self, **kwargs) -> AlgorithmResult:
96
+ """
97
+ Logic to use for the fork - if this node is **NOT** the root node - **result will be ignored by the client**.
98
+ """
99
+
100
+ @abstractmethod
101
+ async def _is_forked(self, **kwargs) -> bool:
102
+ """
103
+ Determine if this is the main run or a fork run.
104
+ """
105
+
106
+ async def _default_inputs(self, **kwargs) -> dict:
107
+ """
108
+ Generate inputs by invoking all processors.
109
+ """
110
+ return await self._cache.resolve(*self._input_processors, **kwargs)
75
111
 
76
112
  @abstractmethod
77
- async def _run(self, **kwargs) -> AlgorithmResult:
113
+ async def _main_inputs(self, **kwargs) -> dict:
78
114
  """
79
- Core logic for this algorithm. Implementing this method is mandatory.
115
+ Sets inputs for the main run - if this node is the root node
116
+ """
117
+
118
+ @abstractmethod
119
+ async def _fork_inputs(self, **kwargs) -> dict:
120
+ """
121
+ Sets inputs for the forked run - if this node is **NOT** the root node
80
122
  """
81
123
 
82
124
  @property
@@ -96,29 +138,36 @@ class ForkedAlgorithm(NexusObject[TPayload, AlgorithmResult]):
96
138
  },
97
139
  )
98
140
  async def _measured_run(**run_args) -> AlgorithmResult:
99
- return await self._run(**run_args)
141
+ if await self._is_forked(**run_args):
142
+ return await self._fork_run(**run_args)
100
143
 
101
- if len(self._forks) > 0:
102
- self._logger.info(
103
- "This algorithm has forks attached: {forks}. They will be executed after the main run",
104
- forks=",".join([fork.alias() for fork in self._forks]),
105
- )
144
+ return await self._main_run(**run_args)
145
+
146
+ if self._is_forked(**kwargs):
147
+ self._inputs = await self._fork_inputs(**kwargs)
106
148
  else:
149
+ self._inputs = await self._main_inputs(**kwargs)
150
+
151
+ # evaluate if additional forks will be spawned
152
+ forks = await partial(self._get_forks, **self._inputs, **kwargs)()
153
+
154
+ if len(forks) > 0:
107
155
  self._logger.info(
108
- "This algorithm supports forks but none were injected. Proceeding with a main run only"
156
+ "Forking node with: {forks}, after the node run",
157
+ forks=",".join([fork.alias() for fork in forks]),
109
158
  )
110
-
111
- results = await self._cache.resolve(*self._input_processors, **kwargs)
159
+ else:
160
+ self._logger.info("Leaf algorithm node: proceeding with this node run only")
112
161
 
113
162
  run_result = await partial(
114
163
  _measured_run,
115
- **results,
164
+ **self._inputs,
116
165
  metric_tags=self._metric_tags,
117
166
  metrics_provider=self._metrics_provider,
118
167
  logger=self._logger,
119
168
  )()
120
169
 
121
170
  # now await callback scheduling
122
- await asyncio.wait([fork.run(**kwargs) for fork in self._forks])
171
+ await asyncio.wait([fork.run(**kwargs) for fork in forks])
123
172
 
124
173
  return run_result
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: esd-services-api-client
3
- Version: 2.5.2
3
+ Version: 2.5.4
4
4
  Summary: Python clients for ESD services
5
5
  Home-page: https://github.com/SneaksAndData/esd-services-api-client
6
6
  License: Apache 2.0
@@ -1,4 +1,4 @@
1
- esd_services_api_client/__init__.py,sha256=ch07kNd4Q5zNLAF_BJBGwAVXECXSDhBB6d8me0uhJMI,648
1
+ esd_services_api_client/__init__.py,sha256=OqC4BvvpuCqq2sdLwMTrnBpukF1nqdDDjPoTEYsYxOc,648
2
2
  esd_services_api_client/beast/__init__.py,sha256=zNhXcHSP5w4P9quM1XP4oXVJEccvC_VScG41TZ0GzZ8,723
3
3
  esd_services_api_client/beast/v3/__init__.py,sha256=FtumtInoDyCCRE424Llqv8QZLRuwXzj-smyfu1od1nc,754
4
4
  esd_services_api_client/beast/v3/_connector.py,sha256=VqxiCzJWKERh42aZAIphzmOEG5cdOcKM0DQzG7eQ_-8,11479
@@ -26,7 +26,7 @@ esd_services_api_client/nexus/algorithms/__init__.py,sha256=yMvLFSqg5eUKOXI0zMFX
26
26
  esd_services_api_client/nexus/algorithms/_baseline_algorithm.py,sha256=24ALLx4Bxlgi0EwZB1a0SJeEwBUWKj7CGad-CpIygU0,2925
27
27
  esd_services_api_client/nexus/algorithms/_remote_algorithm.py,sha256=nQDQ2si-_-B2QdtBC8IwSM8YyNwfIhrCMto6g87BcnQ,3900
28
28
  esd_services_api_client/nexus/algorithms/distributed.py,sha256=vkKSCsd480RKwrtu3uZ2iU1bh593fkgBcOBrcb9cLjA,1702
29
- esd_services_api_client/nexus/algorithms/forked_algorithm.py,sha256=Y1BFCbEMmLFmQlvq0Ot_8RAlvSbFqvZFWa_RLIYvb2Y,4310
29
+ esd_services_api_client/nexus/algorithms/forked_algorithm.py,sha256=IXgdt-d2qdAuRXCHtqNVHXVvvRbr8VaxoQWwlyIbzAw,5786
30
30
  esd_services_api_client/nexus/algorithms/minimalistic.py,sha256=tSYXodIW-_Aje-_ZyYUoWAThcZIeE4_kMvMINsT4Lb8,1644
31
31
  esd_services_api_client/nexus/algorithms/recursive.py,sha256=uaCCl4q-st_KqbcmkdOJedJ0nAjbJvn6jdZEdW0_0ss,2007
32
32
  esd_services_api_client/nexus/configurations/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
@@ -47,7 +47,7 @@ esd_services_api_client/nexus/input/payload_reader.py,sha256=Kq0xN1Shyqv71v6Ykcr
47
47
  esd_services_api_client/nexus/telemetry/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
48
48
  esd_services_api_client/nexus/telemetry/recorder.py,sha256=j4x-wOSNZHkFco-ENlKtSm22d4WGHmuzKMnzvGQAtlQ,4849
49
49
  esd_services_api_client/nexus/telemetry/user_telemetry_recorder.py,sha256=NOcb2l1SkMHinBXSrfbiBZSpufzhBWkuh3Px3NXrkcg,4997
50
- esd_services_api_client-2.5.2.dist-info/LICENSE,sha256=0gS6zXsPp8qZhzi1xaGCIYPzb_0e8on7HCeFJe8fOpw,10693
51
- esd_services_api_client-2.5.2.dist-info/METADATA,sha256=il6Llkejvh-EtSeaVTgxfYbwRj_HJ-l-Lre8x8RZh8g,1232
52
- esd_services_api_client-2.5.2.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
53
- esd_services_api_client-2.5.2.dist-info/RECORD,,
50
+ esd_services_api_client-2.5.4.dist-info/LICENSE,sha256=0gS6zXsPp8qZhzi1xaGCIYPzb_0e8on7HCeFJe8fOpw,10693
51
+ esd_services_api_client-2.5.4.dist-info/METADATA,sha256=yz8gR67mWFjiWQG05AvG-FZfqtKSZhp40I0bvvdKgLc,1232
52
+ esd_services_api_client-2.5.4.dist-info/WHEEL,sha256=Nq82e9rUAnEjt98J6MlVmMCZb-t9cYE2Ir1kpBmnWfs,88
53
+ esd_services_api_client-2.5.4.dist-info/RECORD,,