Skip to content
Snippets Groups Projects
Commit 327db9c3 authored by Cornelia Michlits's avatar Cornelia Michlits
Browse files

add cronjobs

parent d05bbd1c
No related branches found
No related tags found
1 merge request!103241 modify bstat
FROM python:3.8-slim FROM python:3.8-bullseye
MAINTAINER Cornelia Michlits <cornelia.michlits@tuwien.ac.at> MAINTAINER Cornelia Michlits <cornelia.michlits@tuwien.ac.at>
ENV FLASK_APP=app.py ENV FLASK_APP=app.py
...@@ -8,6 +8,9 @@ ENV FLASK_ENV=production ...@@ -8,6 +8,9 @@ ENV FLASK_ENV=production
ENV HOSTNAME=analyse-service ENV HOSTNAME=analyse-service
ENV EUREKA_SERVER=http://discovery-service:9090/eureka/ ENV EUREKA_SERVER=http://discovery-service:9090/eureka/
COPY cronjobs /etc/crontabs/root
CMD ["crond", "-f", "-d", "8"]
WORKDIR /app WORKDIR /app
COPY requirements.txt requirements.txt COPY requirements.txt requirements.txt
......
...@@ -4,14 +4,14 @@ from sqlalchemy import create_engine, text ...@@ -4,14 +4,14 @@ from sqlalchemy import create_engine, text
import requests import requests
import json import json
def update_bstatistic(dbid, tid): def update_bstatistic(dbid, tid):
logging.info("called update_bstatistic") logging.info("called update_bstatistic")
# Get database info # Get database info
try: try:
s = requests.get( s = requests.get(
"http://fda-database-service:9092/api/database/", "http://fda-database-service:9092/api/database/",
params = {"id":dbid} params = {"id":dbid},
headers=headers
).json() ).json()
logging.info("s", s) logging.info("s", s)
...@@ -21,7 +21,7 @@ def update_bstatistic(dbid, tid): ...@@ -21,7 +21,7 @@ def update_bstatistic(dbid, tid):
# Get tablename by dbid and tid # Get tablename by dbid and tid
try: try:
tbl_info = requests.get( tbl_info = requests.get(
"http://fda-table-service:9094/api/database/{0}/table/{1}/".format(dbid,tid)).json() "http://fda-table-service:9094/api/database/{0}/table/{1}/".format(dbid,tid), headers=headers).json()
logging.info(tbl_info) logging.info(tbl_info)
tbl_name = tbl_info['internalName'] tbl_name = tbl_info['internalName']
except Exception as e: except Exception as e:
...@@ -62,12 +62,15 @@ def update_bstatistic(dbid, tid): ...@@ -62,12 +62,15 @@ def update_bstatistic(dbid, tid):
logging.info("insert mdb_columns_nom_cat: " + row) logging.info("insert mdb_columns_nom_cat: " + row)
insert_mdb_catcol(row[0], row[1], row[2]) insert_mdb_catcol(row[0], row[1], row[2])
cursor.close() cursor.close()
cursor = conn.cursor()
cursor.execute("SELECT value FROM mdb_images_environment_item where key=%s",'ROOT')
value=cursor.fetchone()
except Exception as e: except Exception as e:
print("Error while trying to get cname from mdb",e) print("Error while trying to get cname from mdb",e)
# Conneting to database # Conneting to database
try: try:
engine = create_engine('mysql+pymysql://mariadb:mariadb@dbrepo-userdb-'+s[0]['internalName'].replace('_', '-')+'/'+s[0]['internalName']) engine = create_engine('mysql+pymysql://root:'+str(value)+'@dbrepo-userdb-'+s[0]['internalName'].replace('_', '-')+'/'+s[0]['internalName'])
sql = text("""SELECT column_name, columns.data_type, columns.ordinal_position, is_nullable sql = text("""SELECT column_name, columns.data_type, columns.ordinal_position, is_nullable
from information_schema.columns from information_schema.columns
...@@ -111,7 +114,7 @@ def insert_mdb_nomcol(dbid, tid, cid): ...@@ -111,7 +114,7 @@ def insert_mdb_nomcol(dbid, tid, cid):
except Exception as e: except Exception as e:
print("Error:", e) print("Error:", e)
try: try:
engine = create_engine('mysql+pymysql://mariadb:mariadb@dbrepo-userdb-'+s[0]['internalName'].replace('_', '-')+'/'+s[0]['internalName']) engine = create_engine('mysql+pymysql://root:'+str(value)+'@dbrepo-userdb-'+s[0]['internalName'].replace('_', '-')+'/'+s[0]['internalName'])
sql = text("select max(char_length(" + cname + ")) from " + tbl_name) sql = text("select max(char_length(" + cname + ")) from " + tbl_name)
...@@ -179,7 +182,7 @@ def insert_mdb_numcol(dbid, tid, cid): ...@@ -179,7 +182,7 @@ def insert_mdb_numcol(dbid, tid, cid):
# 'internalName']) # 'internalName'])
# Mariadb engine # Mariadb engine
engine = create_engine( engine = create_engine(
'mysql+pymysql://mariadb:mariadb@dbrepo-userdb-' + s[0]['internalName'].replace('_', '-') + '/' + s[0][ 'mysql+pymysql://root:'+str(value)+'@dbrepo-userdb-' + s[0]['internalName'].replace('_', '-') + '/' + s[0][
'internalName']) 'internalName'])
# min # min
...@@ -287,7 +290,7 @@ def insert_mdb_catcol(dbid, tid, cid): ...@@ -287,7 +290,7 @@ def insert_mdb_catcol(dbid, tid, cid):
# 'internalName']) # 'internalName'])
# Mariadb engine # Mariadb engine
engine = create_engine( engine = create_engine(
'mysql+pymysql://mariadb:mariadb@dbrepo-userdb-' + s[0]['internalName'].replace('_', '-') + '/' + s[0][ 'mysql+pymysql://root:'+str(value)+'@dbrepo-userdb-' + s[0]['internalName'].replace('_', '-') + '/' + s[0][
'internalName']) 'internalName'])
# num_categories # num_categories
......
* * * * * python3 update_basic_statistics.py >> /was 2>&1
\ No newline at end of file
#!/usr/bin/env python3
import requests
USER='xyz'
PASSWORD='xyz'
auth_response = requests.post('http://fda-authentication-service:9097/api/auth',
json={'username': USER, 'password': PASSWORD}).json()
token = auth_response['token']
headers = {"Authorization": f"Bearer {token}"}
dbs = requests.get('http://fda-database-service:9092/api/database', headers=headers).json()
for db in dbs:
dbid = db['dbid']
tables = requests.get(f'http://fda-table-service:9094/api/database/{dbid}/table', headers=headers).json()
for table in tables:
tid = table['tid']
update = requests.post('/api/analyse/update_mdb_col', json={'dbid': dbid, 'tid': tid})
print(update)
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment