MCPcopy
hub / github.com/celery/celery / worker

Function worker

celery/bin/worker.py:307–371  ·  view source on GitHub ↗

Start worker instance. \b Examples -------- \b $ celery --app=proj worker -l INFO $ celery -A proj worker -l INFO -Q hipri,lopri $ celery -A proj worker --concurrency=4 $ celery -A proj worker --concurrency=1000 -P eventlet $ celery worker --autoscale=10,0

(ctx, hostname=None, pool_cls=None, app=None, uid=None, gid=None,
           loglevel=None, logfile=None, pidfile=None, statedb=None,
           **kwargs)

Source from the content-addressed store, hash-verified

305@click.pass_context
306@handle_preload_options
307def worker(ctx, hostname=None, pool_cls=None, app=None, uid=None, gid=None,
308 loglevel=None, logfile=None, pidfile=None, statedb=None,
309 **kwargs):
310 """Start worker instance.
311
312 \b
313 Examples
314 --------
315
316 \b
317 $ celery --app=proj worker -l INFO
318 $ celery -A proj worker -l INFO -Q hipri,lopri
319 $ celery -A proj worker --concurrency=4
320 $ celery -A proj worker --concurrency=1000 -P eventlet
321 $ celery worker --autoscale=10,0
322
323 """
324 try:
325 app = ctx.obj.app
326 if 'disable_prefetch' in kwargs and kwargs['disable_prefetch'] is not None:
327 app.conf.worker_disable_prefetch = kwargs.pop('disable_prefetch')
328 if ctx.args:
329 try:
330 app.config_from_cmdline(ctx.args, namespace='worker')
331 except (KeyError, ValueError) as e:
332 # TODO: Improve the error messages
333 raise click.UsageError(
334 "Unable to parse extra configuration from command line.\n"
335 f"Reason: {e}", ctx=ctx)
336 if kwargs.get('detach', False):
337 argv = ['-m', 'celery'] + sys.argv[1:]
338 if '--detach' in argv:
339 argv.remove('--detach')
340 if '-D' in argv:
341 argv.remove('-D')
342 if "--uid" in argv:
343 argv.remove('--uid')
344 if "--gid" in argv:
345 argv.remove('--gid')
346
347 return detach(sys.executable,
348 argv,
349 logfile=logfile,
350 pidfile=pidfile,
351 uid=uid, gid=gid,
352 umask=kwargs.get('umask', None),
353 workdir=kwargs.get('workdir', None),
354 app=app,
355 executable=kwargs.get('executable', None),
356 hostname=hostname)
357
358 maybe_drop_privileges(uid=uid, gid=gid)
359 worker = app.Worker(
360 hostname=hostname, pool_cls=pool_cls, loglevel=loglevel,
361 logfile=logfile, # node format handled by celery.app.log.setup
362 pidfile=node_format(pidfile, hostname),
363 statedb=node_format(statedb, hostname),
364 no_color=ctx.obj.no_color,

Callers

nothing calls this directly

Calls 10

maybe_drop_privilegesFunction · 0.90
node_formatFunction · 0.90
detachFunction · 0.85
config_from_cmdlineMethod · 0.80
WorkerMethod · 0.80
popMethod · 0.45
getMethod · 0.45
removeMethod · 0.45
startMethod · 0.45
errorMethod · 0.45

Tested by

no test coverage detected