Display ip address of worker in `rq info` (#1463)

* `rq info` displays id address

add feature of #1386

* making redis < 5.0.0 compatible

* address -> ip_address

https://github.com/rq/rq/pull/1463#discussion_r633264327
main
rpkak 4 years ago committed by GitHub
parent ef4f0611a7
commit 49b489a880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -131,7 +131,7 @@ def show_workers(queues, raw, by_queue, queue_class, worker_class):
for worker in workers: for worker in workers:
queue_names = ', '.join(worker.queue_names()) queue_names = ', '.join(worker.queue_names())
name = '%s (%s %s)' % (worker.name, worker.hostname, worker.pid) name = '%s (%s %s %s)' % (worker.name, worker.hostname, worker.ip_address, worker.pid)
if not raw: if not raw:
click.echo('%s: %s %s' % (name, state_symbol(worker.get_state()), queue_names)) click.echo('%s: %s %s' % (name, state_symbol(worker.get_state()), queue_names))
else: else:

@ -176,13 +176,6 @@ class Worker:
self.redis_server_version = None self.redis_server_version = None
if prepare_for_work:
self.hostname = socket.gethostname()
self.pid = os.getpid()
else:
self.hostname = None
self.pid = None
self.job_class = backend_class(self, 'job_class', override=job_class) self.job_class = backend_class(self, 'job_class', override=job_class)
self.queue_class = backend_class(self, 'queue_class', override=queue_class) self.queue_class = backend_class(self, 'queue_class', override=queue_class)
self.version = VERSION self.version = VERSION
@ -225,6 +218,16 @@ class Worker:
self.disable_default_exception_handler = disable_default_exception_handler self.disable_default_exception_handler = disable_default_exception_handler
if prepare_for_work:
self.hostname = socket.gethostname()
self.pid = os.getpid()
connection.client_setname(self.name)
self.ip_address = [client['addr'] for client in connection.client_list() if client['name'] == self.name][0]
else:
self.hostname = None
self.pid = None
self.ip_address = None
if isinstance(exception_handlers, (list, tuple)): if isinstance(exception_handlers, (list, tuple)):
for handler in exception_handlers: for handler in exception_handlers:
self.push_exc_handler(handler) self.push_exc_handler(handler)
@ -301,6 +304,7 @@ class Worker:
'queues': queues, 'queues': queues,
'pid': self.pid, 'pid': self.pid,
'hostname': self.hostname, 'hostname': self.hostname,
'ip_address': self.ip_address,
'version': self.version, 'version': self.version,
'python_version': self.python_version, 'python_version': self.python_version,
} }
@ -704,13 +708,15 @@ class Worker:
def refresh(self): def refresh(self):
data = self.connection.hmget( data = self.connection.hmget(
self.key, 'queues', 'state', 'current_job', 'last_heartbeat', self.key, 'queues', 'state', 'current_job', 'last_heartbeat',
'birth', 'failed_job_count', 'successful_job_count', 'birth', 'failed_job_count', 'successful_job_count', 'total_working_time',
'total_working_time', 'current_job_working_time', 'hostname', 'pid', 'version', 'python_version', 'current_job_working_time', 'hostname', 'ip_address', 'pid', 'version', 'python_version',
) )
(queues, state, job_id, last_heartbeat, birth, failed_job_count, (queues, state, job_id, last_heartbeat, birth, failed_job_count,
successful_job_count, total_working_time, current_job_working_time, hostname, pid, version, python_version) = data successful_job_count, total_working_time, current_job_working_time,
hostname, ip_address, pid, version, python_version) = data
queues = as_text(queues) queues = as_text(queues)
self.hostname = as_text(hostname) self.hostname = as_text(hostname)
self.ip_address = as_text(ip_address)
self.pid = int(pid) if pid else None self.pid = int(pid) if pid else None
self.version = as_text(version) self.version = as_text(version)
self.python_version = as_text(python_version) self.python_version = as_text(python_version)

Loading…
Cancel
Save