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
Async External Task Handler Function in run_topic_handlers #11
Comments
Hi @IdemenB, I'd like to take a look at this issue. Do you have a minimal example of what you are trying to accomplish with SQLx so that I can reproduce the error and start from there? |
Hi @Dansvidania , if you can clone the master branch from here https://github.com/IdemenB/camunda_lib_tests/blob/master/src/main.rs you'll see two handler functions initiated from main.rs . One of those functions make async sleep for 2 secs, another for 3 secs. I believe this will give the runtime within runtime error. There is also a commented SQLx example in the handlers.rs file. You can switch from sleep into that. You'll need to install a sample DB for that though. |
The app in the repo seems not to be using this library so I got confused. So the issue is reproduced by, if I understand correctly, having two different handlers sleep different amounts of time? I will start from that. |
Oh I'm sorry, this is a like a sandbox project I created by using the lib code initially. Because there are many different things I'm constantly trying and testing, very new in Rust (and also not a professional programmer) and don't know Git flows very well that's why I did that. By the way, I may have found the solution for this. The problem is that, in run_handler_functions we spawned a new (async) thread for each run_handler_function which in turn they spawn their own (async) threads. But, in essence run_handler_functions are blocking. This is not allowed by tokio-runtime. If you cannot find another and better solution, you can try to initiate blocking spawns in run_handler_functions (tokio::task::spawn_blocking) first, and than the rest should work. |
And one other thing I believe should be fixed is, the following loop in worker.rs
The spawned blocking threads should not be awaited because once they are spawn they will run indefinetely because run_handler_function() is a constant loop. |
I agree. The code running multiple topic handlers needs changing. I will try to play around with this a while and keep you posted. |
I am considering focusing the library functionality on My initial objective was to handle and hide the complexity from the consumers, but it seems to be creating more issues than anything else. This would simplify the architecture of the library itself while also giving more control to the consumers. What do you think? |
My suggestion would be the opposite :), and here is why. I can't think of a production scenario where there will be only a single type of external task in the universe of the company's business processes. If someone is dealing with these matters, especially in Rust, there is a lot of work and some concurrency in mind. So, this library should focus on easy management of concurrent workers. My tests so far, in the way I described in the previous message is working well with multiple Handlers. I even tried to instantiate the same handler twice, and it worked, too. In short, if we run the run_topic_handler() functions from the run_topic_handlers() with tokio::spawn_blocking() it seems to be working fine. My sample:
and one sample handler function of SQLx example -> this is in itself aync
main.rs
|
I agree with your premise, but my point is that it does not seem very complex to just parallelize the execution of The documentation of What I think I will end up doing is moving tokio and the parallel topic handler executor to a different crate/functionality, so that it can be opted in by users and it can be experimented with during the development of |
Yes, you're right. These are delicate areas and I'm so far away from being an expert in them, either. Can you think of an implementation where there is no handlerS() but just a single handler, but it is async and also the handler_function it triggers is also async. If you can set the baseline with that the library would really be helpful to start with. |
I will try to configure the library so that it will be easy for consumers to use I need to study a bit more and find the proper way to do that. |
Hi all,
In addition to the camunda_client crate I'm utilizing this lib of yours, too. Thank you very much! I've run into a problem which is rather advanced for my level in Rust, I'll appreciate if you can take a look.
The use case is as followsİ
On the SO, some users suggested to use tokio::task::spawn_blocking. So I've converted run_topic_handlers() into the following, but it still panics where I highlight :/
The text was updated successfully, but these errors were encountered: