Startcelery mgmt cmd now pipes output to logfile only if 'console' handler is not present in the Django LOGGING settings. Also updated stopcelery warnings to make it clear they are just warnings not errors.

This commit is contained in:
dvanaken 2020-04-03 01:20:51 -04:00 committed by Dana Van Aken
parent 66ad361654
commit 72580f65a0
2 changed files with 14 additions and 13 deletions

View File

@ -80,15 +80,14 @@ class Command(BaseCommand):
self.stdout = open(os.devnull, 'w')
# Stealth option that assigns where to pipe initial output
pipe = options.get('pipe', None)
if pipe is None:
pipe = '> /dev/null 2>&1'
try:
if 'celery' in settings.LOGGING['loggers']['celery']['handlers']:
logfile = settings.LOGGING['handlers']['celery']['filename']
pipe = options.get('pipe', '')
if not pipe:
handler_names = settings.LOGGING.get('loggers', {}).get('celery', {}).get('handlers', [])
if 'console' not in handler_names and 'celery' in handler_names:
logfile = settings.LOGGING.get('handlers', {}).get('celery', {}).get('filename', None)
if logfile:
pipe = '>> {} 2>&1'.format(logfile)
except KeyError:
pass
pipe = pipe or ''
loglevel = options['loglevel'] or ('DEBUG' if settings.DEBUG else 'INFO')
celery_options = [
@ -101,7 +100,7 @@ class Command(BaseCommand):
'--pidfile={}'.format(options['celerybeat_pidfile']),
] + self._parse_suboptions(options['celerybeat_options'])
with lcd(settings.PROJECT_ROOT), hide('commands'): # pylint: disable=not-context-manager
with lcd(settings.PROJECT_ROOT): # pylint: disable=not-context-manager
if not options['celerybeat_only']:
local(self.celery_cmd(
cmd='celery worker', opts=' '.join(celery_options), pipe=pipe))

View File

@ -39,7 +39,7 @@ class Command(BaseCommand):
check_pidfiles.append((name, pidfile))
except Exception as e: # pylint: disable=broad-except
self.stdout.write(self.style.NOTICE(
"ERROR: an exception occurred while stopping '{}':\n{}\n".format(name, e)))
"WARNING: an exception occurred while stopping '{}': {}\n".format(name, e)))
if check_pidfiles:
self.stdout.write("Waiting for processes to shutdown...\n")
@ -49,9 +49,12 @@ class Command(BaseCommand):
time.sleep(1)
wait_sec += 1
if os.path.exists(pidfile):
self.stdout.write(self.style.NOTICE(
"WARNING: file '{}' still exists after stopping {}.".format(
self.stdout.write(self.style.NOTICE((
"WARNING: file '{}' still exists after stopping {}. "
"Removing it manually.").format(
pidfile, name)))
with quiet():
local('rm -f {}'.format(pidfile))
else:
self.stdout.write(self.style.SUCCESS(
"Successfully stopped '{}'.".format(name)))
@ -59,4 +62,3 @@ class Command(BaseCommand):
with quiet():
local("ps auxww | grep '[c]elery worker' | awk '{print $2}' | xargs kill -9")
local("ps auxww | grep '[c]elerybeat' | awk '{print $2}' | xargs kill -9")
local('rm -f {} {}'.format(options['celery_pidfile'], options['celerybeat_pidfile']))