|
24 | 24 | BPMN_MAPPINGS = {} |
25 | 25 |
|
26 | 26 | timeout = ClientTimeout(sock_connect=5) |
27 | | -client_session = ClientSession(timeout=timeout) |
28 | 27 |
|
29 | 28 |
|
30 | 29 | def bpmn_tag(tag): |
@@ -254,49 +253,52 @@ async def run_connector(self, variables, instance_id): |
254 | 253 | ) |
255 | 254 |
|
256 | 255 | # Check method and make request |
257 | | - async with aiohttp.ClientSession() as session: |
258 | | - async with session.get('http://httpbin.org/get') as resp: |
259 | | - print(resp.status) |
260 | | - print(await resp.text()) |
261 | | - print(await resp.text()) |
262 | | - print("test") |
263 | | - return |
264 | | - if method := self.connector_fields["input_variables"].get("method") or "GET": |
265 | | - if method == "POST": |
266 | | - call_function = client_session.post |
267 | | - elif method == "PATCH": |
268 | | - call_function = client_session.patch |
269 | | - else: |
270 | | - call_function = client_session.get |
271 | | - if not isinstance(data, dict): |
272 | | - data = dict(data) |
273 | | - response = await call_function( |
274 | | - url, |
275 | | - params=parameters, |
276 | | - json=data, |
277 | | - headers={'content-type': 'application/json'} |
278 | | - ) |
279 | | - if response.status not in (200, 201): |
280 | | - raise Exception(response.text) |
| 256 | + async with aiohttp.ClientSession(timeout=timeout) as client_session: |
| 257 | + if method := self.connector_fields["input_variables"].get("method") or "GET": |
| 258 | + if method == "POST": |
| 259 | + call_function = client_session.post |
| 260 | + elif method == "PATCH": |
| 261 | + call_function = client_session.patch |
| 262 | + else: |
| 263 | + call_function = client_session.get |
| 264 | + if not isinstance(data, dict): |
| 265 | + data = dict(data) |
| 266 | + response = await call_function( |
| 267 | + url, |
| 268 | + params=parameters, |
| 269 | + json=data, |
| 270 | + headers={'content-type': 'application/json'} |
| 271 | + ) |
| 272 | + if response.status not in (200, 201): |
| 273 | + raise Exception(response.text) |
| 274 | + |
| 275 | + r = {} |
| 276 | + try: |
| 277 | + r = await response.json() |
| 278 | + except Exception as e: |
| 279 | + print("error") |
| 280 | + if not isinstance(e, ContentTypeError): |
| 281 | + raise e |
| 282 | + |
| 283 | + # Check for output variables |
| 284 | + |
| 285 | + if self.output_variables: |
| 286 | + for key in self.output_variables: |
| 287 | + value = self.output_variables.get(key) |
| 288 | + if len(value) > 0: |
| 289 | + variables[key] = parse_expression(expression=value, process_variables=r) |
| 290 | + if key in r: |
| 291 | + variables[key] = r[key] |
| 292 | + print(variables) |
| 293 | + return r |
| 294 | + |
| 295 | + |
| 296 | + |
| 297 | + |
| 298 | + |
281 | 299 |
|
282 | | - r = {} |
283 | | - try: |
284 | | - r = await response.json() |
285 | | - except Exception as e: |
286 | | - print("error") |
287 | | - if not isinstance(e, ContentTypeError): |
288 | | - raise e |
289 | 300 |
|
290 | | - # Check for output variables |
291 | 301 |
|
292 | | - if self.output_variables: |
293 | | - for key in self.output_variables: |
294 | | - value = self.output_variables.get(key) |
295 | | - if len(value) > 0: |
296 | | - variables[key] = parse_expression(expression=value, process_variables=r) |
297 | | - if key in r: |
298 | | - variables[key] = r[key] |
299 | | - print(variables) |
300 | 302 |
|
301 | 303 | async def run(self, variables, instance_id): |
302 | 304 |
|
|
0 commit comments