Skip to content

Commit 907b6b6

Browse files
authored
Merge pull request #967 from scitran/unique-job-search
Fix some null checks, and add a unique Queue.search filter
2 parents c4bba02 + cadcbf1 commit 907b6b6

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

api/dao/containerutil.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@
88

99
CONT_TYPES = ['acquisition', 'analysis', 'collection', 'group', 'project', 'session']
1010
SINGULAR_TO_PLURAL = {
11+
'acquisition': 'acquisitions',
12+
'analysis': 'analyses',
13+
'collection': 'collections',
14+
'device': 'devices',
1115
'group': 'groups',
16+
'job': 'jobs',
1217
'project': 'projects',
1318
'session': 'sessions',
14-
'acquisition': 'acquisitions',
15-
'collection': 'collections',
16-
'analysis': 'analyses',
19+
'user': 'users',
1720
}
1821
PLURAL_TO_SINGULAR = {p: s for s, p in SINGULAR_TO_PLURAL.iteritems()}
1922

api/handlers/containerhandler.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ def handle_origin(self, result):
162162
# Join from database if we haven't for this origin before
163163
if j_type != 'unknown' and result['join-origin'][j_type].get(j_id, None) is None:
164164
# Initial join
165-
join_doc = config.db[j_type + 's'].find_one({'_id': j_id_b})
165+
j_types = containerutil.pluralize(j_type)
166+
join_doc = config.db[j_types].find_one({'_id': j_id_b})
166167

167168
# Join in gear name on the job doc if requested
168-
if join_gear_name and j_type == 'job':
169+
if join_doc is not None and join_gear_name and j_type == 'job':
169170

170171
gear_id = join_doc['gear_id']
171172
gear_name = None
@@ -267,6 +268,16 @@ def get_jobs(self, cid):
267268
cont_array = [containerutil.ContainerReference('analysis', cid) for cid in id_array]
268269
results += Queue.search(cont_array, states=states, tags=tags)
269270

271+
# Stateful closure to remove search duplicates
272+
# Eventually, this code should not call Queue.search and should instead do its own work.
273+
def match_ids(x):
274+
should_add = str(x['_id']) in match_ids.unique_job_ids
275+
match_ids.unique_job_ids.add(str(x['_id']))
276+
return should_add
277+
278+
match_ids.unique_job_ids = set()
279+
results = filter(match_ids, results)
280+
270281
# Ensure job uniqueness
271282
seen_jobs = []
272283
seen_gears = []

0 commit comments

Comments
 (0)