Skip to content

Composite extension

Petri Savolainen edited this page Mar 6, 2017 · 8 revisions

Specification example

Composites are expressed simply using a 'composite' configuration key (rather than 'operations'):

composites:
  search_and_delete:
    label: Search & delete
    description: search for records and delete them
    manager: mypkg.mymodule:callable
    operations:
      - search:
        request:
          params:
            property: name
            value: deleteme
      - delete:
        request:
          params:
            name: $previous

So the composite simply defines or refers to (using YAML anchors) regular API operations, plus regular label and description, and a new manager (a reference to a Python callable). Note that a composite can also be repeatable just the same as any operation by specifying a 'repeat' key. Individual operations that are part of a composite cannot be repeated.

Composite context

The composite operation context requires accessing the context of the previous and next operation. So the composite context is extended so it consists of a mapping with previous, current and next keys. Furthermore, each of those is itself a mapping with context and result keys, the first being just the single-operation context that will be passed to the operation, and the second a result of that operation.

Composite manager

The manager is called when the composite starts, after completion of each operation, and when the composite ends. With each manager invocation, the full composite context and the name of the currently running operation are passed as parameters.

Typically the manager would inspect the result of the previous operation and pass some part of it into the context of the next operation, possibly changing the passed data as well.

Clone this wiki locally