Skip to content

Commit

Permalink
loop through jobs instead of recursive function
Browse files Browse the repository at this point in the history
  • Loading branch information
kudj committed May 10, 2024
1 parent 19ff5d3 commit 7bf43f2
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions python-sync-actions/src/component.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ def run(self):
"""
Main component method
"""
self.make_call()
pass

def init_component(self):
Expand Down Expand Up @@ -221,10 +222,10 @@ def _parse_data(self, data, path) -> list:
except KeyError:
raise UserException(f"Path {path.path} not found in the response data")

if not isinstance(result, list):
element_name = 'root' if path.path == '.' else path.path
raise UserException(f"The {element_name} element of the response is not list, "
"please change your Record Selector path to list")
# if not isinstance(result, list):
# element_name = 'root' if path.path == '.' else path.path
# raise UserException(f"The {element_name} element of the response is not list, "
# "please change your Record Selector path to list")

return result

Expand All @@ -243,7 +244,7 @@ def make_call(self) -> tuple[list, list[dict]]:

parent_results_list = []

for job in self._configurations:
for index, job in enumerate(self._configurations):

api_cfg = job.api
request_cfg = job.request_parameters
Expand All @@ -268,15 +269,24 @@ def make_call(self) -> tuple[list, list[dict]]:
'timeout': timeout}

endpoint_results = []
for row in parent_results or [{}]:
parent_results_ext = parent_results_list + [row]

placeholders = PlaceholdersUtils.get_params_for_child_jobs(job.request_parameters.placeholders,
parent_results_ext, self._parent_params)
try:
sublist = parent_results[index]
except IndexError:
sublist = [{}]

for i, row in enumerate(sublist):
# parent_results_ext = parent_results_list + [row] if row else None

row_path = job.request_parameters.endpoint_path

if job.request_parameters.placeholders:
placeholders = PlaceholdersUtils.get_params_for_child_jobs(job.request_parameters.placeholders,
parent_results_list, self._parent_params)

self._parent_params = placeholders[0]
self._parent_params = placeholders[0]

row_path = self._fill_placeholders(placeholders, job.request_parameters.endpoint_path)
row_path = self._fill_placeholders(placeholders, job.request_parameters.endpoint_path)

response = self._client.send_request(method=job.request_parameters.method,
endpoint_path=row_path, **request_parameters)
Expand All @@ -286,6 +296,7 @@ def make_call(self) -> tuple[list, list[dict]]:
endpoint_results.append(result)

parent_results_list.append(endpoint_results)
parent_results = endpoint_results

return self._final_response, endpoint_results

Expand Down

0 comments on commit 7bf43f2

Please sign in to comment.