mirror of
https://github.com/viq/NewsBlur.git
synced 2025-04-13 09:38:09 +00:00
rename flask to flask_monitor and add import for docker settings
This commit is contained in:
parent
4609d04486
commit
753851f6a8
5 changed files with 18 additions and 12 deletions
|
@ -1,10 +1,16 @@
|
|||
from flask import Flask, abort
|
||||
import flask_settings as settings
|
||||
import os
|
||||
import psycopg2
|
||||
import MySQLdb
|
||||
import pymysql
|
||||
import pymongo
|
||||
import redis
|
||||
import pyes
|
||||
|
||||
if os.getenv("DOCKERBUILD") == "True":
|
||||
import newsblur.docker_local_settings as settings
|
||||
else:
|
||||
import flask_monitor.flask_settings as settings
|
||||
|
||||
app = Flask(__name__)
|
||||
|
||||
@app.route("/db_check/postgres")
|
||||
|
@ -19,14 +25,14 @@ def db_check_postgres():
|
|||
try:
|
||||
conn = psycopg2.connect(connect_params)
|
||||
except:
|
||||
print " ---> Postgres can't connect to the database: %s" % connect_params
|
||||
print(" ---> Postgres can't connect to the database: %s" % connect_params)
|
||||
abort(502)
|
||||
|
||||
cur = conn.cursor()
|
||||
cur.execute("""SELECT id FROM feeds ORDER BY feeds.id DESC LIMIT 1""")
|
||||
rows = cur.fetchall()
|
||||
for row in rows:
|
||||
return unicode(row[0])
|
||||
return str(row[0])
|
||||
|
||||
abort(404)
|
||||
|
||||
|
@ -41,20 +47,20 @@ def db_check_mysql():
|
|||
)
|
||||
try:
|
||||
|
||||
conn = MySQLdb.connect(host=settings.DATABASES['default']['HOST'],
|
||||
conn = pymysql.connect(host=settings.DATABASES['default']['HOST'],
|
||||
port=settings.DATABASES['default']['PORT'],
|
||||
user=settings.DATABASES['default']['USER'],
|
||||
passwd=settings.DATABASES['default']['PASSWORD'],
|
||||
db=settings.DATABASES['default']['NAME'])
|
||||
except:
|
||||
print " ---> Mysql can't connect to the database: %s" % connect_params
|
||||
print(" ---> Mysql can't connect to the database: %s" % connect_params)
|
||||
abort(502)
|
||||
|
||||
cur = conn.cursor()
|
||||
cur.execute("""SELECT id FROM feeds ORDER BY feeds.id DESC LIMIT 1""")
|
||||
rows = cur.fetchall()
|
||||
for row in rows:
|
||||
return unicode(row[0])
|
||||
return str(row[0])
|
||||
|
||||
abort(404)
|
||||
|
||||
|
@ -66,7 +72,7 @@ def db_check_mongo():
|
|||
except:
|
||||
abort(502)
|
||||
|
||||
return unicode(db.stories.count())
|
||||
return str(db.stories.count())
|
||||
|
||||
@app.route("/db_check/redis")
|
||||
def db_check_redis():
|
||||
|
@ -78,7 +84,7 @@ def db_check_redis():
|
|||
|
||||
randkey = r.randomkey()
|
||||
if randkey:
|
||||
return unicode(randkey)
|
||||
return str(randkey)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
|
@ -92,7 +98,7 @@ def db_check_redis_story():
|
|||
|
||||
randkey = r.randomkey()
|
||||
if randkey:
|
||||
return unicode(randkey)
|
||||
return str(randkey)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
|
@ -106,7 +112,7 @@ def db_check_redis_sessions():
|
|||
|
||||
randkey = r.randomkey()
|
||||
if randkey:
|
||||
return unicode(randkey)
|
||||
return str(randkey)
|
||||
else:
|
||||
abort(404)
|
||||
|
||||
|
@ -119,7 +125,7 @@ def db_check_elasticsearch():
|
|||
abort(502)
|
||||
|
||||
if conn.indices.exists_index('feeds-index'):
|
||||
return unicode("Index exists, but didn't try search")
|
||||
return str("Index exists, but didn't try search")
|
||||
# query = pyes.query.TermQuery("title", "daring fireball")
|
||||
# results = conn.search(query=query, size=1, doc_types=['feeds-type'], sort="num_subscribers:desc")
|
||||
# for result in results:
|
Loading…
Add table
Reference in a new issue