github.com/TIBCOSoftware/flogo-lib@v0.5.9/core/action/action.go (about)

     1  package action
     2  
     3  import (
     4  	"context"
     5  	"fmt"
     6  
     7  	"github.com/TIBCOSoftware/flogo-lib/core/data"
     8  )
     9  
    10  // Action is an action to perform as a result of a trigger
    11  type Action interface {
    12  	// Metadata get the Action's metadata
    13  	Metadata() *Metadata
    14  
    15  	// IOMetadata get the Action's IO metadata
    16  	IOMetadata() *data.IOMetadata
    17  }
    18  
    19  // SyncAction is a synchronous action to perform as a result of a trigger
    20  type SyncAction interface {
    21  	Action
    22  
    23  	// Run this Action
    24  	Run(context context.Context, inputs map[string]*data.Attribute) (map[string]*data.Attribute, error)
    25  }
    26  
    27  // AsyncAction is an asynchronous action to perform as a result of a trigger, the action can asynchronously
    28  // return results as it runs.  It returns immediately, but will continue to run.
    29  type AsyncAction interface {
    30  	Action
    31  
    32  	// Run this Action
    33  	Run(context context.Context, inputs map[string]*data.Attribute, handler ResultHandler) error
    34  }
    35  
    36  // Factory is used to create new instances for an action
    37  type Factory interface {
    38  
    39  	// New create a new Action
    40  	New(config *Config) (Action, error)
    41  }
    42  
    43  // GetMetadata method to ensure we have metadata, remove in future
    44  func GetMetadata(act Action) *Metadata {
    45  	if act.Metadata() == nil {
    46  		_, async := act.(AsyncAction)
    47  		return &Metadata{ID: fmt.Sprintf("%T", act), Async: async}
    48  	} else {
    49  		return act.Metadata()
    50  	}
    51  }
    52  
    53  // Runner runs actions
    54  type Runner interface {
    55  	// Deprecated: Use Execute() instead
    56  	Run(context context.Context, act Action, uri string, options interface{}) (code int, data interface{}, err error)
    57  
    58  	// Deprecated: Use Execute() instead
    59  	RunAction(ctx context.Context, act Action, options map[string]interface{}) (results map[string]*data.Attribute, err error)
    60  
    61  	// Execute the specified Action
    62  	Execute(ctx context.Context, act Action, inputs map[string]*data.Attribute) (results map[string]*data.Attribute, err error)
    63  }
    64  
    65  // ResultHandler used to handle results from the Action
    66  type ResultHandler interface {
    67  
    68  	// HandleResult is invoked when there are results available
    69  	HandleResult(results map[string]*data.Attribute, err error)
    70  
    71  	// Done indicates that the action has completed
    72  	Done()
    73  }