Permalink
Browse files

yagni

  • Loading branch information...
1 parent e771261 commit fb00ab64bda20ea1dae09ee8fa4e4e18e4dc9c3c @methodmissing committed Feb 2, 2009
@@ -1,18 +1,12 @@
production:
orm: 'active_record'
- storage: 'cache'
- buffer_threshold: 60
- warmup_threshold: 3600
+ storage: 'memory'
scope:
development:
orm: 'active_record'
storage: 'memory'
- buffer_threshold: 20
- warmup_threshold: 1800
scope:
test:
orm: 'active_record'
- storage: 'memory'
- buffer_threshold: 0
- warmup_threshold: 0
+ storage: 'memory'
scope:
@@ -17,7 +17,6 @@ def call(env)
Scrooge::Base.profile.framework.resource( env )
result
ensure
- Scrooge::Base.profile.storage << Thread.scrooge_resource
Thread.reset_scrooge_resource!
end
end
View
@@ -43,33 +43,7 @@ def initialize( options = {} )
def options=( options )
@options = options
configure!
- end
-
- # Should we do a warmup ?
- #
- def warmup?
- warmup_threshold != 0
- end
- alias :warmed_up? :warmup?
-
- # Should the tracking phase be buffered ?
- #
- def buffer?
- buffer_threshold != 0
- end
- alias :buffered? :buffer?
-
- # Buffer threshold in seconds, if any.
- #
- def buffer_threshold
- @buffer_threshold.to_i
- end
-
- # Warmup threshold, in seconds, if any.
- #
- def warmup_threshold
- @warmup_threshold.to_i
- end
+ end
# Delegates to the underlying ORM framework.
#
@@ -149,8 +123,6 @@ def scope?
def configure! #:nodoc:
@orm = @options['orm'] || :active_record
@storage = @options['storage'] || :memory
- @buffer_threshold = @options['buffer_threshold'] || 0
- @warmup_threshold = @options['warmup_threshold'] || 0
@scope = @options['scope'].to_s || nil
memoize_backends!
end
@@ -1,11 +1,8 @@
module Scrooge
module Storage
-
- autoload :Lookup, 'scrooge/storage/lookup'
+
autoload :Buffer, 'scrooge/storage/buffer'
- autoload :FileSystem, 'scrooge/storage/file_system'
autoload :Memory, 'scrooge/storage/memory'
- autoload :Cache, 'scrooge/storage/cache'
class Base < Scrooge::Base
class NotImplemented < StandardError
@@ -26,13 +23,7 @@ def instantiate( storage_signature )
end
end
-
- # Enable a storage buffer by default.
- #
- def initialize
- extend Buffer
- end
-
+
# Retrieve a given tracker from storage.
#
def read( tracker )
@@ -51,22 +42,6 @@ def expand_key( key )
"#{NAMESPACE}/#{key}"
end
- # Commit a given tracker to the storage backend and register it's signature at
- # central lookup.
- #
- def <<( tracker )
- register_with_lookup!( tracker )
- write( tracker )
- end
-
- private
-
- def register_with_lookup!( tracker ) #:nodoc:
- lookup = unbuffered_read( Scrooge::Storage::Lookup::KEY ) || Scrooge::Storage::Lookup.new
- lookup << tracker
- unbuffered_write( lookup )
- end
-
end
end
end
@@ -1,109 +0,0 @@
-module Scrooge
- module Storage
- module Buffer
-
- GUARD = Mutex.new
-
- attr_accessor :storage_buffer,
- :buffer_flushed_at
-
- def self.extended( klass )
- klass.instance_eval do
- alias :unbuffered_write :write
- alias :unbuffered_read :read
- end
- end
-
- # Initialize with an empty storage buffer.
- #
- def storage_buffer
- @storage_buffer ||= {}
- end
-
- # Calculate when the buffer was last flushed.
- #
- def buffer_flushed_at
- GUARD.synchronize do
- @buffer_flushed_at ||= Time.now.to_i
- end
- end
-
- # Buffered read.
- #
- def read( tracker )
- GUARD.synchronize do
- with_read_buffer( tracker ) do
- super( tracker )
- end
- end
- end
-
- # Buffered write.
- #
- def write( tracker, buffered = true )
- GUARD.synchronize do
- if buffered
- with_write_buffer( tracker ) do
- super( tracker, buffered )
- end
- else
- super( tracker, buffered )
- end
- end
- end
-
- # Determine if we should buffer at all.
- #
- def buffer?
- profile.buffer?
- end
-
- # Determine if the buffer should be flushed.
- #
- def flush_buffer?
- if buffer?
- ( buffer_flushed_at + profile.buffer_threshold ) < Time.now.to_i
- else
- false
- end
- end
-
- # Buffers a given tracker instance.
- #
- def buffer( tracker )
- storage_buffer[tracker.signature] = tracker
- end
-
- # Flush the current buffer.
- def flush!
- GUARD.synchronize do
- while( !storage_buffer.empty? ) do
- write( storage_buffer.shift.last, false )
- end
- buffer_flushed_at = Time.now.to_i
- end
- end
-
- private
-
- def with_read_buffer( tracker ) #:nodoc:
- if flush_buffer?
- flush!
- storage_buffer[tracker.signature]
- else
- yield
- end
- end
-
- def with_write_buffer( tracker ) #:nodoc:
- if flush_buffer?
- flush!
- buffer( tracker )
- else
- yield
- end
- end
-
- end
- end
-end
@@ -1,23 +0,0 @@
-module Scrooge
- module Storage
- class Cache < Base
-
- def initialize
- extend Buffer
- end
-
- # Read from the host framework's cache store.
- #
- def read( tracker )
- profile.framework.read_cache( expand_key( tracker ) )
- end
-
- # Write to the host framework's cache store.
- #
- def write( tracker, buffered = true )
- profile.framework.write_cache( expand_key( tracker ), tracker )
- end
-
- end
- end
-end
@@ -1,56 +0,0 @@
-module Scrooge
- module Storage
- class FileSystem < Base
-
- def initialize
- extend Buffer
- end
-
- # Read a given tracker instance from the filesystem.
- #
- def read( tracker )
- GUARD.synchronize do
- begin
- File.open( tracker_file( tracker ), 'rb') {|t| Marshal.load(t) }
- rescue => exception
- profile.framework.logger.error "Scrooge: Could not read storage entry #{tracker.key} (#{exception.to_s})"
- end
- end
- end
-
- # Writes a given tracker instance to the filesystem.
- #
- def write( tracker, buffered = true )
- GUARD.synchronize do
- begin
- ensure_tracker_path( tracker ) do
- File.open( tracker_file( tracker ), 'w') {|t| Marshal.dump( tracker, t ) }
- end
- rescue => exception
- profile.framework.logger.error "Scrooge: Could not write storage entry #{tracker.key} (#{exception.to_s})"
- end
- end
- end
-
- # Returns the file path to a given tracker instance
- #
- def tracker_file( tracker )
- File.join( tracker_path( tracker ), 'scrooge' )
- end
-
- # Returns the directory path to a given tracker instance
- #
- def tracker_path( tracker )
- File.join( profile.framework.tmp, tracker.signature )
- end
-
- private
-
- def ensure_tracker_path( tracker ) #:nodoc:
- FileUtils.makedirs( tracker_path( tracker ) ) unless File.exist?( tracker_path( tracker ) )
- yield if block_given?
- end
-
- end
- end
-end
@@ -1,31 +0,0 @@
-module Scrooge
- module Storage
- class Lookup
-
- # Centralized Resource Tracker lookup.
- # Partial API compat with Tracker::*
-
- KEY = 'scrooge_lookup'.freeze
-
- attr_accessor :resource_signatures
-
- def initialize
- @resource_signatures = Set.new
- end
-
- # Constant signature
- #
- def signature
- KEY
- end
-
- # Store the signature, and return the given resource instance
- #
- def <<( resource )
- @resource_signatures << resource.signature
- resource
- end
-
- end
- end
-end
@@ -31,7 +31,7 @@ def <<( resource )
def marshal_dump #:nodoc:
GUARD.synchronize do
- { environment() => dumped_resources() }
+ dumped_resources()
end
end
@@ -75,7 +75,7 @@ def environment #:nodoc:
def restored_resources( data ) #:nodoc:
GUARD.synchronize do
- data[environment()].map do |resource|
+ data.map do |resource|
Resource.new.marshal_load( resource )
end
end
@@ -1,12 +1,8 @@
production:
orm: 'active_record'
storage: 'memory'
- buffer_threshold: 60
- warmup_threshold: 300
scope: 1234567891
test:
orm: 'active_record'
storage: 'memory'
- buffer_threshold: 10
- warmup_threshold: 30
scope:
Oops, something went wrong.

0 comments on commit fb00ab6

Please sign in to comment.