API refactor
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-10-07 16:25:52 +09:00
parent 76d0d86211
commit 91c7e04474
1171 changed files with 81940 additions and 44117 deletions

View File

@@ -11,7 +11,6 @@ except ImportError:
import click
import click.exceptions
from click.types import ParamType
from click_didyoumean import DYMGroup
from click_plugins import with_plugins
@@ -48,34 +47,6 @@ Unable to load celery application.
{0}""")
class App(ParamType):
"""Application option."""
name = "application"
def convert(self, value, param, ctx):
try:
return find_app(value)
except ModuleNotFoundError as e:
if e.name != value:
exc = traceback.format_exc()
self.fail(
UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)
)
self.fail(UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND.format(e.name))
except AttributeError as e:
attribute_name = e.args[0].capitalize()
self.fail(UNABLE_TO_LOAD_APP_APP_MISSING.format(attribute_name))
except Exception:
exc = traceback.format_exc()
self.fail(
UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(value, exc)
)
APP = App()
if sys.version_info >= (3, 10):
_PLUGINS = entry_points(group='celery.commands')
else:
@@ -91,7 +62,11 @@ else:
'--app',
envvar='APP',
cls=CeleryOption,
type=APP,
# May take either: a str when invoked from command line (Click),
# or a Celery object when invoked from inside Celery; hence the
# need to prevent Click from "processing" the Celery object and
# converting it into its str representation.
type=click.UNPROCESSED,
help_group="Global Options")
@click.option('-b',
'--broker',
@@ -160,6 +135,26 @@ def celery(ctx, app, broker, result_backend, loader, config, workdir,
os.environ['CELERY_CONFIG_MODULE'] = config
if skip_checks:
os.environ['CELERY_SKIP_CHECKS'] = 'true'
if isinstance(app, str):
try:
app = find_app(app)
except ModuleNotFoundError as e:
if e.name != app:
exc = traceback.format_exc()
ctx.fail(
UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(app, exc)
)
ctx.fail(UNABLE_TO_LOAD_APP_MODULE_NOT_FOUND.format(e.name))
except AttributeError as e:
attribute_name = e.args[0].capitalize()
ctx.fail(UNABLE_TO_LOAD_APP_APP_MISSING.format(attribute_name))
except Exception:
exc = traceback.format_exc()
ctx.fail(
UNABLE_TO_LOAD_APP_ERROR_OCCURRED.format(app, exc)
)
ctx.obj = CLIContext(app=app, no_color=no_color, workdir=workdir,
quiet=quiet)