Can a DependencyProvider create and manage it’s own eventlet GreenPool to facilitate long-running processes that a service needs to create/delete?
We have a scenario where we want a service to create a long-running query as needed, where the query process needs to outlive the service request instance that created it.
You could just send asynchronous message to the service and consume it without blocking any clients.
Publishing asynchronous message:
Consuming the message:
The approach @Jakub_Borys mentions works great if you want to delegate the long-running query to another worker. Often this is the cleanest and most explicit way to do it.
It’s completely valid for a
DependencyProvider to run a background thread though. The service container exposes the
spawn_managed_thread for exactly this purpose.
The advantage of using
spawn_managed_thread over your own
GreenPool is that
Nameko is made aware of the background threads. The container will terminate if a managed thread throws an uncaught exception, for example.
Thanks @Jakub_Borys, @mattbennett - that’s what I needed. I should have remembered spawn_managed_thread().