Commit 73e98dac authored by Alejandro Alvarez Ayllon's avatar Alejandro Alvarez Ayllon
Browse files

FTS-630: Patch to work with old and new schema

parent 752cd136
......@@ -554,16 +554,27 @@ class JobsController(BaseController):
# Insert into the optimizer
unique_pairs = set(map(lambda f: (f['source_se'], f['dest_se']), populated.files))
for source_se, dest_se in unique_pairs:
if not Session.query(OptimizerActive).get((source_se, dest_se)):
optimizer_active = OptimizerActive()
optimizer_active.source_se = source_se
optimizer_active.dest_se = dest_se
optimizer_active.ema = 0
optimizer_active.datetime = datetime.utcnow()
if len(Session.query(OptimizerActive.fixed)\
.filter(OptimizerActive.source_se==source_se, OptimizerActive.dest_se==dest_se).all()) < 1:
# Explicit insert to work with schema versions 1 and 2
# See FTS-630
#optimizer_active = OptimizerActive()
#optimizer_active.source_se = source_se
#optimizer_active.dest_se = dest_se
#optimizer_active.ema = 0
#optimizer_active.datetime = datetime.utcnow()
try:
with Session.begin_nested():
Session.add(optimizer_active)
Session.execute(
"INSERT INTO %s (source_se, dest_se, active, ema, datetime) "
"VALUES (:src, :dst, :active, :ema, :now)" % OptimizerActive.__tablename__,
[dict(
src=source_se, dst=dest_se,
active=2, ema=0,
now=datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S")
)]
)
except IntegrityError:
# Someone else inserted the same record after we did the check, so just skip
pass
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment