Skip to content

Conversation

@benkeanna
Copy link
Contributor

No description provided.

@benkeanna benkeanna marked this pull request as draft September 8, 2025 08:25
@benkeanna benkeanna force-pushed the aben/parallel-gone branch 3 times, most recently from 79dbe0e to ba0d8ab Compare September 8, 2025 12:58
@benkeanna benkeanna marked this pull request as ready for review September 8, 2025 13:11
return 0.0

def __enter__(self) -> "RateLimiter":
self.wait_if_needed()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great if we could use the rate limiter as a decorator instead of context manager... My assumption is that it could be more versatile (for handling the methods from gooddata_sdk) and less verbose (we could wrap functions/methods with @rate_limiter instead of the with ... blocks and the rate limiter would not have to be a part of the instanced object (like the BackupManager). WDYT?

self,
calls_per_second: float = 1.0,
name: Optional[str] = None,
logger: Optional[Any] = None,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can reuse the LoggerLike protocol from gooddata-pipelines/gooddata_pipelines/logger/logger.py here as the logger type


self.calls_per_second = calls_per_second
self.min_interval = 1.0 / calls_per_second
self.name = name or "RateLimiter"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is necessary

from typing import Any, Optional


class RateLimiter:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great if this had some tests

if time_since_last_call < self.min_interval:
sleep_time = self.min_interval - time_since_last_call

if self.logger:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On a second thought, I'd consider if it's worth logging every wait and if the logger is needed - it has a potential for being super spammy (1000 workspaces, say 3-5 waits per each?)

self._lock = threading.Lock()
self._last_call_time = 0.0

def wait_if_needed(self) -> float:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does this method have a return value? If I see it correctly, it is not stored or read anywhere...

@benkeanna benkeanna force-pushed the aben/parallel-gone branch 2 times, most recently from e3020ad to bfe8f11 Compare September 9, 2025 12:48
@benkeanna benkeanna merged commit e907728 into master Sep 9, 2025
9 checks passed
@benkeanna benkeanna deleted the aben/parallel-gone branch September 9, 2025 13:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants