Skip to content

Conversation

@roggervalf
Copy link
Collaborator

Why

Enter your explanation here.

How

Enter the implementation details here.

Additional Notes (Optional)

Any extra info here.

manast
manast previously approved these changes Jul 7, 2025
Copy link
Contributor

@manast manast left a comment

Choose a reason for hiding this comment

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

LGTM

@roggervalf roggervalf marked this pull request as ready for review August 12, 2025 04:21
Copilot AI review requested due to automatic review settings August 12, 2025 04:21
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Adds rate limiting functionality to the Worker class to prevent excessive job processing when rate limits are enforced. This implementation introduces mechanisms to check, wait for, and respect rate limit timeouts.

  • Introduces rate limit checking and waiting mechanisms
  • Modifies the main worker loop to respect rate limit conditions
  • Adds utility methods for managing rate limit delays and timeouts

@returns a Job or undefined if no job was available in the queue.
"""
if not self.waiting and self.drained:
if self.drained and not self.limitUntil and not self.waiting:
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The condition not self.limitUntil will be True when limitUntil is 0, but rate limiting should be based on comparing with current timestamp. This could cause incorrect behavior when limitUntil is 0 but should still allow processing. Consider using not self.isRateLimited() instead.

Suggested change
if self.drained and not self.limitUntil and not self.waiting:
if self.drained and not self.isRateLimited() and not self.waiting:

Copilot uses AI. Check for mistakes.

async def delay(self, milliseconds):
try:
await asyncio.sleep(milliseconds/1000 or 0.1)
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

The expression milliseconds/1000 or 0.1 will use 0.1 when milliseconds is 0, but it should sleep for 0 seconds when milliseconds is 0. Use await asyncio.sleep(milliseconds/1000) or handle the zero case explicitly.

Suggested change
await asyncio.sleep(milliseconds/1000 or 0.1)
await asyncio.sleep(milliseconds/1000)

Copilot uses AI. Check for mistakes.
return None

def isRateLimited(self):
return self.limitUntil > round(time.time() * 1000)
Copy link

Copilot AI Aug 12, 2025

Choose a reason for hiding this comment

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

This method will raise an AttributeError if self.limitUntil is not initialized. The code assumes limitUntil exists but it's not clear where this attribute is defined or initialized.

Suggested change
return self.limitUntil > round(time.time() * 1000)
return getattr(self, "limitUntil", 0) > round(time.time() * 1000)

Copilot uses AI. Check for mistakes.
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