Compare commits
2 Commits
5b17bba5bf
...
3fd2ec4762
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3fd2ec4762 | ||
|
|
36e23465a8 |
3
db.py
3
db.py
@@ -2,6 +2,7 @@ from datetime import datetime
|
||||
from typing import List, Optional
|
||||
from sqlalchemy import create_engine, String, select, ForeignKey, Enum
|
||||
from sqlalchemy.orm import Session, DeclarativeBase, Mapped, mapped_column, relationship
|
||||
from config import Config
|
||||
|
||||
|
||||
def tow(day: int, hour: int, minute: int):
|
||||
@@ -133,4 +134,4 @@ class Schemas(Base):
|
||||
|
||||
|
||||
def connect_db():
|
||||
return create_engine("postgresql+psycopg://postgres:Root12345678@10.10.8.83:32101/db")
|
||||
return create_engine(f"postgresql+psycopg://{Config.pg_username}:{Config.pg_password}@{Config.pg_host}:{Config.pg_port}/{Config.pg_dbname}")
|
||||
|
||||
18
main.py
18
main.py
@@ -12,6 +12,7 @@ from xmlrpc.server import SimpleXMLRPCServer
|
||||
from xmlrpc.client import ServerProxy
|
||||
import logging
|
||||
import os
|
||||
import io
|
||||
import zlib
|
||||
import os.path
|
||||
import requests
|
||||
@@ -70,7 +71,6 @@ def run_tasks():
|
||||
|
||||
def replication_task():
|
||||
while True:
|
||||
print()
|
||||
conn = db.connect_db()
|
||||
with Session(conn) as session:
|
||||
for bndname in connected:
|
||||
@@ -241,7 +241,7 @@ def replication(bnd_name: str, commit_id: str, schema: str):
|
||||
ET.SubElement(res, 'replication', {'id': commit_id, 'scheme': schema})
|
||||
response_params = {
|
||||
'from': f'tcp://{Config.self_bnd}',
|
||||
'to': f'tcp://{Config.remote_bnd}',
|
||||
'to': f'tcp://{bnd_name}',
|
||||
'ts_added': date.timestamp(),
|
||||
'user_id': '0',
|
||||
'query_type': NEW_REPLICATION_REQUEST,
|
||||
@@ -540,18 +540,20 @@ def put_object(params, files, url):
|
||||
|
||||
|
||||
def apply_commits(params, files, url):
|
||||
logger.warning(params, files, url)
|
||||
logger.warning(params)
|
||||
assert len(files) == 1
|
||||
file = files[0]
|
||||
logger.warning(file)
|
||||
dir = TemporaryDirectory()
|
||||
with zipfile.ZipFile(file, 'r') as zip_ref:
|
||||
r = requests.get(file['url'])
|
||||
with zipfile.ZipFile(io.BytesIO(r.content)) as zip_ref:
|
||||
zip_ref.extractall(dir.name)
|
||||
req = ET.fromstring(params['query_data'])
|
||||
repl = req.find('replication')
|
||||
scheme = repl.get('scheme')
|
||||
commit = repl.get('id')
|
||||
logger.warning(scheme, commit)
|
||||
os.path.join(dir.name, 'export.o5c')
|
||||
logger.warning(scheme)
|
||||
logger.warning(commit)
|
||||
con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
|
||||
Config.oodb_username, Config.oodb_passwd, scheme)
|
||||
ws = OODBWorkspace.ws(scheme)
|
||||
@@ -561,10 +563,10 @@ def apply_commits(params, files, url):
|
||||
oe = IpdExporter(ws)
|
||||
oe.improtFromOsm(os.path.join(dir.name, 'export.o5c'))
|
||||
oe.improtFromMbtiles(os.path.join(dir.name, 'export.mbtiles'))
|
||||
with open('export_files.json', 'r') as f:
|
||||
with open(os.path.join(dir.name, 'export_files.json'), 'r') as f:
|
||||
files_data = json.load(f)
|
||||
for file_data in files_data:
|
||||
upload_file(file_data['filename'], file_data['key'], file_data['bucket'])
|
||||
upload_file(os.path.join(dir.name, file_data['key']), file_data['key'], file_data['bucket'])
|
||||
|
||||
|
||||
def run_task(query_type, params, files, url):
|
||||
|
||||
Reference in New Issue
Block a user