Conversation
ef36dce to
17f032f
Compare
| """ | ||
| A Registry allows defining a collection of Actors not directly bound to a Broker. | ||
|
|
||
| This allows your code to declar Actors before configuring a Broker. |
There was a problem hiding this comment.
| This allows your code to declar Actors before configuring a Broker. | |
| This allows your code to declare actors before configuring a broker. |
| from .actor import Actor, _queue_name_re | ||
|
|
||
|
|
||
| class Registry: |
There was a problem hiding this comment.
Great to see this! I nearly have the same class in my projects.
I have implemented this method as well:
def enqueue(self, message, *, delay=None):
raise RuntimeError(
"ActorCollector has not transferred its actors to an actual broker. "
"Ensure transfer_actors() is called."
)
It ensures that the user is told what is going on when trying to call send() on an actor before doing the bind.
| "middleware to your Broker?" | ||
| ) % (actor_name, invalid_options_list)) | ||
|
|
||
| broker.declar_actor(actor) |
There was a problem hiding this comment.
In my code I have an additional helper method to allow binding multople collectors (here it would be registries) at once.
This is handy when linking up independet code from multiple packages.
def transfer_actors(broker, collectors: List[ActorCollector]):
for ac in collectors:
ac.transfer_actors(broker)
|
I have been able to achieve something like this by defining a middleware, that effectively looks like: Then I can reference API_ACTORS from anywhere in my code. Not sure if this approach works. I wanted to optionally store tasks for running via an API. |
|
Ah, but I have missed the point about doing this separately from a broker. Never mind. |
|
flask-melodramatiq solves this as well. |
Currently a WIP, this adds a Registry class to allow registering tasks independently of a Broker, and later register them with a given broker.
This solves the chicken-and-egg problem where decorated task functions may be imported before the configuration for the Broker has been loaded and applied.
Still needs tests...