Add desc support to the BaseWorker initialization
In some cases, when we call the "BaseWorker.start" method (eg: use oslo_service.service.ProcessLanuch to pull up the worker), we cannot pass the "desc" parameter, so we need to pass in the desc parameter during initialization. this patch move the "desc" parameter to the initialization, when call "start" method, if set "desc", it will be used first. if not, "desc" passed in initialization are used. this design solves the problem and keeps compatibility. Partial-bug: #1910623 Change-Id: I4df8c319308224175a7f735cfc966b1080caa227
This commit is contained in:
parent
c0cf1b35aa
commit
1389b63213
@ -49,7 +49,7 @@ class BaseWorker(service.ServiceBase):
|
||||
_default_process_count = 1
|
||||
|
||||
def __init__(self, worker_process_count=_default_process_count,
|
||||
set_proctitle='on'):
|
||||
set_proctitle='on', desc=None):
|
||||
"""Initialize a worker instance.
|
||||
|
||||
:param worker_process_count: Defines how many processes to spawn for
|
||||
@ -60,12 +60,15 @@ class BaseWorker(service.ServiceBase):
|
||||
'off' - do not change process title
|
||||
'on' - set process title to descriptive string and parent
|
||||
'brief' - set process title to descriptive string
|
||||
desc:
|
||||
process descriptive string
|
||||
"""
|
||||
self._worker_process_count = worker_process_count
|
||||
self._my_pid = os.getpid()
|
||||
self._set_proctitle = set_proctitle
|
||||
if set_proctitle == 'on':
|
||||
self._parent_proctitle = setproctitle.getproctitle()
|
||||
self.desc = desc
|
||||
|
||||
@property
|
||||
def worker_process_count(self):
|
||||
@ -102,6 +105,7 @@ class BaseWorker(service.ServiceBase):
|
||||
"""
|
||||
|
||||
# If we are a child process, set our proctitle to something useful
|
||||
desc = desc or self.desc
|
||||
self.setproctitle(name, desc)
|
||||
if self.worker_process_count > 0:
|
||||
registry.notify(resources.PROCESS, events.AFTER_INIT, self.start)
|
||||
|
Loading…
x
Reference in New Issue
Block a user