Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve extensibility #783

Conversation

egor-georgiev
Copy link

No description provided.

@egor-georgiev
Copy link
Author

egor-georgiev commented Jan 9, 2024

Hello, thanks for your work on Huey. I have added several ways to facilitate extensibility of Huey components, here are the use cases I added them for:

  1. Moving consumer event loop logic to a separate method allows to insert custom operations into every iteration of event loop without checking that updates do not break custom logic (by calling super()). For instance, in our codebase, we make sure that every iteration of consumer event loop touches a file as a means of health-checking Consumer process in container runtime.
  2. Adding consumer_class, task_wrapper_class allows to use custom classes for Huey Consumer and TaskWrapper without overriding whole task, create_consumer methods. To illustrate the use case, in our codebase we add several new convenience methods to Consumer class in order to facilitate health-check logic described in 1. We also plan on overriding TaskWrapper's s() and schedule() methods in order to register task id <-> task name mapping in redis storage.

@egor-georgiev
Copy link
Author

I brought task_wrapper_class as a @property in order not to toss around class declarations (property is lazy, but attribute is not, therefore, adding it as an attribute and not re-ordering declarations would cause a NameError).

coleifer added a commit that referenced this pull request Jan 9, 2024
coleifer added a commit that referenced this pull request Jan 9, 2024
@coleifer
Copy link
Owner

coleifer commented Jan 9, 2024

Some of these changes are now implemented in:

It seemed silly to make the consumer class an attribute and task wrapper a property. I'll retain the convention of requiring people to override the get_consumer() method if they want to use a custom Consumer implementation, and have also added a new get_task_wrapper_class() method that can be overridden to provide a custom TaskWrapper.

For the consumer, I've factored the main loop into its own method similar to how you have it, although I pulled the exception into the consumer module, as it's not something I expect people to generally attempt to catch.

I believe these changes should make it possible for you to accomplish what you've described.

@coleifer coleifer closed this Jan 9, 2024
@egor-georgiev
Copy link
Author

@coleifer thank you for your quick response! Do you have in mind a timeline for the next release?

@coleifer
Copy link
Owner

coleifer commented Jan 9, 2024

Not particularly, no, feel free to run on master in the meantime - I generally keep it stable & tests passing.

@egor-georgiev egor-georgiev deleted the feature/improve-extensibility branch January 9, 2024 16:54
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