module Octo::OctoHooks::ClassMethods

Add all the post-hook-call methods here. Also, extend the module

from here.

Public Instance Methods

add_session(opts) click to toggle source

Adds user session for page_view and product_page_view to redis. It self expires in n seconds from last hit

# File lib/octocore-cassandra/callbacks.rb, line 75
def add_session(opts)
  if Octo.is_not_flagged?(Octo::Funnel)
    if opts.has_key?(:type)
      createRedisShadowKey(opts[:enterprise].id.to_s + '_' + opts[:user].id.to_s,
                           opts[:type].to_s,
                           Octo.get_config(:session_length))
    end
  end
end
createRedisShadowKey(keyname, value, duration) click to toggle source

Method was created because when a redis key

expires you can just catch the key name,
and not its value. So what we do is
create a shadow key for the given key name
and make it expire in the given amt of
time (seconds).

This helps us in catching the event

when the (shadow) key expires, after which we
read the value of the main key and later
delete the main key

You can change it from rpush to lpush, or set

whichever you want to use.
# File lib/octocore-cassandra/callbacks.rb, line 97
def createRedisShadowKey(keyname, value, duration)
  Cequel::Record.redis.setex("shadow:" + keyname,duration,"")
  Cequel::Record.redis.rpush(keyname, value)
end
update_counters(opts) click to toggle source

Updates the counters of various types depending

on the event.

@param [Hash] opts The options hash

# File lib/octocore-cassandra/callbacks.rb, line 54
def update_counters(opts)
  if opts.has_key?(:product)
    Octo::ProductHit.increment_for(opts[:product])
  end
  if opts.has_key?(:categories)
    opts[:categories].each do |cat|
      Octo::CategoryHit.increment_for(cat)
    end
  end
  if opts.has_key?(:tags)
    opts[:tags].each do |tag|
      Octo::TagHit.increment_for(tag)
    end
  end
  if opts.has_key?(:event)
    Octo::ApiHit.increment_for(opts[:event])
  end
end