port-ocean 0.5.4__py3-none-any.whl → 0.5.5__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.

port_ocean/utils/cache.py CHANGED
@@ -1,14 +1,20 @@
1
1
  import functools
2
+ import hashlib
2
3
  from typing import Callable, AsyncIterator, Any
3
-
4
4
  from port_ocean.context.event import event
5
5
 
6
6
  AsyncIteratorCallable = Callable[..., AsyncIterator[list[Any]]]
7
7
 
8
8
 
9
- def cache_iterator_result(
10
- cache_key: str,
11
- ) -> Callable[[AsyncIteratorCallable], AsyncIteratorCallable]:
9
+ def hash_func(function_name: str, *args: Any, **kwargs: Any) -> str:
10
+ args_str = str(args)
11
+ kwargs_str = str(kwargs)
12
+ concatenated_string = args_str + kwargs_str
13
+ hash_object = hashlib.sha256(concatenated_string.encode())
14
+ return f"{function_name}_{hash_object.hexdigest()}"
15
+
16
+
17
+ def cache_iterator_result() -> Callable[[AsyncIteratorCallable], AsyncIteratorCallable]:
12
18
  """
13
19
  This decorator caches the results of an async iterator function. It checks if the result is already in the cache
14
20
  and if not, it fetches the all the data and caches it at ocean.attributes cache the end of the iteration.
@@ -18,9 +24,12 @@ def cache_iterator_result(
18
24
  For example, you can use this to cache data coming back from the third-party API to avoid making the same request
19
25
  multiple times for each kind.
20
26
 
27
+ The caching mechanism also detects changes in parameters.
28
+ If a function is called with different parameter values, it will be stored in different hash keys for each unique call.
29
+
21
30
  Usage:
22
31
  ```python
23
- @cache_iterator_result("my_cache_key")
32
+ @cache_iterator_result()
24
33
  async def my_async_iterator_function():
25
34
  # Your code here
26
35
  ```
@@ -29,6 +38,9 @@ def cache_iterator_result(
29
38
  def decorator(func: AsyncIteratorCallable) -> AsyncIteratorCallable:
30
39
  @functools.wraps(func)
31
40
  async def wrapper(*args: Any, **kwargs: Any) -> Any:
41
+ # Create Hash key from function name, args and kwargs
42
+ cache_key = hash_func(func.__name__, *args, **kwargs)
43
+
32
44
  # Check if the result is already in the cache
33
45
  if cache := event.attributes.get(cache_key):
34
46
  yield cache
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: port-ocean
3
- Version: 0.5.4
3
+ Version: 0.5.5
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
@@ -117,13 +117,13 @@ port_ocean/run.py,sha256=vyShtqg_jEiE6M4SJpci6c4oRD9k2ztesAXEx_6Sc9M,1906
117
117
  port_ocean/sonar-project.properties,sha256=X_wLzDOkEVmpGLRMb2fg9Rb0DxWwUFSvESId8qpvrPI,73
118
118
  port_ocean/utils/__init__.py,sha256=KMGnCPXZJbNwtgxtyMycapkDz8tpSyw23MSYT3iVeHs,91
119
119
  port_ocean/utils/async_http.py,sha256=arnH458TExn2Dju_Sy6pHas_vF5RMWnOp-jBz5WAAcE,1226
120
- port_ocean/utils/cache.py,sha256=cXDl0mzvMhx-yyJIuk-flcdxSB5CmZg498jKUW19gTs,1640
120
+ port_ocean/utils/cache.py,sha256=3KItZDE2yVrbVDr-hoM8lNna8s2dlpxhP4ICdLjH4LQ,2231
121
121
  port_ocean/utils/misc.py,sha256=2XmO8W0SgPjV0rd9HZvrHhoMlHprIwmMFsINxlAmgyw,1723
122
122
  port_ocean/utils/repeat.py,sha256=0EFWM9d8lLXAhZmAyczY20LAnijw6UbIECf5lpGbOas,3231
123
123
  port_ocean/utils/signal.py,sha256=Fab0049Cjs69TPTQgvEvilaVZKACQr6tGkRdySjNCi8,1515
124
124
  port_ocean/version.py,sha256=UsuJdvdQlazzKGD3Hd5-U7N69STh8Dq9ggJzQFnu9fU,177
125
- port_ocean-0.5.4.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
126
- port_ocean-0.5.4.dist-info/METADATA,sha256=yM5zZqYuTbwTa7E-Rjx6mChEceQkMw94mx2kmdJLgsg,6510
127
- port_ocean-0.5.4.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
128
- port_ocean-0.5.4.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
129
- port_ocean-0.5.4.dist-info/RECORD,,
125
+ port_ocean-0.5.5.dist-info/LICENSE.md,sha256=WNHhf_5RCaeuKWyq_K39vmp9F28LxKsB4SpomwSZ2L0,11357
126
+ port_ocean-0.5.5.dist-info/METADATA,sha256=626xjgEwjL3tRbdXoUR-P5rQc0eN2Ju0xOjIXznbuAo,6510
127
+ port_ocean-0.5.5.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
128
+ port_ocean-0.5.5.dist-info/entry_points.txt,sha256=F_DNUmGZU2Kme-8NsWM5LLE8piGMafYZygRYhOVtcjA,54
129
+ port_ocean-0.5.5.dist-info/RECORD,,