Skip to content

Commit

Permalink
The celery multi command now works as expected.
Browse files Browse the repository at this point in the history
  • Loading branch information
thedrow committed Oct 6, 2020
1 parent 86e0d93 commit 9b08813
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 4 deletions.
26 changes: 23 additions & 3 deletions celery/apps/multi.py
Expand Up @@ -150,7 +150,7 @@ def _setdefaultopt(self, d, alt, value):
pass
value = d.setdefault(alt[0], os.path.normpath(value))
dir_path = os.path.dirname(value)
if not os.path.exists(dir_path):
if dir_path and not os.path.exists(dir_path):
os.makedirs(dir_path)
return value

Expand All @@ -160,10 +160,30 @@ def _prepare_expander(self):
self.name, shortname, hostname)

def _prepare_argv(self):
cmd = self.expander(self.cmd).split(' ')
i = cmd.index('celery') + 1

options = self.options.copy()
for opt, value in self.options.items():
if opt in (
'-A', '--app',
'-b', '--broker',
'--result-backend',
'--loader',
'--config',
'--workdir',
'-C', '--no-color',
'-q', '--quiet',
):
cmd.insert(i, format_opt(opt, self.expander(value)))

options.pop(opt)

cmd = [' '.join(cmd)]
argv = tuple(
[self.expander(self.cmd)] +
cmd +
[format_opt(opt, self.expander(value))
for opt, value in self.options.items()] +
for opt, value in options.items()] +
[self.extra_args]
)
if self.append:
Expand Down
7 changes: 6 additions & 1 deletion celery/bin/multi.py
Expand Up @@ -471,4 +471,9 @@ def DOWN(self):
def multi(ctx):
"""Start multiple worker instances."""
cmd = MultiTool(quiet=ctx.obj.quiet, no_color=ctx.obj.no_color)
return cmd.execute_from_commandline([''] + ctx.args)
# In 4.x, celery multi ignores the global --app option.
# Since in 5.0 the --app option is global only we
# rearrange the arguments so that the MultiTool will parse them correctly.
args = sys.argv[1:]
args = args[args.index('multi'):] + args[:args.index('multi')]
return cmd.execute_from_commandline(args)

0 comments on commit 9b08813

Please sign in to comment.