The document discusses Redis, a key-value store used for caching and persistence. It also discusses the ALEF framework, which uses Redis to manage stateful widgets and background jobs. Widgets in ALEF can asynchronously load and save session data to Redis to prevent one widget's changes from overriding another's. Background jobs in ALEF are handled via Resque and Redis to process logs and update user models asynchronously.
6. ALEF stateful widgets
• Asynchronous initialization & callbacks
• Problem
– The action1 servicing widget1 loads the current
session
– The action2 servicing widget2 loads the current
session
– action1 makes some changes to its copy of the session
– action2 makes some changes to its copy of the session
– action2 completes and saves its changed session data
– action1 completes and saves its changed session data
7. ALEF stateful widgets
• Asynchronous initialization & callbacks
• Problem
– The action1 servicing widget1 loads the current
session
– The action2 servicing widget2 loads the current
session
– action1 makes some changes to its copy of the session
– action2 makes some changes to its copy of the session
– action2 completes and saves its changed session data
– action1 completes and saves its changed session data
• action1 destroys the changes made by action2
8. ALEF stateful widgets
class WidgetController < ApplicationController
include WidgetManager
before_filter :get_user_widget_id, :get_persistent
after_filter :set_persistent
end
def get_persistent
$redis.hgetall(@widget_id).symbolize_keys.each do |key,
value|
if @persistent.include? key
self.instance_variable_set key, Marshal.load(value)
end
end
end
9. ALEF stateful widgets
def set_persistent
to_persist = Hash.new
@persistent.each do |key|
to_persist[key] =
Marshal.dump(self.instance_variable_get(key))
end
$redis.mapped_hmset @widget_id, to_persist
end
10. ALEF background jobs
• We log everything
• We process logs to update user model
• Solution
– resque + redis
– resque-pool
Resque.redis = Redis.new((config.symbolize_keys))
Resque.enqueue(KnowledgeModellerJob,
session[:user_id], @lo.id, @user_answer[:right])
11. ALEF background jobs
class KnowledgeModellerJob
@queue = :knowledge_modellers
def self.perform(user_id, lo_id, params)
student = User.find_by_id user_id
lo = LearningObject.find_by_id lo_id
KnowledgeModeller.new.
question_response(student, lo, params)
end
end