Functions
skyQueryA 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, deadlocks are possible due to its synchronous nature (e.g. do not let two picos query each other simultaneously). See Accessing a Function Shared by Another Pico for more information. ParametersParameter | Datatype | Description |
---|
eci | String | The ECI to send the query to | mod | String | The ruleset to send the query to | func | String | The name of the function to query | params | Map | The parameters to be passed to the function on the target pico. Given as an object with parameter name mapped to argument value. | _host | String | The host of the pico engine being queried. Note this must include protocol (http:// or https://) being used and port number if not 80. For example "http://localhost:8080", which also is the default. | _path | String | The sub path of the url which does not include mod or func. For example "/sky/cloud/", which also is the default. | _root_url | String | The entire URL except eci, mod , func. For example, dependent on _host and _path is "http://localhost:8080/sky/cloud/", which also is the default. Defaults to meta:host (the pico engine itself). |
ReturnsSuccess: the result of the function queried for. Failure: a map of error information which contains:
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
| {
"error":"general error message",
"skyQueryError":"The value of the 'error key', if it exists, of the function results"
"skyQueryErrorMsg":"The value of the 'error_str', if it exists, of the function results"
"skyQueryReturnValue":"The function call results"
} |
Code Block |
---|
language | js |
---|
theme | Confluence |
---|
title | Example |
---|
| 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(); // Check that it did not return an error
fired {
// process using answer
} |
|