mantiumai / chirps

Discover sensitive/confidential information stored in a vector database
GNU General Public License v3.0
57 stars 6 forks source link

Worker Status #146

Closed zimventures closed 1 year ago

zimventures commented 1 year ago

As a user, it would be helpful to view the current status of the configured Celery workers.

For example, this bug, which may or may not be a bug - would be better triaged if we knew that the Celery workers were up and running. Currently, the user is expected to know how to use the CLI to execute various commands. It would be much easier to display this information within the UI.

Worker application

A new application will be added to the project for handling this feature, and future worker-based functionality: worker.

Status View

The new application will provide a single view to get the status of the local celery worker: /worker/status. This view will return the HTML element to render the status icon within the navbar (described below). It's expected that this view is called via an HTMX polling mechanism.

The status of the workers can be fetched using the following logic:

from chirps.celery import app
inspection = app.inspect()
result =  i.ping()
# Result:  {'w1@fc74cd718b1d': {'ok': 'pong'}}

Details of each worker can be fetched using the stats() method:

>>> i.stats()
{'w1@fc74cd718b1d': {'total': {}, 'pid': 42322, 'clock': '162', 'uptime': 161, 'pool': {'implementation': 'celery.concurrency.prefork:TaskPool', 'max-concurrency': 4, 'processes': [42374, 42375, 42376, 42377], 'max-tasks-per-child': 'N/A', 'put-guarded-by-semaphore': False, 'timeouts': [0, 1800], 'writes': {'total': 0, 'avg': '0.00', 'all': '', 'raw': '', 'strategy': 'fair', 'inqueues': {'total': 4, 'active': 0}}}, 'broker': {'hostname': '127.0.0.1', 'userid': 'guest', 'virtual_host': '/', 'port': 5672, 'insist': False, 'ssl': False, 'transport': 'amqp', 'connect_timeout': 4, 'transport_options': {}, 'login_method': 'PLAIN', 'uri_prefix': None, 'heartbeat': 120.0, 'failover_strategy': 'round-robin', 'alternates': []}, 'prefetch_count': 16, 'rusage': {'utime': 3.251868, 'stime': 0.6368199999999999, 'maxrss': 105900, 'ixrss': 0, 'idrss': 0, 'isrss': 0, 'minflt': 59522, 'majflt': 0, 'nswap': 0, 'inblock': 0, 'oublock': 24, 'msgsnd': 0, 'msgrcv': 0, 'nsignals': 0, 'nvcsw': 444, 'nivcsw': 2020}}}

In the event Celery is running, but the message broker (RabbitMQ) is NOT, an exception will be raised.

>>> i.stats()
...
ConnectionResetError: [Errno 104] Connection reset by peer

UI Changes

In the navbar, justified to the right side, a new status icon will be displayed. The icon will be a simple green, yellow, or red dot. When the user's mouse is over the dot, any textual information about the status of the worker should be displayed.

An HTMX polling (5 second) trigger will be setup to automatically update the status indicator. It should call the status view described above and replace the contents of the status container div with the result.

zimventures commented 1 year ago

Initial implementation complete. Will be adding a follow-on ticket to make the status polling route faster. The UI currently takes too long to respond to the request.