Skip to content

Commit

Permalink
Fix crossplatform log and pid files in multi mode
Browse files Browse the repository at this point in the history
it relates to celery#6017
  • Loading branch information
mchataigner committed May 17, 2020
1 parent 736e93d commit a6171e6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
4 changes: 2 additions & 2 deletions celery/apps/multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ def _setdefaultopt(self, d, alt, value):
return d[opt]
except KeyError:
pass
path_split = value.split("/")
dir_path = "/".join(path_split[0:-1])
value = os.path.normpath(value)
dir_path = os.path.dirname(value)
if not os.path.exists(dir_path):
os.makedirs(dir_path)
return d.setdefault(alt[0], value)
Expand Down
23 changes: 12 additions & 11 deletions t/unit/apps/test_multi.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import errno
import signal
import sys
import os

import pytest
from case import Mock, call, patch, skip
Expand Down Expand Up @@ -113,8 +114,8 @@ def assert_line_in(name, args):

def _args(name, *args):
return args + (
'--pidfile=/var/run/celery/{}.pid'.format(name),
'--logfile=/var/log/celery/{}%I.log'.format(name),
'--pidfile={}.pid'.format(os.path.join(os.path.normpath('/var/run/celery/'), name)),
'--logfile={}%I.log'.format(os.path.join(os.path.normpath('/var/log/celery/'), name)),
'--executable={0}'.format(sys.executable),
'',
)
Expand Down Expand Up @@ -194,10 +195,10 @@ def test_from_kwargs(self):
'--executable={0}'.format(n.executable),
'-O fair',
'-n [email protected]',
'--logfile=/var/log/celery/foo%I.log',
'--logfile={}'.format(os.path.normpath('/var/log/celery/foo%I.log')),
'-Q q1,q2',
'--max-tasks-per-child=30',
'--pidfile=/var/run/celery/foo.pid',
'--pidfile={}'.format(os.path.normpath('/var/run/celery/foo.pid')),
'',
])

Expand Down Expand Up @@ -275,7 +276,7 @@ def test_handle_process_exit__signalled(self):

def test_logfile(self):
assert self.node.logfile == self.expander.return_value
self.expander.assert_called_with('/var/log/celery/%n%I.log')
self.expander.assert_called_with(os.path.normpath('/var/log/celery/%n%I.log'))


class test_Cluster:
Expand Down Expand Up @@ -375,8 +376,8 @@ def test_getpids(self):
assert sorted(node_0.argv) == sorted([
'',
'--executable={0}'.format(node_0.executable),
'--logfile=/var/log/celery/foo%I.log',
'--pidfile=/var/run/celery/foo.pid',
'--logfile={}'.format(os.path.normpath('/var/log/celery/foo%I.log')),
'--pidfile={}'.format(os.path.normpath('/var/run/celery/foo.pid')),
'-m celery worker --detach',
'-n [email protected]',
])
Expand All @@ -386,8 +387,8 @@ def test_getpids(self):
assert sorted(node_1.argv) == sorted([
'',
'--executable={0}'.format(node_1.executable),
'--logfile=/var/log/celery/bar%I.log',
'--pidfile=/var/run/celery/bar.pid',
'--logfile={}'.format(os.path.normpath('/var/log/celery/bar%I.log')),
'--pidfile={}'.format(os.path.normpath('/var/run/celery/bar.pid')),
'-m celery worker --detach',
'-n [email protected]',
])
Expand All @@ -404,8 +405,8 @@ def __init__(self, path):

def read_pid(self):
try:
return {'/var/run/celery/foo.pid': 10,
'/var/run/celery/bar.pid': 11}[self.path]
return {os.path.normpath('/var/run/celery/foo.pid'): 10,
os.path.normpath('/var/run/celery/bar.pid'): 11}[self.path]
except KeyError:
raise ValueError()
self.Pidfile.side_effect = pids

0 comments on commit a6171e6

Please sign in to comment.