mirror of
https://github.com/viq/NewsBlur.git
synced 2025-08-05 16:49:45 +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
|
from flask import Flask, abort
|
||||||
import flask_settings as settings
|
import os
|
||||||
import psycopg2
|
import psycopg2
|
||||||
import MySQLdb
|
import pymysql
|
||||||
import pymongo
|
import pymongo
|
||||||
import redis
|
import redis
|
||||||
import pyes
|
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 = Flask(__name__)
|
||||||
|
|
||||||
@app.route("/db_check/postgres")
|
@app.route("/db_check/postgres")
|
||||||
|
@ -19,14 +25,14 @@ def db_check_postgres():
|
||||||
try:
|
try:
|
||||||
conn = psycopg2.connect(connect_params)
|
conn = psycopg2.connect(connect_params)
|
||||||
except:
|
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)
|
abort(502)
|
||||||
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute("""SELECT id FROM feeds ORDER BY feeds.id DESC LIMIT 1""")
|
cur.execute("""SELECT id FROM feeds ORDER BY feeds.id DESC LIMIT 1""")
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
return unicode(row[0])
|
return str(row[0])
|
||||||
|
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@ -41,20 +47,20 @@ def db_check_mysql():
|
||||||
)
|
)
|
||||||
try:
|
try:
|
||||||
|
|
||||||
conn = MySQLdb.connect(host=settings.DATABASES['default']['HOST'],
|
conn = pymysql.connect(host=settings.DATABASES['default']['HOST'],
|
||||||
port=settings.DATABASES['default']['PORT'],
|
port=settings.DATABASES['default']['PORT'],
|
||||||
user=settings.DATABASES['default']['USER'],
|
user=settings.DATABASES['default']['USER'],
|
||||||
passwd=settings.DATABASES['default']['PASSWORD'],
|
passwd=settings.DATABASES['default']['PASSWORD'],
|
||||||
db=settings.DATABASES['default']['NAME'])
|
db=settings.DATABASES['default']['NAME'])
|
||||||
except:
|
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)
|
abort(502)
|
||||||
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute("""SELECT id FROM feeds ORDER BY feeds.id DESC LIMIT 1""")
|
cur.execute("""SELECT id FROM feeds ORDER BY feeds.id DESC LIMIT 1""")
|
||||||
rows = cur.fetchall()
|
rows = cur.fetchall()
|
||||||
for row in rows:
|
for row in rows:
|
||||||
return unicode(row[0])
|
return str(row[0])
|
||||||
|
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@ -66,7 +72,7 @@ def db_check_mongo():
|
||||||
except:
|
except:
|
||||||
abort(502)
|
abort(502)
|
||||||
|
|
||||||
return unicode(db.stories.count())
|
return str(db.stories.count())
|
||||||
|
|
||||||
@app.route("/db_check/redis")
|
@app.route("/db_check/redis")
|
||||||
def db_check_redis():
|
def db_check_redis():
|
||||||
|
@ -78,7 +84,7 @@ def db_check_redis():
|
||||||
|
|
||||||
randkey = r.randomkey()
|
randkey = r.randomkey()
|
||||||
if randkey:
|
if randkey:
|
||||||
return unicode(randkey)
|
return str(randkey)
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@ -92,7 +98,7 @@ def db_check_redis_story():
|
||||||
|
|
||||||
randkey = r.randomkey()
|
randkey = r.randomkey()
|
||||||
if randkey:
|
if randkey:
|
||||||
return unicode(randkey)
|
return str(randkey)
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@ -106,7 +112,7 @@ def db_check_redis_sessions():
|
||||||
|
|
||||||
randkey = r.randomkey()
|
randkey = r.randomkey()
|
||||||
if randkey:
|
if randkey:
|
||||||
return unicode(randkey)
|
return str(randkey)
|
||||||
else:
|
else:
|
||||||
abort(404)
|
abort(404)
|
||||||
|
|
||||||
|
@ -119,7 +125,7 @@ def db_check_elasticsearch():
|
||||||
abort(502)
|
abort(502)
|
||||||
|
|
||||||
if conn.indices.exists_index('feeds-index'):
|
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")
|
# query = pyes.query.TermQuery("title", "daring fireball")
|
||||||
# results = conn.search(query=query, size=1, doc_types=['feeds-type'], sort="num_subscribers:desc")
|
# results = conn.search(query=query, size=1, doc_types=['feeds-type'], sort="num_subscribers:desc")
|
||||||
# for result in results:
|
# for result in results:
|
Loading…
Add table
Reference in a new issue