restructured code

This commit is contained in:
Marvin Zhang
2019-03-06 10:11:07 +08:00
parent de3247269c
commit fc4c98eccf
45 changed files with 153 additions and 7 deletions

112
crawlab/.gitignore vendored Normal file
View File

@@ -0,0 +1,112 @@
.idea/
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
# node_modules
node_modules/
# egg-info
*.egg-info

View File

@@ -0,0 +1,4 @@
class ActionType:
APP = 'app'
FLOWER = 'flower'
RUN_ALL = 'run_all'

View File

@@ -1,11 +1,14 @@
import os
import shutil
import subprocess
from multiprocessing import Process
from flask import Flask, logging
import click
from flask import Flask
from flask_cors import CORS
from flask_restful import Api
from config import FLASK_HOST, FLASK_PORT, PROJECT_LOGS_FOLDER
from config import FLASK_HOST, FLASK_PORT, PROJECT_LOGS_FOLDER, BROKER_URL
from constants.manage import ActionType
from routes.deploys import DeployApi
from routes.files import FileApi
from routes.nodes import NodeApi
@@ -52,9 +55,36 @@ api.add_resource(StatsApi,
'/api/stats',
'/api/stats/<string:action>')
# create folder if it does not exist
if not os.path.exists(PROJECT_LOGS_FOLDER):
os.makedirs(PROJECT_LOGS_FOLDER)
def run_app():
# create folder if it does not exist
if not os.path.exists(PROJECT_LOGS_FOLDER):
os.makedirs(PROJECT_LOGS_FOLDER)
# run app instance
app.run(host=FLASK_HOST, port=FLASK_PORT)
def run_flower():
p = subprocess.Popen(['celery', 'flower', '-b', BROKER_URL], stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in iter(p.stdout.readline, 'b'):
if line.decode('utf-8') != '':
print(line.decode('utf-8'))
@click.command()
@click.argument('action', type=click.Choice([ActionType.APP, ActionType.FLOWER, ActionType.RUN_ALL]))
def main(action):
if action == ActionType.APP:
run_app()
elif action == ActionType.FLOWER:
run_flower()
elif action == ActionType.RUN_ALL:
p_flower = Process(target=run_flower)
p_flower.start()
p_app = Process(target=run_app)
p_app.start()
if __name__ == '__main__':
app.run(host=FLASK_HOST, port=FLASK_PORT)
main()

0
crawlab/test/__init__.py Normal file
View File