port-ocean 0.12.2.dev6__py3-none-any.whl → 0.12.2.dev8__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.

Potentially problematic release.


This version of port-ocean might be problematic. Click here for more details.

@@ -1,14 +1,12 @@
1
- import asyncio
2
1
  from abc import abstractmethod
3
- from concurrent.futures import ProcessPoolExecutor
4
2
  from typing import TypedDict, Callable, Any, Awaitable
5
3
 
6
4
  from pydantic import Extra
7
5
 
8
6
  from port_ocean.config.base import BaseOceanModel
7
+ from port_ocean.utils.signal import signal_handler
9
8
  from port_ocean.context.ocean import ocean
10
9
  from port_ocean.utils.misc import IntegrationStateStatus
11
- from port_ocean.utils.signal import signal_handler
12
10
 
13
11
 
14
12
  class EventListenerEvents(TypedDict):
@@ -69,14 +67,7 @@ class BaseEventListener:
69
67
  """
70
68
  await self._before_resync()
71
69
  try:
72
- loop = asyncio.get_event_loop()
73
- with ProcessPoolExecutor() as executor:
74
- e = executor.submit(
75
- lambda: asyncio.run_coroutine_threadsafe(
76
- self.events["on_resync"](resync_args), loop
77
- )
78
- )
79
- signal_handler.register(e.cancel)
70
+ await self.events["on_resync"](resync_args)
80
71
  await self._after_resync()
81
72
  except Exception as e:
82
73
  await self._on_resync_failure(e)
@@ -3,7 +3,6 @@ import inspect
3
3
  import typing
4
4
  from typing import Callable, Awaitable, Any
5
5
 
6
- import httpx
7
6
  from loguru import logger
8
7
 
9
8
  from port_ocean.clients.port.types import UserAgentType
@@ -140,9 +139,9 @@ class SyncRawMixin(HandlerMixin, EventsMixin):
140
139
  objects_diff = await self._calculate_raw(
141
140
  [(resource, results)], parse_all, send_raw_data_examples_amount
142
141
  )
143
- await self.entities_state_applier.upsert(
144
- objects_diff[0].entity_selector_diff.passed, user_agent_type
145
- )
142
+ # modified_objects = await self.entities_state_applier.upsert(
143
+ # objects_diff[0].entity_selector_diff.passed, user_agent_type
144
+ # )
146
145
  return CalculationResult(
147
146
  objects_diff[0].entity_selector_diff._replace(passed=objects_diff[0].entity_selector_diff.passed),
148
147
  errors=objects_diff[0].errors,
@@ -426,20 +425,20 @@ class SyncRawMixin(HandlerMixin, EventsMixin):
426
425
  use_cache=False
427
426
  )
428
427
  logger.info(f"Resync will use the following mappings: {app_config.dict()}")
429
- try:
430
- did_fetched_current_state = True
431
- entities_at_port = await ocean.port_client.search_entities(
432
- user_agent_type
433
- )
434
- except httpx.HTTPError as e:
435
- logger.warning(
436
- "Failed to fetch the current state of entities at Port. "
437
- "Skipping delete phase due to unknown initial state. "
438
- f"Error: {e}\n"
439
- f"Response status code: {e.response.status_code if isinstance(e, httpx.HTTPStatusError) else None}\n"
440
- f"Response content: {e.response.text if isinstance(e, httpx.HTTPStatusError) else None}\n"
441
- )
442
- did_fetched_current_state = False
428
+ # try:
429
+ # did_fetched_current_state = True
430
+ # entities_at_port = await ocean.port_client.search_entities(
431
+ # user_agent_type
432
+ # )
433
+ # except httpx.HTTPError as e:
434
+ # logger.warning(
435
+ # "Failed to fetch the current state of entities at Port. "
436
+ # "Skipping delete phase due to unknown initial state. "
437
+ # f"Error: {e}\n"
438
+ # f"Response status code: {e.response.status_code if isinstance(e, httpx.HTTPStatusError) else None}\n"
439
+ # f"Response content: {e.response.text if isinstance(e, httpx.HTTPStatusError) else None}\n"
440
+ # )
441
+ # did_fetched_current_state = False
443
442
 
444
443
  creation_results: list[tuple[list[Entity], list[Exception]]] = []
445
444
 
@@ -458,36 +457,36 @@ class SyncRawMixin(HandlerMixin, EventsMixin):
458
457
  except asyncio.CancelledError as e:
459
458
  logger.warning("Resync aborted successfully, skipping delete phase. This leads to an incomplete state")
460
459
  raise
461
- else:
462
- if not did_fetched_current_state:
463
- logger.warning(
464
- "Due to an error before the resync, the previous state of entities at Port is unknown."
465
- " Skipping delete phase due to unknown initial state."
466
- )
467
- return
468
-
469
- logger.info("Starting resync diff calculation")
470
- flat_created_entities, errors = zip_and_sum(creation_results) or [
471
- [],
472
- [],
473
- ]
474
-
475
- if errors:
476
- message = f"Resync failed with {len(errors)}. Skipping delete phase due to incomplete state"
477
- error_group = ExceptionGroup(
478
- f"Resync failed with {len(errors)}. Skipping delete phase due to incomplete state",
479
- errors,
480
- )
481
- if not silent:
482
- raise error_group
483
-
484
- logger.error(message, exc_info=error_group)
485
- else:
486
- logger.info(
487
- f"Running resync diff calculation, number of entities at Port before resync: {len(entities_at_port)}, number of entities created during sync: {len(flat_created_entities)}"
488
- )
489
- await self.entities_state_applier.delete_diff(
490
- {"before": entities_at_port, "after": flat_created_entities},
491
- user_agent_type,
492
- )
493
- logger.info("Resync finished successfully")
460
+ # else:
461
+ # if not did_fetched_current_state:
462
+ # logger.warning(
463
+ # "Due to an error before the resync, the previous state of entities at Port is unknown."
464
+ # " Skipping delete phase due to unknown initial state."
465
+ # )
466
+ # return
467
+ #
468
+ # logger.info("Starting resync diff calculation")
469
+ # flat_created_entities, errors = zip_and_sum(creation_results) or [
470
+ # [],
471
+ # [],
472
+ # ]
473
+ #
474
+ # if errors:
475
+ # message = f"Resync failed with {len(errors)}. Skipping delete phase due to incomplete state"
476
+ # error_group = ExceptionGroup(
477
+ # f"Resync failed with {len(errors)}. Skipping delete phase due to incomplete state",
478
+ # errors,
479
+ # )
480
+ # if not silent:
481
+ # raise error_group
482
+ #
483
+ # logger.error(message, exc_info=error_group)
484
+ # else:
485
+ # logger.info(
486
+ # f"Running resync diff calculation, number of entities at Port before resync: {len(entities_at_port)}, number of entities created during sync: {len(flat_created_entities)}"
487
+ # )
488
+ # await self.entities_state_applier.delete_diff(
489
+ # {"before": entities_at_port, "after": flat_created_entities},
490
+ # user_agent_type,
491
+ # )
492
+ # logger.info("Resync finished successfully")
@@ -1,8 +1,8 @@
1
1
  import asyncio
2
2
  import logging
3
3
  import sys
4
+ import threading
4
5
  import time
5
- from concurrent.futures import ProcessPoolExecutor
6
6
  from datetime import datetime
7
7
  from logging.handlers import MemoryHandler
8
8
  from typing import Any
@@ -65,19 +65,18 @@ class HTTPMemoryHandler(MemoryHandler):
65
65
  if self.ocean is None or not self.buffer:
66
66
  return
67
67
 
68
+ def _wrap_event_loop(_ocean: Ocean, logs_to_send: list[dict[str, Any]]) -> None:
69
+ loop = asyncio.new_event_loop()
70
+ loop.run_until_complete(self.send_logs(_ocean, logs_to_send))
71
+ loop.close()
72
+
68
73
  self.acquire()
69
74
  logs = list(self._serialized_buffer)
70
75
  if logs:
71
76
  self.buffer.clear()
72
77
  self._serialized_buffer.clear()
73
78
  self.last_flush_time = time.time()
74
- loop = asyncio.new_event_loop()
75
- with ProcessPoolExecutor() as executor:
76
- executor.submit(
77
- lambda: asyncio.run_coroutine_threadsafe(
78
- self.send_logs(self.ocean, logs), loop
79
- )
80
- )
79
+ threading.Thread(target=_wrap_event_loop, args=(self.ocean, logs)).start()
81
80
  self.release()
82
81
 
83
82
  async def send_logs(
port_ocean/ocean.py CHANGED
@@ -1,6 +1,6 @@
1
1
  import asyncio
2
2
  import sys
3
- from concurrent.futures import ProcessPoolExecutor
3
+ import threading
4
4
  from contextlib import asynccontextmanager
5
5
  from typing import Callable, Any, Dict, AsyncIterator, Type
6
6
 
@@ -9,6 +9,8 @@ from loguru import logger
9
9
  from pydantic import BaseModel
10
10
  from starlette.types import Scope, Receive, Send
11
11
 
12
+ from port_ocean.core.handlers.resync_state_updater import ResyncStateUpdater
13
+ from port_ocean.core.models import Runtime
12
14
  from port_ocean.clients.port.client import PortClient
13
15
  from port_ocean.config.settings import (
14
16
  IntegrationConfiguration,
@@ -18,15 +20,13 @@ from port_ocean.context.ocean import (
18
20
  ocean,
19
21
  initialize_port_ocean_context,
20
22
  )
21
- from port_ocean.core.handlers.resync_state_updater import ResyncStateUpdater
22
23
  from port_ocean.core.integrations.base import BaseIntegration
23
- from port_ocean.core.models import Runtime
24
24
  from port_ocean.log.sensetive import sensitive_log_filter
25
25
  from port_ocean.middlewares import request_handler
26
- from port_ocean.utils.misc import IntegrationStateStatus
27
26
  from port_ocean.utils.repeat import repeat_every
28
27
  from port_ocean.utils.signal import signal_handler
29
28
  from port_ocean.version import __integration_version__
29
+ from port_ocean.utils.misc import IntegrationStateStatus
30
30
 
31
31
 
32
32
  class Ocean:
@@ -92,13 +92,6 @@ class Ocean:
92
92
  )
93
93
  raise e
94
94
 
95
- def pool_executor_wrapper(event_loop) -> None:
96
- with ProcessPoolExecutor() as executor:
97
- e = executor.submit(lambda: asyncio.run_coroutine_threadsafe(
98
- execute_resync_all(), event_loop
99
- ))
100
- signal_handler.register(e.cancel)
101
-
102
95
  interval = self.config.scheduled_resync_interval
103
96
  loop = asyncio.get_event_loop()
104
97
  if interval is not None:
@@ -110,7 +103,13 @@ class Ocean:
110
103
  seconds=interval * 60,
111
104
  # Not running the resync immediately because the event listener should run resync on startup
112
105
  wait_first=True,
113
- )(lambda _: pool_executor_wrapper(loop))
106
+ )(
107
+ lambda: threading.Thread(
108
+ target=lambda: asyncio.run_coroutine_threadsafe(
109
+ execute_resync_all(), loop
110
+ )
111
+ ).start()
112
+ )
114
113
  await repeated_function()
115
114
 
116
115
  async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: port-ocean
3
- Version: 0.12.2.dev6
3
+ Version: 0.12.2.dev8
4
4
  Summary: Port Ocean is a CLI tool for managing your Port projects.
5
5
  Home-page: https://app.getport.io
6
6
  Keywords: ocean,port-ocean,port
@@ -65,7 +65,7 @@ port_ocean/core/defaults/clean.py,sha256=S3UAfca-oU89WJKIB4OgGjGjPr0vxBQ2aRZsLTZ
65
65
  port_ocean/core/defaults/common.py,sha256=uVUg6VEn4RqtXQwLwMNGfkmT5zYRN_h5USfKw3poVyo,3561
66
66
  port_ocean/core/defaults/initialize.py,sha256=qg4JLIWjp0c5-9w09X99muHRYX4k1cGZ_77vYo-tnpU,8422
67
67
  port_ocean/core/event_listener/__init__.py,sha256=mzJ33wRq0kh60fpVdOHVmvMTUQIvz3vxmifyBgwDn0E,889
68
- port_ocean/core/event_listener/base.py,sha256=tc7NHg-Vvt8M4iVIBrJvkecVTmTDGE1r-bjMQZpK_ME,2719
68
+ port_ocean/core/event_listener/base.py,sha256=1Nmpg00OfT2AD2L8eFm4VQEcdG2TClpSWJMhWhAjkEE,2356
69
69
  port_ocean/core/event_listener/factory.py,sha256=AYYfSHPAF7P5H-uQECXT0JVJjKDHrYkWJJBSL4mGkg8,3697
70
70
  port_ocean/core/event_listener/http.py,sha256=N8HrfFqR3KGKz96pWdp_pP-m30jGtcz_1CkijovkBN8,2565
71
71
  port_ocean/core/event_listener/kafka.py,sha256=ulidnp4sz-chXwHsbH9JayVjcxy_mG6ts_Im3YKmLpI,6983
@@ -94,7 +94,7 @@ port_ocean/core/integrations/mixins/__init__.py,sha256=FA1FEKMM6P-L2_m7Q4L20mFa4
94
94
  port_ocean/core/integrations/mixins/events.py,sha256=Ddfx2L4FpghV38waF8OfVeOV0bHBxNIgjU-q5ffillI,2341
95
95
  port_ocean/core/integrations/mixins/handler.py,sha256=mZ7-0UlG3LcrwJttFbMe-R4xcOU2H_g33tZar7PwTv8,3771
96
96
  port_ocean/core/integrations/mixins/sync.py,sha256=B9fEs8faaYLLikH9GBjE_E61vo0bQDjIGQsQ1SRXOlA,3931
97
- port_ocean/core/integrations/mixins/sync_raw.py,sha256=hWaO1XbW7m2pUTGXlPJE30gOfbVhYhPXz0uNKEuDaNs,18849
97
+ port_ocean/core/integrations/mixins/sync_raw.py,sha256=VVAReztpakDil4DSuXWdBnVSyKSBs-Dv7GCdm6toJp4,18988
98
98
  port_ocean/core/integrations/mixins/utils.py,sha256=7y1rGETZIjOQadyIjFJXIHKkQFKx_SwiP-TrAIsyyLY,2303
99
99
  port_ocean/core/models.py,sha256=dJ2_olTdbjUpObQJNmg7e7EENU_zZiX6XOaknNp54B0,1342
100
100
  port_ocean/core/ocean_types.py,sha256=3_d8-n626f1kWLQ_Jxw194LEyrOVupz05qs_Y1pvB-A,990
@@ -111,11 +111,11 @@ port_ocean/helpers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuF
111
111
  port_ocean/helpers/async_client.py,sha256=SRlP6o7_FCSY3UHnRlZdezppePVxxOzZ0z861vE3K40,1783
112
112
  port_ocean/helpers/retry.py,sha256=IQ0RfQ2T5o6uoZh2WW2nrFH5TT6K_k3y2Im0HDp5j9Y,15059
113
113
  port_ocean/log/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
114
- port_ocean/log/handlers.py,sha256=Br_1aujTmMkT15DbZj1E-mg0sHauvtKQB4E9-SDypmE,2861
114
+ port_ocean/log/handlers.py,sha256=k9G_Mb4ga2-Jke9irpdlYqj6EYiwv0gEsh4TgyqqOmI,2853
115
115
  port_ocean/log/logger_setup.py,sha256=BaXt-mh9CVXhneh37H46d04lqOdIBixG1pFyGfotuZs,2328
116
116
  port_ocean/log/sensetive.py,sha256=lVKiZH6b7TkrZAMmhEJRhcl67HNM94e56x12DwFgCQk,2920
117
117
  port_ocean/middlewares.py,sha256=9wYCdyzRZGK1vjEJ28FY_DkfwDNENmXp504UKPf5NaQ,2727
118
- port_ocean/ocean.py,sha256=ZPIRXqBF2WB3-tLsOwRnbFioGzGh2iRadK7YgYP1rpM,5227
118
+ port_ocean/ocean.py,sha256=Oe4H3kKtkj52uNO4Rd_47iY3MBdrTtshXZ_16q7A8bM,5071
119
119
  port_ocean/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
120
120
  port_ocean/run.py,sha256=rTxBlrQd4yyrtgErCFJCHCEHs7d1OXrRiJehUYmIbN0,2212
121
121
  port_ocean/sonar-project.properties,sha256=X_wLzDOkEVmpGLRMb2fg9Rb0DxWwUFSvESId8qpvrPI,73
@@ -140,8 +140,8 @@ port_ocean/utils/repeat.py,sha256=0EFWM9d8lLXAhZmAyczY20LAnijw6UbIECf5lpGbOas,32
140
140
  port_ocean/utils/signal.py,sha256=K-6kKFQTltcmKDhtyZAcn0IMa3sUpOHGOAUdWKgx0_E,1369
141
141
  port_ocean/utils/time.py,sha256=pufAOH5ZQI7gXvOvJoQXZXZJV-Dqktoj9Qp9eiRwmJ4,1939
142
142
  port_ocean/version.py,sha256=UsuJdvdQlazzKGD3Hd5-U7N69STh8Dq9ggJzQFnu9fU,177
143
- port_ocean-0.12.2.dev6.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
144
- port_ocean-0.12.2.dev6.dist-info/METADATA,sha256=2jHYgbU6PsEbwOZIXbqyF9PfomB4mCoGmsBcdsr0XZU,6619
145
- port_ocean-0.12.2.dev6.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
146
- port_ocean-0.12.2.dev6.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
147
- port_ocean-0.12.2.dev6.dist-info/RECORD,,
143
+ port_ocean-0.12.2.dev8.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
144
+ port_ocean-0.12.2.dev8.dist-info/METADATA,sha256=vakquKZunnwpNx8anyEnp8R8Fx6t235fknBMWSvRuxQ,6619
145
+ port_ocean-0.12.2.dev8.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
146
+ port_ocean-0.12.2.dev8.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
147
+ port_ocean-0.12.2.dev8.dist-info/RECORD,,