-
-
Notifications
You must be signed in to change notification settings - Fork 318
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
Recognize actor with module name instead of only func name #640
Comments
I think we need to raise error if try to register actor with same name and require change it. And to auto resolve name conflict is best to use
|
maybe I will have a PR recently |
We've encountered this problem as well. We added a Dramatiq middleware to detect duplicate actor names: class EnforceUniqueActorNames(Middleware):
def before_declare_actor(self, broker, actor):
if actor.actor_name in broker.actors:
logger.error(
"Duplicate actor name detected: %s. Actor names must be unique. "
"Set a unique name using the `actor_name` kwarg or by renaming the "
"function decorated by @dramatiq.actor.",
actor.actor_name,
)
raise DuplicateActorError Wealso use a replacement for the standard def actor_v2(
fn: Optional[Callable] = None,
*,
actor_name: Optional[str] = None,
**options,
) -> Union[Actor, Callable]:
def decorator(fn):
nonlocal actor_name
if actor_name is None:
actor_name = fn.__name__
full_actor_name = f"{fn.__module__}.{actor_name}"
return actor(
fn,
actor_name=full_actor_name,
**options,
)
if fn is None:
return decorator
return decorator(fn) |
Issues
GitHub issues are for bugs. If you have questions, please ask them on the mailing list.
Checklist
Creating two func decorated with
@actor
without setting itsactor_name
in different module, import the first registered func and send message to run, and you may find that dramatiq run the second but not the first func...It seems dramatiq recognize func defaultly by its func name...
In many cases, the function names in different modules are set to the same. I think that it is an unreasonable design to use the function name as the only index.
dramatiq/dramatiq/actor.py
Line 258 in 4b6ad18
Should we change the default
actor_name
toactor_name = actor_name or f'{fn.__module__}.{fn.__name__}'
?I am not familiar with the source code. Based on my initial understanding, it seems that actor_name is only used as the key of the destination function and can be set at will without duplication.
The text was updated successfully, but these errors were encountered: