[Kimchi-devel] [PATCH] [Wok 2/3] Issue #158: Update model/tasks.py with AsyncTasks in memory.
Daniel Henrique Barboza
dhbarboza82 at gmail.com
Mon Aug 29 19:42:46 UTC 2016
On 08/29/2016 04:18 PM, pvital at linux.vnet.ibm.com wrote:
> From: Paulo Vital <pvital at linux.vnet.ibm.com>
>
> TasksModel and TaskModel classes need to be updated after move
> AsyncTasks to memory.
>
> Signed-off-by: Paulo Vital <pvital at linux.vnet.ibm.com>
> ---
> src/wok/i18n.py | 1 +
> src/wok/model/tasks.py | 22 +++++++++++++---------
> 2 files changed, 14 insertions(+), 9 deletions(-)
>
> diff --git a/src/wok/i18n.py b/src/wok/i18n.py
> index 1a0446b..ade2ae9 100644
> --- a/src/wok/i18n.py
> +++ b/src/wok/i18n.py
> @@ -33,6 +33,7 @@ messages = {
> "WOKAPI0008E": _("Parameters does not match requirement in schema: %(err)s"),
> "WOKAPI0009E": _("You don't have permission to perform this operation."),
>
> + "WOKASYNC0001E": _("Unable to find task id: %(id)s"),
> "WOKASYNC0003E": _("Timeout of %(seconds)s seconds expired while running task '%(task)s."),
>
> "WOKAUTH0001E": _("Authentication failed for user '%(username)s'. [Error code: %(code)s]"),
> diff --git a/src/wok/model/tasks.py b/src/wok/model/tasks.py
> index 9c32554..d1111a6 100644
> --- a/src/wok/model/tasks.py
> +++ b/src/wok/model/tasks.py
> @@ -22,7 +22,8 @@
>
> import time
>
> -from wok.exception import TimeoutExpired
> +from wok.exception import NotFoundError, TimeoutExpired
> +from wok.asynctask import tasks_queue
Wrong import order
>
>
> class TasksModel(object):
> @@ -30,8 +31,7 @@ class TasksModel(object):
> self.objstore = kargs['objstore']
>
> def get_list(self):
> - with self.objstore as session:
> - return session.get_list('task')
> + return tasks_queue.keys()
>
>
> class TaskModel(object):
> @@ -39,8 +39,13 @@ class TaskModel(object):
> self.objstore = kargs['objstore']
>
> def lookup(self, id):
> - with self.objstore as session:
> - return session.get('task', str(id))
> + if id not in tasks_queue.keys():
> + raise NotFoundError('WOKASYNC0001E', {'id': id})
> + task = tasks_queue[id]
> + return {'id': id,
> + 'status': task.status,
> + 'message': task.message,
> + 'target_uri': task.target_uri}
>
> def wait(self, id, timeout=10):
> """Wait for a task until it stops running (successfully or due to
> @@ -54,13 +59,12 @@ class TaskModel(object):
> "TimeoutExpired" is raised.
> """
> for i in range(0, timeout):
> - with self.objstore as session:
> - task = session.get('task', str(id))
> + task = tasks_queue[id]
>
> - if task['status'] != 'running':
> + if task.status != 'running':
> return
>
> time.sleep(1)
>
> raise TimeoutExpired('WOKASYNC0003E', {'seconds': timeout,
> - 'task': task['target_uri']})
> + 'task': task.target_uri})
More information about the Kimchi-devel
mailing list