Skip to content
Snippets Groups Projects
Commit eec8fa8a authored by Harsha Kethineni's avatar Harsha Kethineni
Browse files

Now checks to for tag with specific gear name

parent aaf21766
No related branches found
No related tags found
No related merge requests found
......@@ -962,14 +962,14 @@ def upgrade_to_26_closure(job):
return True
# This logic WILL NOT WORK in parallel mode
gear_name = gear['gear']['name']
# Checks if the specific gear tag already exists for the job
# Redundant now that cursor only finds jobs without the tags
# for tag in job['tags']:
# if tag == gear_name:
# return True
for tag in job['tags']:
if tag == gear_name:
logging.info("Gear name tag already exists")
return True
# Update doc
result = config.db.jobs.update_one({'_id': job['_id']}, {'$push': {'tags': gear_name }})
if result.modified_count == 1:
......@@ -979,10 +979,25 @@ def upgrade_to_26_closure(job):
def upgrade_to_26_test_closure(job):
for count, tag in enumerate(job['tags'],1):
logging.info(count)
if count > 2:
raise Exception("Job has multiple gear tags")
gear = config.db.gears.find_one({'_id': bson.ObjectId(job['gear_id'])}, {'gear.name': 1})
# This logic WILL NOT WORK in parallel mode
if gear is None:
logging.info('No gear found for job ' + str(job['_id']))
return True
if gear.get('gear', {}).get('name', None) is None:
logging.info('No gear found for job ' + str(job['_id']))
return True
# This logic WILL NOT WORK in parallel mode
gear_name = gear['gear']['name']
gear_name_tag_count = 0
# Checks if the specific gear tag already exists for the job
for tag in job['tags']:
if tag == gear_name:
gear_name_tag_count = gear_name_tag_count + 1
if gear_name_tag_count > 1:
raise Exception("Job has multiple gear name tags")
return True
def upgrade_to_26():
......@@ -991,7 +1006,7 @@ def upgrade_to_26():
Add job tags back to the job document, and use a faster cursor-walking update method
"""
cursor = config.db.jobs.find({'tags[1]': {'$exists': True}})
# cursor = config.db.jobs.find({'tags[1]': {'$exists': True}})
process_cursor(cursor, upgrade_to_26_closure)
cursor = config.db.jobs.find({})
process_cursor(cursor,upgrade_to_26_test_closure)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment