Day 4 – Explicit Events

Goal: Demonstrate raising explicit events in a ruleset and how it effects execution flow of the application.

ruleset a60x23 {
  meta {
    name "raise explicit event"
    description <<       raising explicit events and why they are awesome     >>
    author "Mike Grace"
    logging on
  }

  rule start_the_party {
    select when pageview ".*"
    {
      notify("Getting this party started!",": )") with sticky = true;
    }
    fired {
      raise explicit event time_to_clean_up
    }
  }

  rule clean_up {
    select when explicit time_to_clean_up
    {
      notify("Looks like it's time to clean up this party",": (") with sticky = true;
    }
  }
}
  • For a single execution cycle, rules are executed in the order they are given in the ruleset
  • 11-19 is a rule
  • 12 is a selection expression
  • 13-15 is the action block
  • 14 is an action called notify
  • 16-18 is a postlude block
  • Postlude blocks are executed after an action block is executed
  • Postlude’s can be ‘fired’, ‘not fired’, or ‘always’
  • Action blocks can fire or not fire based on conditions set in the action block
  • 17 raise event syntax -> explicit is the event domain and ‘time_to_clean_up’ is the name of the event

App run on example.com with bookmarklet:

** TIMESTAMPS IN LOGGING LINES REMOVED FOR READABILITY**
//  DEBUG Rules.pm a60x23 [global] Found 2 rules for RID a60x23
//  DEBUG Events.pm a60x23 start_the_party Adding to schedule: a60x23 & start_the_party
//  DEBUG Scheduler.pm a60x23 clean_up Schedule iterator returning start_the_party with current RID count 0 and current rule count 1
//  DEBUG Rules.pm a60x23 clean_up Getting ruleset a60x23 for http://example.com/
//  DEBUG Repository.pm a60x23 clean_up Using cached ruleset for a60x23 (dev) with key ruleset:dev:a60x23 & optimization version 7
//  DEBUG Rules.pm a60x23 clean_up Found 2 rules for RID a60x23
//  INFO Rules.pm a60x23 clean_up Processing rules for site a60x23
//  DEBUG Rules.pm a60x23 clean_up Global vars:
//  DEBUG Rules.pm a60x23 start_the_party Rule start_the_party is active
//  DEBUG Rules.pm a60x23 start_the_party [selected] start_the_party
//  DEBUG Rules.pm a60x23 start_the_party
// -begin rule execution: start_the_party ------------------------
//  DEBUG Rules.pm a60x23 start_the_party Rule not pre optimized...
//  DEBUG Rules.pm a60x23 start_the_party [rules::optimize_pre] foreach vars:
//  INFO Rules.pm a60x23 start_the_party fired
//  DEBUG Actions.pm a60x23 start_the_party blocktype is every
//  DEBUG Actions.pm a60x23 start_the_party actions list contains 1 actions
//  DEBUG Actions.pm a60x23 start_the_party [action] notify_two executing with args ('162349319',callBacks,{'rule_name' :'start_the_party','rid' :'a60x23','txn_id' :'87C4B27A-07C0-11E0-837F-D6FBB418B7D8','sticky' :true},'Getting this party started!',': )')
//  DEBUG Postlude.pm a60x23 start_the_party [post] evaling post expressions with rule fired
//  DEBUG Postlude.pm a60x23 start_the_party [post] evaling consequent
//  INFO Expressions.pm a60x23 start_the_party Variable 'time_to_clean_up' is undefined
//  DEBUG Postlude.pm a60x23 start_the_party Raising explicit event explicit:time_to_clean_up for a60x23
//  DEBUG Postlude.pm a60x23 start_the_party Raising explicit event for RID a60x23, version dev
//  DEBUG Events.pm a60x23 start_the_party Processing events for a60x23
//  DEBUG Rules.pm a60x23 start_the_party Getting ruleset a60x23 for http://example.com/
//  DEBUG Rules.pm a60x23 start_the_party Found 2 rules for RID a60x23
//  DEBUG Events.pm a60x23 clean_up Adding to schedule: a60x23 & clean_up
//  DEBUG Scheduler.pm a60x23 clean_up Schedule iterator returning clean_up with current RID count 0 and current rule count 2
//  DEBUG Rules.pm a60x23 clean_up Rule clean_up is active
//  DEBUG Rules.pm a60x23 clean_up [selected] clean_up
//  DEBUG Rules.pm a60x23 clean_up
// -begin rule execution: clean_up ------------------------
//  DEBUG Rules.pm a60x23 clean_up Rule not pre optimized...
//  DEBUG Rules.pm a60x23 clean_up [rules::optimize_pre] foreach vars:
//  INFO Rules.pm a60x23 clean_up fired
//  DEBUG Actions.pm a60x23 clean_up blocktype is every
//  DEBUG Actions.pm a60x23 clean_up actions list contains 1 actions
//  DEBUG Actions.pm a60x23 clean_up [action] notify_two executing with args ('941281146',callBacks,{'rule_name' :'clean_up','rid' :'a60x23','txn_id' :'87C4B27A-07C0-11E0-837F-D6FBB418B7D8','sticky' :true},'Looks like it\'s time to clean up this party',': (')
//  DEBUG Scheduler.pm a60x23 clean_up Moving to next RID
//  DEBUG Scheduler.pm a60x23 clean_up Resetting schedule
//  DEBUG Rules.pm a60x23 clean_up Finished processing rules for a60x23
//  DEBUG AST.pm a60x23 clean_up Generating JS for a60x23
//  DEBUG AST.pm a60x23 clean_up Generating resource statement for a60x23
//  DEBUG Log.pm a60x23 clean_up [logging] Storing logging data for a60x23
//  DEBUG Log.pm a60x23 clean_up results for start_the_party
//  DEBUG Log.pm a60x23 clean_up results for clean_up
//  DEBUG Log.pm a60x23 clean_up TXN_ID: 87C4B27A-07C0-11E0-837F-D6FBB418B7D8
//  DEBUG Session.pm a60x23 clean_up Cleaning up session
//  INFO Response.pm a60x23 clean_up Event processing finished
//  DEBUG Response.pm a60x23 clean_up __FLUSH__
//  DEBUG Response.pm a60x23 clean_up Called with GET /blue/event/web/pageview/a60x23/12923584313588381970601622015?kvars=%7B%7D&caller=http%3A%2F%2Fexample.com%2F&referer=&title=Example+Web+Page&endpoint=[object%20Object]&a60x23:kynetx_app_version=dev HTTP/1.0
//  DEBUG Response.pm a60x23 clean_up Returning javascript from evaluation
// KNS Tue Dec 14 20:27:11 2010
** GENERATED JAVASCRIPT REMOVED FOR READABILITY**
  • 11 ‘start_the_party’ rule selected because the selection expression matched
  • 13 starting execution of ‘start_the_party’ rule
  • 17-19 action block fires and does its thing
  • 20 starting evaluation of postlude
  • 23 raising explicit event ‘time_to_clean_up’ to same ruleset
  • Yes, explicit events can be raised to other rulesets
  • time_to_clean_up rule runs

Get the bookmarklet to try it out yourself!

Gratuitous day 4 crazy face

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