Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for dm identity map and action timeouts.
- Loading branch information
Showing
3 changed files
with
49 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
module Merb | ||
module ResourceController | ||
module DM | ||
|
||
# to be extended into controller | ||
module IdentityMapSupport | ||
|
||
def enable_identity_map(options = {}) | ||
@action_timeout = options[:action_timeout] || 0 | ||
# maybe also useful for retries | ||
class_inheritable_accessor :action_timeout | ||
include InstanceMethods | ||
end | ||
|
||
module InstanceMethods | ||
|
||
# taken from: | ||
# http://datamapper.org/doku.php?id=docs:identity_map | ||
def _call_action(*) | ||
repository do |r| # enable identity_map | ||
Merb.logger.info "Inside #{r.name} repository block" | ||
if self.class.respond_to?(:action_timeout) | ||
return super if self.class.action_timeout < 1 | ||
# more information on system_timer: | ||
# http://adam.blog.heroku.com/past/2008/6/17/battling_wedged_mongrels_with_a/ | ||
require 'system_timer' # laziness | ||
SystemTimer.timeout(self.class.action_timeout) do | ||
super | ||
end | ||
else | ||
super | ||
end | ||
end | ||
end | ||
|
||
end | ||
|
||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
class Application < Merb::Controller | ||
extend Merb::ResourceController::Mixin::ClassMethods | ||
extend Merb::ResourceController::DM::IdentityMapSupport | ||
enable_identity_map :action_timeout => 1 | ||
end |