-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmain.py
64 lines (47 loc) · 1.6 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python3
from faceanalysis.api import app as application
from faceanalysis.log import get_logger
from faceanalysis.models import delete_models
from faceanalysis.models import init_models
from faceanalysis.settings import FACE_VECTORIZE_ALGORITHM
from faceanalysis.settings import IMAGE_PROCESSOR_CONCURRENCY
from faceanalysis.settings import IMAGE_PROCESSOR_QUEUE
from faceanalysis.settings import LOGGING_LEVEL
from faceanalysis.tasks import celery
logger = get_logger(__name__)
class Commands:
@classmethod
def worker(cls):
if FACE_VECTORIZE_ALGORITHM == 'FaceApi':
logger.warning('FaceApi backend detected: not starting worker')
return
celery.worker_main([
'--queues={}'.format(IMAGE_PROCESSOR_QUEUE),
'--concurrency={}'.format(IMAGE_PROCESSOR_CONCURRENCY),
'--loglevel={}'.format(LOGGING_LEVEL),
'-Ofair',
])
@classmethod
def runserver(cls):
application.run()
@classmethod
def createdb(cls):
init_models()
@classmethod
def dropdb(cls):
delete_models()
def _main(command: str):
command = getattr(Commands, command)
command()
def _cli():
from argparse import ArgumentParser
from inspect import getmembers
from inspect import ismethod
all_commands = [name for name, _ in
getmembers(Commands, predicate=ismethod)]
parser = ArgumentParser(description=__doc__)
parser.add_argument('command', choices=all_commands)
args = parser.parse_args()
_main(args.command)
if __name__ == '__main__':
_cli()