Make create task as non-blocking

Currently, the create task api is blocking and waits until the task
is complete to return a 201 but that too with a Pending status.

The patch runs the task executor in an eventlet thread.

Closes-Bug: #1459051

Change-Id: I94f932afb5b754d9bcfa7bbbd1c450bdef7f28ef
This commit is contained in:
Sabari Kumar Murugesan 2015-05-18 14:08:32 -07:00 committed by Sabari
parent ef636718af
commit 1296c6d0eb
2 changed files with 7 additions and 5 deletions

View File

@ -25,6 +25,7 @@ import six
import six.moves.urllib.parse as urlparse
import webob.exc
from glance.api import common
from glance.api import policy
from glance.common import exception
from glance.common import utils
@ -67,7 +68,8 @@ class TasksController(object):
task_input=task['input'])
task_repo.add(new_task)
task_executor = executor_factory.new_task_executor(req.context)
new_task.run(task_executor)
pool = common.get_thread_pool("tasks_eventlet_pool")
pool.spawn_n(new_task.run, task_executor)
except exception.Forbidden as e:
msg = (_LW("Forbidden to create task. Reason: %(reason)s")
% {'reason': utils.exception_to_str(e)})

View File

@ -146,6 +146,10 @@ class TestTasksApi(base.ApiTest):
headers=minimal_task_headers())
self.assertEqual(200, response.status)
# NOTE(sabari): wait for all task executions to finish before checking
# task status.
self._wait_on_task_execution()
# 4. GET /tasks
# Get all tasks (not deleted)
path = "/v2/tasks"
@ -169,10 +173,6 @@ class TestTasksApi(base.ApiTest):
self.assertIsNotNone(task['created_at'])
self.assertIsNotNone(task['updated_at'])
# NOTE(nikhil): wait for all task executions to finish before exiting
# else there is a risk of running into deadlock
self._wait_on_task_execution()
def test_task_schema_api(self):
# 0. GET /schemas/task
# Verify schema for task