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.
18 Workflow event logging.
22 from ... import modeling
25 def _get_task_name(task):
26 if isinstance(task.actor, modeling.model_bases.service_instance.RelationshipBase):
27 return '{source_node.name}->{target_node.name}'.format(
28 source_node=task.actor.source_node, target_node=task.actor.target_node)
30 return task.actor.name
33 @events.start_task_signal.connect
34 def _start_task_handler(ctx, **kwargs):
35 # If the task has no function this is an empty task.
38 logger = ctx.logger.info
40 suffix = 'has no implementation'
41 logger = ctx.logger.debug
43 logger('{name} {task.interface_name}.{task.operation_name} {suffix}'.format(
44 name=_get_task_name(ctx.task), task=ctx.task, suffix=suffix))
47 @events.on_success_task_signal.connect
48 def _success_task_handler(ctx, **kwargs):
49 if not ctx.task.function:
51 ctx.logger.info('{name} {task.interface_name}.{task.operation_name} successful'
52 .format(name=_get_task_name(ctx.task), task=ctx.task))
55 @events.on_failure_task_signal.connect
56 def _failure_operation_handler(ctx, traceback, **kwargs):
58 '{name} {task.interface_name}.{task.operation_name} failed'
59 .format(name=_get_task_name(ctx.task), task=ctx.task), extra=dict(traceback=traceback)
63 @events.start_workflow_signal.connect
64 def _start_workflow_handler(context, **kwargs):
65 context.logger.info("Starting '{ctx.workflow_name}' workflow execution".format(ctx=context))
68 @events.on_failure_workflow_signal.connect
69 def _failure_workflow_handler(context, **kwargs):
70 context.logger.info("'{ctx.workflow_name}' workflow execution failed".format(ctx=context))
73 @events.on_success_workflow_signal.connect
74 def _success_workflow_handler(context, **kwargs):
75 context.logger.info("'{ctx.workflow_name}' workflow execution succeeded".format(ctx=context))
78 @events.on_cancelled_workflow_signal.connect
79 def _cancel_workflow_handler(context, **kwargs):
80 context.logger.info("'{ctx.workflow_name}' workflow execution canceled".format(ctx=context))
83 @events.on_cancelling_workflow_signal.connect
84 def _cancelling_workflow_handler(context, **kwargs):
85 context.logger.info("Cancelling '{ctx.workflow_name}' workflow execution".format(ctx=context))