...
- An editor. There are KRL plugins for many popular editors
- A Github account
- An account on a KRE instance. The easiest way to do this is to use the Kynetx hosted instance of KRE.
Creating a Pico
- Create a Kynetx account and pico
- Authorize the KRL Developer Tools application to access your account and it's associated pico (using OAuth).
Info |
---|
The styling of the account creation and OAuth authroization page is different than the KRL Developer Tools page styling. This is normal in an OAuth situation. |
Once you create your account, the minimum rulesets for running the pico and the KRL Developer Tools will have been installed. After authorizing the KRL Developer Tools you should see the main page:
Writing KRL
Do the following:
- Create a
git
repo for your KRL rulesets and put it on Github. You can create a different repo for each ruleset if you like or create one repo and put multiple rulesets in it. Create file in your ruleset repo called
hello.krl
and put the following in it:Code Block theme Confluence language javascript ruleset hello_world { meta { name "Hello World" description << A first ruleset for the Quickstart >> author "Phil Windley" logging on sharing on provides hello } global { hello = function(obj) { msg = "Hello " + obj msg }; } rule hello_world is active { select when echo hello send_directive("say") with something = "Hello World"; } }
Use one of the methods in Tips for Developers to validate (parse) your ruleset.
Info Installing and using the KRL command line parser can be a real time saver if you're going to be writing several rulesets. Checking in and trying to execute rulesets that don't parse is one of the primary frustrations of beginning KRL developers.
- Check your ruleset into Github.
Registering Your Ruleset
Getting your parsed ruleset into Github is a great first step, but the rules engine doesn't know anything about it. Registering a ruleset gives it a Ruleset ID (RID) in the rules engine so that other users can install and run it.
To register the ruleset, we will use the KRL Developer Tools at Pico Labs.
Info |
---|
For information about creating an account and using the KRL Developer Tools, see the Developer Tools Tutorial. |
When you click on the "Register Rulesets" menu item in the KRl KRL Developer tools, you will see this page that shows all your registered rulesets and a menu item to register a new ruleset:
When you click on "Register a new ruleset" you'll see this page:
...
Clicking on the ruleset you just installed will show you information about it (and give you a button for uninstalling it if you choose):
Flushing the Ruleset
When the rules engine reads a ruleset from the URL where it is located, the rules engine parses it, optimizes it, and caches the result. The next time the ruleset engine needs the ruleset it uses the cached copy, saving time in getting, parsing, and optimizing.
...
Info |
---|
One frustrating part of using Github for a rule repository is that changes that are checked in can sometimes take several minutes to be seen in the raw URL. Even if you have flushed the ruleset from the rules engine, if Github returns the old content, you'll see the old behavior. You can't really do anything but wait this out. |
Testing the Ruleset
Debugging the Ruleset