Correcting replication and no_files flag
All checks were successful
Build xmlrpcserver image / Build (push) Successful in 56s

This commit is contained in:
Ivan Vazhenin
2024-04-08 20:30:34 +03:00
parent 219b597042
commit cdaccb911b
2 changed files with 61 additions and 16 deletions

1
db.py
View File

@@ -77,6 +77,7 @@ class Profile(Base):
scheme: Mapped[str] scheme: Mapped[str]
branch: Mapped[str] = mapped_column(String, nullable=True) branch: Mapped[str] = mapped_column(String, nullable=True)
json: Mapped[str] = mapped_column(String, nullable=True) json: Mapped[str] = mapped_column(String, nullable=True)
no_files: Mapped[bool]
user: Mapped['User'] = relationship(back_populates='profiles') user: Mapped['User'] = relationship(back_populates='profiles')

76
main.py
View File

@@ -80,6 +80,15 @@ def get_branch(bndname: str, scheme: str):
return None, None return None, None
def get_profile(bndname: str, scheme: str):
conn = db.connect_db()
with Session(conn) as session:
item = session.query(db.Profile).filter_by(scheme=scheme).join(db.User).filter_by(bndname=bndname).one_or_none()
if item:
return item
return None
def run_tasks(): def run_tasks():
logger.debug('Task thread started.') logger.debug('Task thread started.')
while True: while True:
@@ -256,6 +265,8 @@ def replication(bnd_name: str, commit_id: str, schema: str):
rxmls = RequestXmlService() rxmls = RequestXmlService()
res_id = uuid4().hex res_id = uuid4().hex
profile = get_profile(bndname=bnd_name, scheme=schema)
res = rxmls.get_request_document(res_id, None) res = rxmls.get_request_document(res_id, None)
rxmls.set_result(res, 0, '') rxmls.set_result(res, 0, '')
ET.SubElement(res, 'replication', {'id': commit_id, 'scheme': schema}) ET.SubElement(res, 'replication', {'id': commit_id, 'scheme': schema})
@@ -307,22 +318,23 @@ def replication(bnd_name: str, commit_id: str, schema: str):
qu.setUids(created) qu.setUids(created)
ws.load(qu, uids) ws.load(qu, uids)
exported_files = [] exported_files = []
for feature_uid in uids: if not profile or not profile.no_files:
feature = ws.featureByUid(feature_uid) for feature_uid in uids:
if not feature: feature = ws.featureByUid(feature_uid)
continue if not feature:
for attr in feature.attributes('c1000'): continue
updated_files.append(variantToFileValue(attr.val())) for attr in feature.attributes('c1000'):
# updated_files.append(feature_uid) updated_files.append(variantToFileValue(attr.val()))
for x in updated_files: # updated_files.append(feature_uid)
exported_files.append({ for x in updated_files:
'key': x.key, exported_files.append({
'bucket': x.bucket, 'key': x.key,
'filename': x.fileName, 'bucket': x.bucket,
}) 'filename': x.fileName,
fp = os.path.join(z.dirname, x.key) })
os.makedirs(os.path.dirname(fp), exist_ok=True) fp = os.path.join(z.dirname, x.key)
download_file(x.key, x.bucket, fp) os.makedirs(os.path.dirname(fp), exist_ok=True)
download_file(x.key, x.bucket, fp)
with open(os.path.join(z.dirname, 'export_files.json'), 'w') as f: with open(os.path.join(z.dirname, 'export_files.json'), 'w') as f:
f.write(json.dumps(exported_files)) f.write(json.dumps(exported_files))
ws.clearData(True) ws.clearData(True)
@@ -898,6 +910,38 @@ async def correction_replication(bnd_name: str, schema: str):
logger.error('Error sending') logger.error('Error sending')
@app.get("/get_cr")
async def correction_replication(bnd_name: str, schema: str):
date = datetime.datetime.now()
rxmls = RequestXmlService()
res_id = uuid4().hex
res = rxmls.get_request_document(res_id, None)
con = OOConnectionParams(schema, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
Config.oodb_username, Config.oodb_passwd, schema)
ws = OODBWorkspace.ws(schema)
if not ws.isInit():
res = ws.init(con)
logger.warning(res)
ET.SubElement(res, 'commit', {'id': ws.currentCommit(), 'schema': schema})
params = {
'from': f'tcp://{Config.self_bnd}',
'to': f'tcp://{bnd_name}',
'ts_added': date.timestamp(),
'user_id': '0',
'query_type': NEW_COMMIT_RESPONSE,
'query_data': ET.tostring(res, encoding='unicode', xml_declaration=True),
}
proxy = ServerProxy(Config.enserver)
try:
proxy.send(params, [], Config.ret_path)
except:
logger.error('Error sending')
def main(): def main():
global connection global connection
global server global server