You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ariatosca.apache.org by mx...@apache.org on 2017/06/14 20:48:18 UTC
incubator-ariatosca git commit: task update wrapper [Forced Update!]
Repository: incubator-ariatosca
Updated Branches:
refs/heads/ARIA-278-Remove-core-tasks 8b6d7068d -> d1cfd261d (forced update)
task update wrapper
Project: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/commit/d1cfd261
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/tree/d1cfd261
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/diff/d1cfd261
Branch: refs/heads/ARIA-278-Remove-core-tasks
Commit: d1cfd261d73cbc448615f1ad3402a9b8dbd22221
Parents: 600e54e
Author: max-orlov <ma...@gigaspaces.com>
Authored: Wed Jun 14 19:08:14 2017 +0300
Committer: max-orlov <ma...@gigaspaces.com>
Committed: Wed Jun 14 23:48:12 2017 +0300
----------------------------------------------------------------------
aria/orchestrator/workflows/executor/base.py | 26 ++++++++++-------
aria/orchestrator/workflows/executor/dry.py | 34 +++++++++++------------
2 files changed, 33 insertions(+), 27 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d1cfd261/aria/orchestrator/workflows/executor/base.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/base.py b/aria/orchestrator/workflows/executor/base.py
index 955b536..a727e5c 100644
--- a/aria/orchestrator/workflows/executor/base.py
+++ b/aria/orchestrator/workflows/executor/base.py
@@ -21,6 +21,15 @@ from aria import logger
from aria.orchestrator import events
+def update_ctx(func):
+ def _wrapper(self, ctx, *args, **kwargs):
+ ctx.update_task()
+ func(self, ctx, *args, **kwargs)
+ ctx.update_task()
+
+ return _wrapper
+
+
class BaseExecutor(logger.LoggerMixin):
"""
Base class for executors for running tasks
@@ -28,12 +37,12 @@ class BaseExecutor(logger.LoggerMixin):
def _execute(self, task):
raise NotImplementedError
+ @update_ctx
def execute(self, ctx):
"""
Execute a task
:param task: task to execute
"""
- ctx.update_task()
if ctx.task.function:
self._execute(ctx)
else:
@@ -49,20 +58,17 @@ class BaseExecutor(logger.LoggerMixin):
"""
pass
- @staticmethod
- def _task_started(ctx):
+ @update_ctx
+ def _task_started(self, ctx):
events.start_task_signal.send(ctx)
- ctx.update_task()
- @staticmethod
- def _task_failed(ctx, exception, traceback=None):
+ @update_ctx
+ def _task_failed(self, ctx, exception, traceback=None):
events.on_failure_task_signal.send(ctx, exception=exception, traceback=traceback)
- ctx.update_task()
- @staticmethod
- def _task_succeeded(ctx):
+ @update_ctx
+ def _task_succeeded(self, ctx):
events.on_success_task_signal.send(ctx)
- ctx.update_task()
class StubTaskExecutor(BaseExecutor): # pylint: disable=abstract-method
http://git-wip-us.apache.org/repos/asf/incubator-ariatosca/blob/d1cfd261/aria/orchestrator/workflows/executor/dry.py
----------------------------------------------------------------------
diff --git a/aria/orchestrator/workflows/executor/dry.py b/aria/orchestrator/workflows/executor/dry.py
index 72080b4..c12ba7c 100644
--- a/aria/orchestrator/workflows/executor/dry.py
+++ b/aria/orchestrator/workflows/executor/dry.py
@@ -18,37 +18,37 @@ Dry executor
"""
from datetime import datetime
-from .base import BaseExecutor
+from . import base
-class DryExecutor(BaseExecutor): # pylint: disable=abstract-method
+class DryExecutor(base.BaseExecutor): # pylint: disable=abstract-method
"""
Executor which dry runs tasks - prints task information without causing any side effects
"""
- def execute(self, task):
+ @base.update_ctx
+ def execute(self, ctx):
# updating the task manually instead of calling self._task_started(task),
# to avoid any side effects raising that event might cause
- with task._update():
- task.started_at = datetime.utcnow()
- task.status = task.STARTED
+ ctx.task.started_at = datetime.utcnow()
+ ctx.task.status = ctx.task.STARTED
dry_msg = '<dry> {name} {task.interface_name}.{task.operation_name} {suffix}'
- logger = task.context.logger.info if task.function else task.context.logger.debug
+ logger = ctx.logger.info if ctx.task.function else ctx.logger.debug
- if hasattr(task.actor, 'source_node'):
+ if hasattr(ctx.task.actor, 'source_node'):
name = '{source_node.name}->{target_node.name}'.format(
- source_node=task.actor.source_node, target_node=task.actor.target_node)
+ source_node=ctx.task.actor.source_node, target_node=ctx.task.actor.target_node)
else:
- name = task.actor.name
+ name = ctx.task.actor.name
- if task.function:
- logger(dry_msg.format(name=name, task=task, suffix='started...'))
- logger(dry_msg.format(name=name, task=task, suffix='successful'))
+ if ctx.task.function:
+ logger(dry_msg.format(name=name, task=ctx.task, suffix='started...'))
+ logger(dry_msg.format(name=name, task=ctx.task, suffix='successful'))
else:
- logger(dry_msg.format(name=name, task=task, suffix='has no implementation'))
+ logger(dry_msg.format(name=name, task=ctx.task, suffix='has no implementation'))
# updating the task manually instead of calling self._task_succeeded(task),
# to avoid any side effects raising that event might cause
- with task._update():
- task.ended_at = datetime.utcnow()
- task.status = task.SUCCESS
+ ctx.task.ended_at = datetime.utcnow()
+ ctx.task.status = ctx.task.SUCCESS
+ ctx.update_task()