I've been writing an agent (service) that is responsible for checking in with a remote server and retrieve tasks every now and then. It also provides a REST interface for inbound communication from the server and/or it's clients.
Thus far I have a very simple architecture: spawn 2 threads, one for serving a REST api (via Flask) and one which polls a queue for things to do (mostly for speaking to the server).
This queue is initialised with a "hello" message so as to force the agent to register to the server on start. However, now that I started working on the views/REST endpoints, I realized that I need to expose the queue or some abstraction from that context so I can push new actions into the queue directly from views/api endpoints. For example, we can have any request to the /dumpconfig
endpoint initiate outbound connections to nearby agents to gather their config by putting a message in the queue. So, my question is - how should I expose the queues from a totally different context? The api endpoints are defined as functions, so I was thinking of wrapping the main flask app startup in an object, initialise that object by passing it a queue and exposing it such that I could later in the file call queue = object.queue
from the global context in the api file.
Aucun commentaire:
Enregistrer un commentaire