Day 2 – Dual Execution Environment part 1

A small look into KRL’s dual execution environment and what it means

ruleset a60x6 {
  meta {
    name "Dual execution environment"
    description <<
      Simple app to show where different parts execute and end up
    >>
    author "Mike Grace"
    logging on
  }

  global {
    notSoRandomNumber = 4;
    favoriteNumber = 73
  }

  rule simple_rule {
    select when pageview ".*"
    pre {
      addedNumber = notSoRandomNumber + favoriteNumber;
    }
    {
      notify("addedNumber",addedNumber) with sticky = true;
    }
  }
}

App run on example.com with bookmarklet:

  • Line 11-14 global block: (optional) evaluated server side and results available client side in the web domain. Can do everything a pre block can do plus some and evaluates for EVERY event for this ruleset that is raised to the Kynetx server regardless of rules selecting or not.
  • Line 17 select statement: evaluated server side. Server uses this to decide if the rule gets evaluated or not for the current event that it is responding to. For web events, the select statement executes the select statement’s regular expression and if there is a match, the rule is ‘selected’ and evaluated.
  • Line 18-20 pre block: (optional) evaluated server side and results are available client side in the web domain. Has access to all global block variables.
  • Line 21-23 action block: (optional) evaluated server side and client side. In the web domain, most actions in the action block are evaluated and JavaScript is generated that then gets executed on the client side. In this case, the notify JavaScript function is called and passed the title and body that we have set in the action and also passed optional parameters of sticky being true.

Get the bookmarklet to try it out yourself!

About these ads
This entry was posted in Kynetx and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s