1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
20 from datetime import datetime
25 class DryExecutor(base.BaseExecutor): # pylint: disable=abstract-method
27 Dry task executor: prints task information without causing any side effects.
29 def execute(self, ctx):
30 with ctx.persist_changes:
31 # updating the task manually instead of calling self._task_started(task),
32 # to avoid any side effects raising that event might cause
33 ctx.task.started_at = datetime.utcnow()
34 ctx.task.status = ctx.task.STARTED
36 dry_msg = '<dry> {name} {task.interface_name}.{task.operation_name} {suffix}'
37 logger = ctx.logger.info if ctx.task.function else ctx.logger.debug
39 if hasattr(ctx.task.actor, 'source_node'):
40 name = '{source_node.name}->{target_node.name}'.format(
41 source_node=ctx.task.actor.source_node, target_node=ctx.task.actor.target_node)
43 name = ctx.task.actor.name
46 logger(dry_msg.format(name=name, task=ctx.task, suffix='started...'))
47 logger(dry_msg.format(name=name, task=ctx.task, suffix='successful'))
49 logger(dry_msg.format(name=name, task=ctx.task, suffix='has no implementation'))
51 # updating the task manually instead of calling self._task_succeeded(task),
52 # to avoid any side effects raising that event might cause
53 ctx.task.ended_at = datetime.utcnow()
54 ctx.task.status = ctx.task.SUCCESS