Skip to content
Snippets Groups Projects
Commit 0909e431 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

SW-657: simple priority sorting for new python3 changes, simplified...

SW-657: simple priority sorting for new python3 changes, simplified canProduceNextJob method to simple lookup of a single scheduled job
parent 3a5a84bd
No related branches found
No related tags found
No related merge requests found
......@@ -634,6 +634,12 @@ class IngestJobManager:
with self.__lock:
def getNextJobByStatus(status, min_age=None, exclude_job_group_ids=[]):
# TODO: replace jad_compare_func with fully implemented jad_sort_value_func
# needed for python2 -> python3 sorting changes
# Right now, we just sort on prio
def jad_sort_value_func(jad):
return jad['job'].get('priority', DEFAULT_JOB_PRIORITY)
def jad_compare_func(jad_a, jad_b):
# sort on priority first
if jad_a['job'].get('priority', DEFAULT_JOB_PRIORITY) != jad_b['job'].get('priority', DEFAULT_JOB_PRIORITY):
......@@ -676,7 +682,7 @@ class IngestJobManager:
# filter out jad's from exclude_job_group_ids
job_admin_dicts = [jad for jad in job_admin_dicts if 'job_group_id' not in jad['job'] or jad['job']['job_group_id'] not in exclude_job_group_ids]
job_admin_dicts = sorted(job_admin_dicts, key=cmp_to_key(jad_compare_func))
job_admin_dicts = sorted(job_admin_dicts, key=jad_sort_value_func, reverse=True)
if job_admin_dicts:
logger.info('%s jobs with status %s waiting', len(job_admin_dicts), jobState2String(status))
return job_admin_dicts[0]
......@@ -757,12 +763,8 @@ class IngestJobManager:
def canProduceNextJob(self):
# test if the managed_job_queue is empty enough, and if our administration agrees
try:
with self.__jobs_for_transfer_queue_peeker:
num_scheduled = self.__jobs_for_transfer_queue_peeker.nr_of_messages_in_queue(0.01)
if num_scheduled <= 1:
scheduled_jads = self.getJobAdminDicts(status=JobScheduled)
return len(scheduled_jads) <= 1
return False
scheduled_jads = self.getJobAdminDicts(status=JobScheduled)
return len(scheduled_jads) < 1
except Exception as e:
logger.exception('canProduceNextJob: %s', e)
if 'No active session' in str(e):
......
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