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.

Copilot AI review requested due to automatic review settings October 29, 2025 03:34
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

This PR adds retry functionality and pause support to the Worker class, along with cleanup improvements. The main changes include adding a retry_if_failed method for retrying failed operations, implementing a pause method to pause job processing, and updating the close method to emit events and set state flags.

  • Added retry_if_failed method for retrying coroutine functions with configurable delays and max retries
  • Implemented pause method to pause worker and wait for active jobs to complete
  • Enhanced close method to set closed flag and emit 'closed' event

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +297 to +298
if not self.paused:
self.paused = True
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The self.paused attribute is not initialized in the __init__ method. This will raise an AttributeError when pause() is called for the first time or when retry_if_failed() checks self.paused at line 238. Add self.paused = False in the __init__ method around line 56 where other state flags are initialized.

Copilot uses AI. Check for mistakes.
retry += 1
if retry >= max_retries:
raise err
await asyncio.sleep(delay_in_ms / 1000.0)
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

The delay is applied even after the last retry fails before re-raising the exception. The sleep at line 245 should only occur if there will be another retry attempt. Consider moving the sleep to before the retry increment or adding a condition to skip it when retry + 1 >= max_retries.

Suggested change
await asyncio.sleep(delay_in_ms / 1000.0)
else:
await asyncio.sleep(delay_in_ms / 1000.0)

Copilot uses AI. Check for mistakes.
finally:
self.jobs.remove((job, token))

async def retry_if_failed(self, fn, opts=None):
Copy link

Copilot AI Oct 29, 2025

Choose a reason for hiding this comment

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

Mixing implicit and explicit returns may indicate an error, as implicit returns always return None.

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.

2 participants