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)
| 338 | @click.pass_context |
| 339 | @handle_preload_options |
| 340 | def worker(ctx, hostname=None, pool_cls=None, app=None, uid=None, gid=None, |
| 341 | loglevel=None, logfile=None, pidfile=None, statedb=None, |
| 342 | **kwargs): |
| 343 | """Start worker instance. |
| 344 | |
| 345 | \b |
| 346 | Examples |
| 347 | -------- |
| 348 | |
| 349 | \b |
| 350 | $ celery --app=proj worker -l INFO |
| 351 | $ celery -A proj worker -l INFO -Q hipri,lopri |
| 352 | $ celery -A proj worker --concurrency=4 |
| 353 | $ celery -A proj worker --concurrency=1000 -P eventlet |
| 354 | $ celery worker --autoscale=10,0 |
| 355 | |
| 356 | """ |
| 357 | try: |
| 358 | app = ctx.obj.app |
| 359 | if 'disable_prefetch' in kwargs and kwargs['disable_prefetch'] is not None: |
| 360 | app.conf.worker_disable_prefetch = kwargs.pop('disable_prefetch') |
| 361 | if ctx.args: |
| 362 | try: |
| 363 | app.config_from_cmdline(ctx.args, namespace='worker') |
| 364 | except (KeyError, ValueError) as e: |
| 365 | # TODO: Improve the error messages |
| 366 | raise click.UsageError( |
| 367 | "Unable to parse extra configuration from command line.\n" |
| 368 | f"Reason: {e}", ctx=ctx) |
| 369 | if kwargs.get('detach', False): |
| 370 | argv = ['-m', 'celery'] + sys.argv[1:] |
| 371 | if '--detach' in argv: |
| 372 | argv.remove('--detach') |
| 373 | if '-D' in argv: |
| 374 | argv.remove('-D') |
| 375 | if "--uid" in argv: |
| 376 | argv.remove('--uid') |
| 377 | if "--gid" in argv: |
| 378 | argv.remove('--gid') |
| 379 | |
| 380 | return detach(sys.executable, |
| 381 | argv, |
| 382 | logfile=logfile, |
| 383 | pidfile=pidfile, |
| 384 | uid=uid, gid=gid, |
| 385 | umask=kwargs.get('umask', None), |
| 386 | workdir=kwargs.get('workdir', None), |
| 387 | app=app, |
| 388 | executable=kwargs.get('executable', None), |
| 389 | hostname=hostname) |
| 390 | |
| 391 | maybe_drop_privileges(uid=uid, gid=gid) |
| 392 | worker = app.Worker( |
| 393 | hostname=hostname, pool_cls=pool_cls, loglevel=loglevel, |
| 394 | logfile=logfile, # node format handled by celery.app.log.setup |
| 395 | pidfile=node_format(pidfile, hostname), |
| 396 | statedb=node_format(statedb, hostname), |
| 397 | no_color=ctx.obj.no_color, |
nothing calls this directly
no test coverage detected