-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathapp_manager.py
85 lines (67 loc) · 1.91 KB
/
app_manager.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# -*- coding: utf-8 -*-
__author__ = 'AminHP'
# python imports
import os
# flask imports
from flask import Flask
from flask.ext.script import Manager
# project imports
from project.application import create_app
from project.config import DevelopmentConfig, DeploymentConfig, TestingConfig
manager = Manager(Flask('manager'))
@manager.command
def run():
"""
Run server on port 8080 with default config.
"""
app = create_app()
app.run(host='0.0.0.0', port=8080)
@manager.command
def develop():
"""
Run server on port 8080 with development config.
"""
app = create_app(DevelopmentConfig)
app.run(host='0.0.0.0', port=8080)
@manager.command
def deploy():
"""
Run server on port 8080 with deployment config.
"""
app = create_app(DeploymentConfig)
app.run(host='0.0.0.0', port=8080)
@manager.command
def testing():
"""
Run server on port 8080 with testing config.
"""
app = create_app(TestingConfig)
app.run(host='0.0.0.0', port=8080)
@manager.option(dest='config_file')
def custom_config(config_file):
"""
Run server on port 8080 with custom config file.
"""
app = create_app(config_file=os.path.abspath(config_file))
app.run(host='0.0.0.0', port=8080)
@manager.command
def celery():
"""
Run celery worker.
"""
app = create_app()
from mongoengine.connection import disconnect
from project.extensions import celery
from celery.bin import worker
disconnect()
worker = worker.worker(app=celery)
worker.run()
@manager.option('-r', dest='resource', required=False, help='Resource name')
@manager.option('-u', dest='url', required=False, default='http://localhost:8080', help='Server url')
def test(resource, url):
"""
Test api. You can specify a resource (like api_1.user) for single testing.
By default all resources will be tested.
"""
from tests import run
run(url, resource)