Use profiles for replication
This commit is contained in:
20
main.py
20
main.py
@@ -62,6 +62,15 @@ def upload_file(filename: str, key: str, bucket: str):
|
|||||||
client.put_object(Body=f.read(), Bucket=bucket, Key=key)
|
client.put_object(Body=f.read(), Bucket=bucket, Key=key)
|
||||||
|
|
||||||
|
|
||||||
|
def get_branch(bndname: str, scheme: str):
|
||||||
|
conn = db.connect_db()
|
||||||
|
with Session(conn) as session:
|
||||||
|
item = session.query(db.IncomeBranch).filter_by(scheme=scheme).join(db.User).filter_by(bndname=bndname).one_or_none()
|
||||||
|
if item:
|
||||||
|
return item.branch
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
def run_tasks():
|
def run_tasks():
|
||||||
logger.debug('Task thread started.')
|
logger.debug('Task thread started.')
|
||||||
while True:
|
while True:
|
||||||
@@ -325,8 +334,10 @@ def pika_callback(ch, method, properties, body):
|
|||||||
conn = db.connect_db()
|
conn = db.connect_db()
|
||||||
with Session(conn) as session:
|
with Session(conn) as session:
|
||||||
for user in session.query(db.User).filter(db.User.active == True, db.User.upstream == False).all():
|
for user in session.query(db.User).filter(db.User.active == True, db.User.upstream == False).all():
|
||||||
item = db.Queue(user_id=user.id, commit_id=commit, schema=schema)
|
profiles = {x.scheme: x.to_dict() for x in user.profiles}
|
||||||
session.add(item)
|
if len(profiles) == 0 or schema in profiles:
|
||||||
|
item = db.Queue(user_id=user.id, commit_id=commit, schema=schema)
|
||||||
|
session.add(item)
|
||||||
session.commit()
|
session.commit()
|
||||||
ch.basic_ack(delivery_tag=method.delivery_tag)
|
ch.basic_ack(delivery_tag=method.delivery_tag)
|
||||||
|
|
||||||
@@ -543,10 +554,8 @@ def put_object(params, files, url):
|
|||||||
|
|
||||||
|
|
||||||
def apply_commits(params, files, url):
|
def apply_commits(params, files, url):
|
||||||
logger.warning(params)
|
|
||||||
assert len(files) == 1
|
assert len(files) == 1
|
||||||
file = files[0]
|
file = files[0]
|
||||||
logger.warning(file)
|
|
||||||
dir = TemporaryDirectory()
|
dir = TemporaryDirectory()
|
||||||
r = requests.get(file['url'])
|
r = requests.get(file['url'])
|
||||||
with zipfile.ZipFile(io.BytesIO(r.content)) as zip_ref:
|
with zipfile.ZipFile(io.BytesIO(r.content)) as zip_ref:
|
||||||
@@ -555,8 +564,7 @@ def apply_commits(params, files, url):
|
|||||||
repl = req.find('replication')
|
repl = req.find('replication')
|
||||||
scheme = repl.get('scheme')
|
scheme = repl.get('scheme')
|
||||||
commit = repl.get('id')
|
commit = repl.get('id')
|
||||||
logger.warning(scheme)
|
branch = get_branch(params['from'].replace('tcp://', ''), scheme)
|
||||||
logger.warning(commit)
|
|
||||||
con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
|
con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,
|
||||||
Config.oodb_username, Config.oodb_passwd, scheme)
|
Config.oodb_username, Config.oodb_passwd, scheme)
|
||||||
ws = OODBWorkspace.ws(scheme)
|
ws = OODBWorkspace.ws(scheme)
|
||||||
|
|||||||
Reference in New Issue
Block a user