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
Branches
Tags
No related merge requests found
...@@ -221,6 +221,10 @@ tasks_schema = { ...@@ -221,6 +221,10 @@ tasks_schema = {
'default': 'queued' 'default': 'queued'
}, },
'priority': { 'priority': {
'type': 'integer',
'default': 0
},
'job_priority': {
'type': 'integer', 'type': 'integer',
'min': 1, 'min': 1,
'max': 100, 'max': 100,
......
...@@ -91,7 +91,7 @@ def view_job_depsgraph(project, job_id): ...@@ -91,7 +91,7 @@ def view_job_depsgraph(project, job_id):
tid_to_idx = {task['_id']: tidx tid_to_idx = {task['_id']: tidx
for tidx, task in enumerate(tasks._items)} 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']] task_id = tid_to_idx[task['_id']]
nodes.append({ nodes.append({
'id': task_id, 'id': task_id,
......
...@@ -27,7 +27,7 @@ REQUEABLE_TASK_STATES = {'completed', 'canceled', 'failed'} ...@@ -27,7 +27,7 @@ REQUEABLE_TASK_STATES = {'completed', 'canceled', 'failed'}
class TaskManager(object): class TaskManager(object):
_log = attrs_extra.log('%s.TaskManager' % __name__) _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. """Creates a task in MongoDB for the given job, executing commands.
Returns the ObjectId of the created task. Returns the ObjectId of the created task.
...@@ -43,7 +43,8 @@ class TaskManager(object): ...@@ -43,7 +43,8 @@ class TaskManager(object):
'status': 'queued', 'status': 'queued',
'job_type': job['job_type'], 'job_type': job['job_type'],
'commands': [cmd.to_dict() for cmd in commands], 'commands': [cmd.to_dict() for cmd in commands],
'priority': job['priority'], 'job_priority': job['priority'],
'priority': priority,
'project': job['project'], 'project': job['project'],
} }
# Insertion of None parents is not supported # Insertion of None parents is not supported
...@@ -68,7 +69,12 @@ class TaskManager(object): ...@@ -68,7 +69,12 @@ class TaskManager(object):
payload = { payload = {
'where': { 'where': {
'job': unicode(job_id), 'job': unicode(job_id),
}} },
'sorted': [
('priority', -1),
('_id', 1),
],
}
if status: if status:
payload['where']['status'] = status payload['where']['status'] = status
tasks = Task.all(payload, api=api) 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