-
-
Notifications
You must be signed in to change notification settings - Fork 294
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
Feature Request: Standard way to inject arguments #389
Comments
I used this approach for injecting unit of work instance but failed messages were not retried then. Dramatiq emitted standard "Failed to process" message and silently removed it from the queue. However it worked when injecting e.g. integer value. (I added this middleware before Retries middleware.) |
Yeah, sounds like Dramatiq couldn't re-serialize the That's why I delete the additions afterwards. |
I think the right level at which to do this is a custom I don't think I'd want to standardize something like this in Dramatiq, though, because there are many ways you could want to do DI and Dramatiq already provides enough configuration knobs for you do be able to do it yourself. |
maybe we can re-serialize message like this #366, use re-serialize message is really useful |
Ok, I'm trying to wrap my head around how to do this without core dramatiq support, and it's not working. There's two cases where an actor is called: directly, and from a queue. How I want my application-specific additions to behave will vary by context. First thing is a status & progress tracker: It reports to a separate data store the status of message, as well as in-job progress (we have some long jobs). It needs the ID of the message to key off in this data store. I want to be able to pass along a callable to the underlying function that'll let it report progress. (If it's from a message, an actual call. If it's a direct call, a filler no-op function.) Second is database transactions: I want to wrap each call in a transaction, and gives the actor a database handle. In the case of a direct call, it expects the caller to hand them a database handle. The problem is that I can't come up with The core problem is that |
Note that I'm not looking for a complete DI framework. I just want a mechanism by which Middleware can add additional keyword arguments to Actors and Messages. |
(sorry for ditching the template)
Things I'm wanting to do with dramatiq involve things shaped like dependency injection: the actor requests a kind of dependency (like a progress status callable or a database connection), and then a middleware accepts the flag and injects the dependency into the message.
This is currently not as easy as it could be, because the message is then re-serialized and dependencies are often not serializable (nor should they be included).
Current solution:
The text was updated successfully, but these errors were encountered: