Scheduler

This is the graph execution engine. To create graphs, see Plastic-IO Graph Editor.

The Plastic-IO Graph Editor uses this engine to test and execute graphs in the browser.

If you're trying to execute graphs in an AWS environment, you might want to check out the Plastic-IO Graph Server.

If you want to implement the scheduler yourself and run graphs in your own way, then you have come to the right place!

To begin the execution of a graph, you must first instantiate your graph in the Scheduler. See the constructor for more information on instantiation. After you instantiate the scheduler, you can call url to directly invoke a node's edge (set function).

Graph

Graphs contain arrays of Nodes. Nodes are executable units of code and can be local to the graph, or reference other nodes or graphs.

Scheduler Execution Digram

              1                         2                            3
+-------------+ +---------------+ +--------------------+
| | | | | |
| Scheduler | | Node Edge | | Edge Connector |
| | | | | |
+-------------+ +---------------+ +--------------------+
| | |
| | |
| +-----------------------------------------+
+-+ | +-+ Graph Loop +-+ |
| +-Scheduler.url()----->+ | | | |
| | | | +------edges[field]------->+ | |
| | | +-+ | | |
| | | | | | |
| | | +-+ | | |
| | | | | | | |
| +<----End--------------+ +<-------------------------+ | |
| | | +-+ | | |
| | | | +-+ |
| | +-----------------------------------------+
| | | |
| | | |
+-+ | |
| | |
+ + +
  1. Scheduler.url() calls a node's edge (set function) based on the node.url.
  2. Node Edge calls edges[field] which invokes n connectors referencing other node edges
  3. Node edge is invoked just like step one, creating a graph loop.

Hierarchy

  • default

Constructors

  • Parameters

    • graph: Graph

      Graph to execute.

    • context: object = {}

      What will appear as the this object for any node set function that executes on your graph.

    • state: object = {}

      Object that will be available to node set functions during graph execution. You can alter this object before or after instantiating the scheduler. See NodeInterface.

    • logger: Logger = nullLogger

      Optional logging function to listen to info and debug messages coming out of the scheduler. Functional messages are emitted via the event emitter.

      Basic Usage

      To start graph execution, instantiate the scheduler and pass your graph to it.

      const scheduler = new Scheduler(myGraphJSON);
      scheduler.url("my-graph-url");

      With Context

      You can also execute the graph and pass context variables to the nodes. In the example below, nodes executing on myGraph will have access to {foo: "bar"} by accessing this.foo at runtime. This allows you to attach properties like server response functions, database connections, client side component references, and many other things use full to the node's set function on runtime.

      const scheduler = new Scheduler(myGraphJSON, {foo: "bar"});
      

      With State Defined

      Nodes now have a mutable object with which they can share long running objects, data caches or other resources that are expensive to instantiate per edge invocation. State is whatever you pass into before you instantiate the scheduler or at run time. The scheduler has no opinion.

      const scheduler = new Scheduler(myGraphJSON, {}, {foo: bar});
      

      Using the Logger

      You can listen to info and debug messages emitted from the scheduler by attaching an object or class that matches the Logger interface. Which happens to be almost exactly like console.

      ```TypeScript const scheduler = new Scheduler(myGraphJSON, {}, {}, console);

    Returns default

Events

afterSet: ((e: NodeSetEvent) => void)

Type declaration

    • (e: NodeSetEvent): void
    • Occurs after a node's set function has completed. Contains the return value of the function. Although this return value is present, using it is considered an anti-pattern and is only included for debugging.

      Parameters

      Returns void

begin: ((e: SchedulerEvent) => void)

Type declaration

beginconnector: ((e: ConnectorEvent) => void)

Type declaration

beginedge: ((e: SchedulerEvent) => void)

Type declaration

end: ((e: SchedulerEvent) => void)

Type declaration

    • (e: SchedulerEvent): void
    • Occurs at the end of the initial graph promise chain. The graph may continue to run as asynchronous functions return.

      Parameters

      Returns void

endconnector: ((e: ConnectorEvent) => void)

Type declaration

    • (e: ConnectorEvent): void
    • Occurs when a connector promise chain has completed after a node's set function has called edges[field] = <value>;.

      Parameters

      Returns void

endedge: ((e: SchedulerEvent) => void)

Type declaration

    • (e: SchedulerEvent): void
    • Occurs after all all edge promises are completed. Note: If your nodes do not return promises.

      Parameters

      Returns void

error: ((e: EdgeError) => void)

Type declaration

    • (e: EdgeError): void
    • Occurs when an error occurred during the invocation of a node.

      Parameters

      Returns void

load: ((e: LoadEvent) => void)

Type declaration

    • (e: LoadEvent): void
    • Occurs when an external resource is loaded. You can invoke setValue in the event argument to override the default loader with your own.

      Parameters

      Returns void

set: ((e: NodeSetEvent) => void)

Type declaration

    • (e: NodeSetEvent): void
    • Occurs just before set is called. You can use setContext to alter the this context object of the node just before the node's set function is invoked.

      Parameters

      Returns void

warning: ((e: Warning) => void)

Type declaration

    • (e: Warning): void
    • Occurs when a warning is logged.

      Parameters

      Returns void

Properties

context: object

The domain specific context object. User defined and used by set methods.

events: {
    [key: string]: Function[];
}

Holds events in the event bus

Type declaration

  • [key: string]: Function[]
graph: Graph

The base graph

graphLoader: Loader<Graph>

Loader for loading graphs

graphPath: string

The parameterized path to linked graph documents

logger: Logger

Logging functions

nodeCache: {
    [key: string]: {};
}

Node specific runtime cache object. Used in set functions for any reason the author sees fit.

Type declaration

  • [key: string]: {}
    nodeLoader: Loader<Node>

    Loader for loading nodes

    nodePath: string

    The parameterized path to linked node documents

    sequence: number

    Edge traversal counter

    state: object

    Mutable state object. This object can be changed and examined later.

    Methods

    • Parameters

      • id: string
      • version: number

      Returns string

    • Parameters

      • id: string
      • version: number

      Returns string

    • Removes an event listener

      Parameters

      • eventName: string
      • listener: (() => void)
          • (): void
          • Returns void

      Returns void

    • Simple Node Edge Invocation

      Invoke a Node's Edge (set function).

      const scheduler = new Scheduler(myGraphJSON);
      scheduler.url("my-graph-url");

      Invoke Edge with Value

      Invoke a Node's Edge (set function), and send a value to the edge.

      const scheduler = new Scheduler(myGraphJSON);
      scheduler.url("my-graph-url", "some value");

      Invoke Edge with Value, and Field

      Invoke a Node's Edge (set function), and send a value to the edge.

      const scheduler = new Scheduler(myGraphJSON);
      scheduler.url("my-graph-url", "some value", "some_field");

      Advanced: Pass Previous Execution Context

      By passing a node instance, you can invoke nodes embedded in inner graphs.

      ```TypeScript const scheduler = new Scheduler(myGraphJSON); scheduler.url("my-graph-url", "some value", "some_field", myInnerNodeInstance);

      Parameters

      • url: string
      • value: any
      • field: string
      • currentNode: Node

      Returns Promise<ExecutionResult>

    Generated using TypeDoc