Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 21 Next »

This page is unfinished. For a taste, see the engine module documentation.

Wrangler is an operating system written in KRL for picos. Wrangler provides developers a way to programmatically and easily manage picos.

To use Wrangler as a module, add "use module io.picolabs.wrangler alias wrangler" in your meta block.

Functions

For all functions, enter the parameters in the order listed.

Italicized parameters are optional.

children

Returns an array of the children of the pico. Has optional parameter "name" which returns just the attributes for the child with the specific name if it exists, otherwise it returns attributes on every child if not provided.

Parameters
ParameterDatatypeDescription
nameStringName of the pico to search for
Returns

An array containing a map for each returned pico. Each map contains:

parent_eci: The ECI from the pico to the respective child. Should be used for parent-child interaction.

name: The child pico's name

id: The id of the child pico

eci: The main wrangler ECI for the child pico

children = wrangler:children()
/*
[
  {
    "parent_eci": "CyrmdG4PkiVYRUo2K69k2E",
    "name": "Section CS462-1 Pico",
    "id": "cjh6pbzun005zvde06bwy2pci",
    "eci": "JfcEBxEK5WDKA69Bvach4Y"
  },
  {
    "parent_eci": "Tg5ULPBYByJjsEoKpfsbQ2",
    "name": "Section CS462-2 Pico",
    "id": "cjh6pc28r0067vde04qd23t6o",
    "eci": "56S414r4Uq4kGx6Xi1qmSs"
  }
]
*/

myself

Returns a map giving basic meta information about the pico. This information includes the pico's ID, ECI, and name.

Returns

A map giving basic information about a pico with the following contents:

id: The ID of the pico

eci: The main wrangler ECI of the pico

name: The name of the pico


myself_result = wrangler:myself()
/*
{
  "id": "cjhtji2op009hpkrq35bcpodh",
  "eci": "4bUS9W4HY5S1YfsAM9Ygw5",
  "name": "Front Porch"
}
*/


skyQuery

A user friendly way to make an HTTP request between picos. It provides cleanup and returns the error if the returned HTTP status was not 200.

It is mainly used to programmatically call functions inside of other picos from inside a rule. However, do not have a pico query itself, or have two picos query each other simultaneously. See Accessing a Function Shared by Another Pico for more information.

Parameters
ParameterDatatypeDescription
eciStringThe ECI to send the query to
modStringThe ruleset to send the query to
funcStringThe name of the function to query
paramsMapThe parameters to be passed to the function on the target pico. Given as an object with parameter name mapped to argument value.
_hostStringThe target pico's host
_pathStringAn optional different path for the beginning of the underlying URL
_root_urlStringThe root URL for the request. Defaults to meta:host (the pico engine itself).
Returns

The result of the function queried for.

pre {
	eci = event:attr("eci")
	wellknown = wrangler:skyQuery( eci , "io.picolabs.subscription", "wellKnown_Rx")
}
if wellknown{"error"}.isnull() then
	noop()
always {
	ent:savedWellknown := wellknown;
}
/*
Query the the function wellKnown_Rx() in the ruleset "io.picolabs.subscription" through the pico ECI given in the event attribute "eci".
*/

pre {
  eci = eci_to_other_pico;
  args = {"arg1": val1, "arg2": val2};
  answer = Wrangler:skyQuery(eci,"my.ruleset.id","myFunction",args);
}
if answer{"error"}.isnull() then noop();
fired {
  // process using answer
}


Defactions


Events/Rules

When a rule raises an event in the postlude, it will also pass along all the attributes it received (including any attributes not used in that event) in addition to any new information that may be relevant to other rules.

Raised Events are events that the rule will directly raise.

Sent Events are events that the rule will send elsewhere.

Italicized attributes are optional.

Ruleset Events

installRulesets

Domain: wrangler
Type: install_rulesets_requested

Installs the given rulesets in the pico that receives this event.

Attributes
AttributeDatatypeAdditional Description
rids

Array

String

The RIDs of the rulesets to be installed on this pico. Each RID can be an entry in an array, or in a semicolon denoted list (e.g. "io.picolabs.ruleset_one;io.picolabs.ruleset_two").
Directives Returned
send_directive("rulesets installed", { "rids": /* An array of rids that were installed*/ });
Raised Events
DomainTypeAttributes Added
wranglerruleset_added
"rids": /* An array of rids that were installed*/

Pico Events

createChild

Domain: wrangler
Type: child_creation or new_child_request

Creates a new child for this pico with optional arguments for the child's name, and rulesets to install on it upon creation.

AttributeDatatypeDescription
nameStringThe name for the new child pico. Will generate a random name if not provided.
rids

String Array

String

The RIDs of the rulesets to be installed on the new child pico. Each RID can be an entry in an array, or in a semicolon denoted list (e.g. "io.picolabs.ruleset_one;io.picolabs.ruleset_two").

Raised events
Response Events


  • No labels