CodeEngine

Kind: global class

new CodeEngine(config, [options])

CodeEngine is an abstraction for a "worker" in a ThingsJS network. A CodeEngine instance connects to the Publish/Subscribe service at the provided URL. Once connected, CodeEngine listens for incoming commands by subscribing to a unique topic. (e.g. "${engine.id}/cmd")

Param Type Description
config Object The configuration object used to initialize the CodeEngine instance
config.pubsub_url string URL of the Publish/Subscribe service
[config.id] string ID to assign to the CodeEngine instance
[options] Object Additional options object for customizing the CodeEngine behaviour

codeEngine.reportStatus(eventName) ⇒ Promise

Publish its status to ENGINE_REGISTRY_NAMESPACE

Kind: instance method of CodeEngine
Returns: Promise - - resolves to true, as per Pubsub.prototype.publish

Param Type Description
eventName String In addition to the default message published, the message object can have an additional "eventName" field to further categorize the message.

codeEngine.reportResource() ⇒ undefined

Publish its resource usage

Kind: instance method of CodeEngine
Returns: undefined - [description]

codeEngine.log()

Augmented console.log function for debugging purposes, the log is published to pubsub so we can see the debug messages on the dashboard as well

Kind: instance method of CodeEngine

codeEngine.run_code()

[restore_code description]

Kind: instance method of CodeEngine

codeEngine.restore_code()

[restore_code description]

Kind: instance method of CodeEngine

codeEngine.migrate_code()

[migrate_code description]

Kind: instance method of CodeEngine

codeEngine.kill()

[kill description]

Kind: instance method of CodeEngine

CodeEngine.Behaviours

CodeEngine Behaviours are a set of functions with the following signature: function(self, kwargs), where self points to the CodeEngine instance, and kwargs is an object carrying additional arguments. The function must return a Promise object that resolves to a JSON-serializable object; the result will be transmitted over the network via HTTP/MQTT. These functions are invoked when a CodeEngine receives a message.

Kind: static property of CodeEngine

Behaviours.run_code(self, kwargs) ⇒ Promise

Run the given code as a ThingsJS process.

Kind: static method of Behaviours
Returns: Promise - - resolves to the JSON object representing a ThingsJS process

Param Type Description
self CodeEngine The CodeEngine instance to run on
kwargs object extra arguments
kwargs.source object the source code to run
[kwargs.code_name] object name to assign to the Code instance

Behaviours.restore_code(self, kwargs) ⇒ Promise

Restore the given JSON snapshot as a ThingsJS process.

Kind: static method of Behaviours
Returns: Promise - - resolves to the JSON object representing a ThingsJS process

Param Type Description
self CodeEngine The CodeEngine instance to run on
kwargs object extra arguments
kwargs.snapshot object the JSON snapshot

Behaviours.migrate_code(self, kwargs) ⇒ Promise

Migrate the specified ThingsJS process to another CodeEngine.

Kind: static method of Behaviours
Returns: Promise - - resolves to the JSON object representing a ThingsJS process

Param Type Description
self CodeEngine The CodeEngine instance to migrate from
kwargs object extra arguments
kwargs.instance_id object the ID of the ThingsJS process
kwargs.engine object the ID of the CodeEngine to migrate to

results matching ""

    No results matching ""