Skip to content
Snippets Groups Projects
Commit 975c6fa7 authored by Sybren A. Stüvel's avatar Sybren A. Stüvel
Browse files

Server: separated task.priority into .job_priority and .priority

Now tasks can be sorted by job and task priority, and different tasks can
have different priorities within a job. This will allow for better control
over task ordering than just relying on parent relationships.
parent 9646701c
No related branches found
No related tags found
No related merge requests found
......@@ -221,6 +221,10 @@ tasks_schema = {
'default': 'queued'
},
'priority': {
'type': 'integer',
'default': 0
},
'job_priority': {
'type': 'integer',
'min': 1,
'max': 100,
......
......@@ -91,7 +91,7 @@ def view_job_depsgraph(project, job_id):
tid_to_idx = {task['_id']: tidx
for tidx, task in enumerate(tasks._items)}
for task in tasks._items:
for task in sorted(tasks._items, key=lambda task: task['priority']):
task_id = tid_to_idx[task['_id']]
nodes.append({
'id': task_id,
......
......@@ -27,7 +27,7 @@ REQUEABLE_TASK_STATES = {'completed', 'canceled', 'failed'}
class TaskManager(object):
_log = attrs_extra.log('%s.TaskManager' % __name__)
def api_create_task(self, job, commands, name, parents=None):
def api_create_task(self, job, commands, name, parents=None, priority=50):
"""Creates a task in MongoDB for the given job, executing commands.
Returns the ObjectId of the created task.
......@@ -43,7 +43,8 @@ class TaskManager(object):
'status': 'queued',
'job_type': job['job_type'],
'commands': [cmd.to_dict() for cmd in commands],
'priority': job['priority'],
'job_priority': job['priority'],
'priority': priority,
'project': job['project'],
}
# Insertion of None parents is not supported
......@@ -68,7 +69,12 @@ class TaskManager(object):
payload = {
'where': {
'job': unicode(job_id),
}}
},
'sorted': [
('priority', -1),
('_id', 1),
],
}
if status:
payload['where']['status'] = status
tasks = Task.all(payload, api=api)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment