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 5 Next »

Wrangler raises an event, ruleset_added on successful installation of a rid with the installed rid as an attribute rids. This event is meant for developers to catch in rulesets for initializing state, which could include channel creation, subscription request, and child pico creation. Initialization rules should be listed first in rulesets, because rulesets execute in order this will cause the initialization rule to run first.  This model of initialization has replaced prototypes. 

Create Channel On Installation Example

This example is taken from io.picolabs.subscription ruleset. 

initialization example
rule create_wellKnown_Rx{
  select when wrangler ruleset_added where rids >< meta:rid
  pre{ channel = wellKnown_Rx() }
  if(channel.isnull() || channel{"type"} != "Tx_Rx") then
    engine:newChannel(meta:picoId, "wellKnown_Rx", "Tx_Rx")
  fired{
    raise Tx_Rx event "wellKnown_Rx_created" attributes event:attrs;
  }
  else{
    raise Tx_Rx event "wellKnown_Rx_not_created" attributes event:attrs; //exists
  }
}

Create well known Rx rule selects on ruleset_added event where rids matches its own ruleset rid. Checks for a well known channel, and creates it if one does not exist. Then raises an event detailing the creation. This rule guarantees a well known channel exist, which is a dependency of subscriptions.

Warning: Deprecated, Untested Example of prototypes


Picos can be created using prototypes that describe what state a pico should be created in.

Picos can have certain rulesets, channels, and subscriptions that control what a pico is, Prototypes directly reflect this.

here is an example of a Prototype.

{
      "meta" : {
                "discription": "picoLabExample prototype"
                },
                
      "rids": [  
                "b16x29.prod", 
                "b507901x6.prod" 
                 
              ],
      "channels" : [{
                      "name"       : "_wellKnown_app_eci",
                      "type"       : "WellKnown",
                      "attributes" : "none",
                      "policy"     : "not implemented"
                    }
                    ], 
      "prototypes" : [],
      "subscriptions_request": [],
      "Prototype_events" : [], 
      "PDS" : {
                "profile" : {
                            "name":"base",
                            "description":"discription of the general pds created",
                            "location":"40.252683,-111.657486",
                            "model":"unknown",
                            "model_description":"no model at this time",
                            "photo":""
                            },
                "general" : {"test":{"subtest":"just a test"}},
                "settings": {"b507901x1.prod":{
                                              "name":"wrangler",
                                              "keyed_rid" :"b507901x1.prod",
                                              "schema":["im","a","schema"],
                                              "data_key":"first_key",
                                              "value":"first_value"
                                              }
                            }
              }
  }

Prototypes are json objects which have desired things to be added at creation.

Before a child_creation event you can add a prototype by url, and have wrangler use this prototype to create the pico accordingly.


    rule createPicoWithPrototypeURL {
      select when owner need_new_pico
        pre {}
        /*action*/{ noop();}
        always {
          raise wrangler event "add_prototype" 
            with prototype_name = 'NewPrototypeExample'
             and url = 'https://raw.githubusercontent.com/burdettadam/Practice-with-KRL/master/manifold/NewPrototypeExample.json';// ----------------------------------------------needs url to prototype. ---------------------------------------------------------
          raise wrangler event "child_creation" 
            with name = 'PrototypeExample'
             and prototype = 'NewPrototypeExample'; // must be the same name you used above
        log("SUCCESS OFTEN COMES AFTER DISAPPOINTMENTS.");// just a friendly log.
	    }
    }


While the url is hard coded in this example you could easily use a attribute to dynamically pass in any prototype you would like. 



  • No labels