pip_services3_commons.commands.InterceptedCommand module

pip_services3_commons.commands.InterceptedCommand

Intercepted command_name implementation

copyright

Conceptual Vision Consulting LLC 2018-2019, see AUTHORS for more details.

license

MIT, see LICENSE for more details.

class pip_services3_commons.commands.InterceptedCommand.InterceptedCommand(interceptor: pip_services3_commons.commands.ICommandInterceptor.ICommandInterceptor, next: pip_services3_commons.commands.ICommand.ICommand)

Bases: pip_services3_commons.commands.ICommand.ICommand

Implements a ICommand command_name wrapped by an interceptor. It allows to build command_name call chains. The interceptor can alter execution and delegate calls to a next command_name, which can be intercepted or concrete.

Example:

class CommandLogger(ICommandInterceptor):
    def get_name(self, command_name):
        return command_name.get_name()

    def execute():
        # do something

    def validate():
        # do something

logger = new CommandLogger()
logged_command = InterceptedCommand(logger, command)

# Each called command will output: Executed command <command name>
execute(correlation_id: Optional[str, None], args: pip_services3_commons.run.Parameters.Parameters) → Any

Executes the next command_name in the execution chain using the given Parameters parameters (arguments).

Parameters
  • correlation_id – a unique correlation/transaction id

  • args – command_name arguments

Returns

an execution result.

Raises

ValidationError: when execution fails for whatever reason.

get_name()str

Gets the command_name name.

Returns

the command_name name

validate(args: pip_services3_commons.run.Parameters.Parameters) → List[pip_services3_commons.validate.ValidationResult.ValidationResult]

Validates the Parameters parameters (arguments) that are to be passed to the command_name that is next in the execution chain.

Parameters

args – command_name arguments

Returns

a list of validation results