diff options
author | Luke Kanies <luke@puppetlabs.com> | 2010-06-10 20:57:41 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 8f3e8bb31d513f67ea28a5f249aa850789a10ff2 (patch) | |
tree | 7bc17146f574667822b062e3e32653fe91d3c580 /lib/puppet | |
parent | d6407f46f1743b9f3916d74bc0ed521fb5bf259d (diff) | |
download | puppet-8f3e8bb31d513f67ea28a5f249aa850789a10ff2.tar.gz puppet-8f3e8bb31d513f67ea28a5f249aa850789a10ff2.tar.xz puppet-8f3e8bb31d513f67ea28a5f249aa850789a10ff2.zip |
Working #3139 - ResourceHarness does caching
This is again about moving transactional behaviour out
of Puppet::Type and into the transactional code.
I initially moved this code into Resource::Status,
but it seemed to make more sense in the Harness - the
Status object should be thin and have no code
that doesn't make sense on both sides of the pipe,
it seemed.
The interface gets a bit uglier as a result, but this
is all about good design != good OO (because we're
increasing the argument count of methods by moving
them outside of the target class).
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/transaction.rb | 2 | ||||
-rw-r--r-- | lib/puppet/transaction/resource_harness.rb | 18 | ||||
-rw-r--r-- | lib/puppet/type.rb | 12 |
3 files changed, 15 insertions, 17 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index d2dbf7a1c..88563242e 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -318,7 +318,7 @@ class Puppet::Transaction # Is the resource currently scheduled? def scheduled?(resource) - self.ignoreschedules or resource_harness.scheduled?(resource) + self.ignoreschedules or resource_harness.scheduled?(resource_status(resource), resource) end # Should this resource be skipped? diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index 05e569b92..17e8dfa79 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -23,10 +23,20 @@ class Puppet::Transaction::ResourceHarness status.changed = true end + # Used mostly for scheduling at this point. + def cached(resource, name) + Puppet::Util::Storage.cache(resource)[name] + end + + # Used mostly for scheduling at this point. + def cache(resource, name, value) + Puppet::Util::Storage.cache(resource)[name] = value + end + def changes_to_perform(status, resource) current = resource.retrieve - resource.cache :checked, Time.now + cache resource, :checked, Time.now return [] if ! allow_changes?(resource) @@ -54,7 +64,7 @@ class Puppet::Transaction::ResourceHarness status.change_count = changes.length apply_changes(status, changes) if ! resource.noop? - resource.cache(:synced, Time.now) + cache(resource, :synced, Time.now) resource.flush if resource.respond_to?(:flush) end end @@ -73,7 +83,7 @@ class Puppet::Transaction::ResourceHarness @transaction = transaction end - def scheduled?(resource) + def scheduled?(status, resource) return true if Puppet[:ignoreschedules] return true unless schedule = schedule(resource) @@ -82,7 +92,7 @@ class Puppet::Transaction::ResourceHarness # have been synced a long time ago (e.g., a file only gets updated # once a month on the server and its schedule is daily; the last sync time # will have been a month ago, so we'd end up checking every run). - return schedule.match?(resource.cached(:checked).to_i) + return schedule.match?(cached(resource, :checked).to_i) end def schedule(resource) diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index 4b5a65e1e..fc6161735 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1865,18 +1865,6 @@ class Type end.flatten.reject { |r| r.nil? } end - # Return a cached value - def cached(name) - Puppet::Util::Storage.cache(self)[name] - #@cache[name] ||= nil - end - - # Cache a value - def cache(name, value) - Puppet::Util::Storage.cache(self)[name] = value - #@cache[name] = value - end - # For now, leave the 'name' method functioning like it used to. Once 'title' # works everywhere, I'll switch it. def name |