Hello,
We have a service whose purpose is to sort of oversee and monitor other
services. It keeps track of updates and information from other services. We
want each service in our system to register with this monitor service on
startup.
Specifically, every service should have a uuid to identify it so we can
group updates and information together and associate them with a particular
run of a service. The uuid should be specific to a run of a service, so if
we restart it, the uuid should change, and if we start a second instance of
that service on a different (or even the same) server, it would also have a
different uuid.
We can generate a uuid and store it as an attribute on the service class,
and report it when requested, but we're looking for a way to report it on
startup. For example:
MonitorService is running
ServiceA is not running
ServiceA is invoked (using `nameko run servicea` or a more manual run
process)
ServiceA establishes its dependencies and entrypoints and is ready to
listen on queues, and has generated a uuid for itself
ServiceA makes an RPC (or publishes to a queue, etc.) to MonitorService to
report its uuid and indicate that it's online
ServiceA processes requests as normal
At some point in the future we'd also like:
ServiceA is told to gracefully shut down
ServiceA makes an RPC (or publishes to a queue, etc.) to MonitorService to
indicate that it's going offline (and supplies its uuid so MonitorService
knows who's going down)
We've also considered having MonitorService generate the uuid and return it
to ServiceA in a response to the startup request, but we weren't sure how
to get ServiceA to store it as an attribute that all future workers would
inherit, and that seemed like the wrong approach anyway.
We tried using a generic publisher to publish to a queue that the monitor
service is listening to in the service's __init__() or in a dependency
provider, but it didn't like that and we don't want to register with every
worker, just on the service setup.
We have a method listening on an event broadcast that all services will
respond to, and we can set that event on a timer, but again, we'd like a
service to announce itself rather than wait to be pinged. (It might come
online and go offline between firings of the timer and we wouldn't know.)
We're considering writing our own run script and wrapping the
ServiceContainer in order to make a REST call during start() and stop().
We've looked at nameko.testing.services @once, nameko.extensions.Extension,
and nameko.extensions.DependencyProvider among other things. It looks like
Extension should allow us to do what we want, namely make a call when the
service is ready to go and also when it's shutting down, but I haven't
figured out how to get this to work. @once is part of a testing module (so
probably not meant for production) and DependencyProvider seems like its
meant for non-nameko dependencies, so I'm not really sure which direction
we should be pursuing.
TL;DR:
How would you recommend we make a nameko service depend on another nameko
service?