Keeping Channels clean
It is easy and cheap to create a new channel for a pico. See Managing Channels for the details.
The problem
As a side effect of this ease, you may find your Channels tab in the developer UI showing a multitude of channels with the exact same tags which your code has created as you test a new ruleset.
You would expect that only the latest such channel created to be used, but the idiom commonly used to find the channel actually returns the first such channel.
eci = wrangler:channels(tags).head().get("id")
That is generally okay, unless you have changed your code to use a different policy when creating the channel. If you do need the latest channel created, you could use this idiom:
eci = wrangler:channels(tags).reverse().head().get("id")
Keeping only the latest channel created
As an alternative to this, you could modify your ruleset to keep only the latest channel created.
Let’s assume that you create your channel in a rule like this one:
rule initialize {
select when wrangler ruleset_installed where event:attr("rids") >< meta:rid
every {
wrangler:createChannel(
["boilerplates"],
{"allow":[{"domain":"boilerplate","name":"*"}],"deny":[]},
{"allow":[{"rid":meta:rid,"name":"*"}],"deny":[]}
)
}
fired {
raise boilerplate event "factory_reset"
}
}
As you are writing and testing your ruleset, you will find a number of channels with the tags ["boilerplates"]
and these will pile up in the Channels tab. Ideally you would only have one such channel.
This can be easily achieved by adding this rule:
Copyright Picolabs | Licensed under Creative Commons.