diff options
author | Luke Kanies <luke@puppetlabs.com> | 2010-06-10 20:31:34 -0700 |
---|---|---|
committer | test branch <puppet-dev@googlegroups.com> | 2010-02-17 06:50:53 -0800 |
commit | 0b95a8528e554df07efe970c9ecfc34535d17c92 (patch) | |
tree | 42ac163a4ab9497e3fb9f676365c1b3da35c5c7d /lib/puppet | |
parent | 4627b8fe11dc14bf42e98b84121b885df73c709e (diff) | |
download | puppet-0b95a8528e554df07efe970c9ecfc34535d17c92.tar.gz puppet-0b95a8528e554df07efe970c9ecfc34535d17c92.tar.xz puppet-0b95a8528e554df07efe970c9ecfc34535d17c92.zip |
Working #3139 - scheduling moved to resource harness
We previously had the schedule checking code in Puppet::Type,
but it's more of a transactional function, and in order to
do proper auditing in the transactional area, we need the
cache checking done there. Scheduling is one
of the few functions that actually uses cached data currently.
Signed-off-by: Luke Kanies <luke@puppetlabs.com>
Diffstat (limited to 'lib/puppet')
-rw-r--r-- | lib/puppet/transaction.rb | 10 | ||||
-rw-r--r-- | lib/puppet/transaction/resource_harness.rb | 22 | ||||
-rw-r--r-- | lib/puppet/type.rb | 43 |
3 files changed, 26 insertions, 49 deletions
diff --git a/lib/puppet/transaction.rb b/lib/puppet/transaction.rb index e57fe5648..d2dbf7a1c 100644 --- a/lib/puppet/transaction.rb +++ b/lib/puppet/transaction.rb @@ -318,12 +318,11 @@ class Puppet::Transaction # Is the resource currently scheduled? def scheduled?(resource) - self.ignoreschedules or resource.scheduled? + self.ignoreschedules or resource_harness.scheduled?(resource) end # Should this resource be skipped? def skip?(resource) - skip = false if missing_tags?(resource) resource.debug "Not tagged with %s" % tags.join(", ") elsif ! scheduled?(resource) @@ -356,11 +355,10 @@ class Puppet::Transaction # Is this resource tagged appropriately? def missing_tags?(resource) - not appropriately_tagged?(resource) - end + return false if ignore_tags? + return false if tags.empty? - def appropriately_tagged?(resource) - self.ignore_tags? or tags.empty? or resource.tagged?(*tags) + not resource.tagged?(*tags) end end diff --git a/lib/puppet/transaction/resource_harness.rb b/lib/puppet/transaction/resource_harness.rb index 76148e69f..05e569b92 100644 --- a/lib/puppet/transaction/resource_harness.rb +++ b/lib/puppet/transaction/resource_harness.rb @@ -73,6 +73,28 @@ class Puppet::Transaction::ResourceHarness @transaction = transaction end + def scheduled?(resource) + return true if Puppet[:ignoreschedules] + return true unless schedule = schedule(resource) + + # We use 'checked' here instead of 'synced' because otherwise we'll + # end up checking most resources most times, because they will generally + # 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) + end + + def schedule(resource) + unless resource.catalog + resource.warning "Cannot schedule without a schedule-containing catalog" + return nil + end + + return nil unless name = resource[:schedule] + resource.catalog.resource(:schedule, name) || resource.fail("Could not find schedule #{name}") + end + private def absent_and_not_being_created?(current, param) diff --git a/lib/puppet/type.rb b/lib/puppet/type.rb index dde342880..4b5a65e1e 100644 --- a/lib/puppet/type.rb +++ b/lib/puppet/type.rb @@ -1669,45 +1669,6 @@ class Type end.flatten.reject { |r| r.nil? } end - ############################### - # All of the scheduling code. - - # Look up the schedule and set it appropriately. This is done after - # the instantiation phase, so that the schedule can be anywhere in the - # file. - def schedule - unless catalog - warning "Cannot schedule without a schedule-containing catalog" - return nil - end - - unless defined? @schedule - if name = self[:schedule] - if sched = catalog.resource(:schedule, name) - @schedule = sched - else - self.fail "Could not find schedule %s" % name - end - else - @schedule = nil - end - end - @schedule - end - - # Check whether we are scheduled to run right now or not. - def scheduled? - return true if Puppet[:ignoreschedules] - return true unless schedule = self.schedule - - # We use 'checked' here instead of 'synced' because otherwise we'll - # end up checking most resources most times, because they will generally - # 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?(self.cached(:checked).to_i) - end - # Define the initial list of tags. def tags=(list) tag(self.class.name) @@ -1895,10 +1856,6 @@ class Type # Set up all of our autorequires. def finish - # Scheduling has to be done when the whole config is instantiated, so - # that file order doesn't matter in finding them. - self.schedule - # Make sure all of our relationships are valid. Again, must be done # when the entire catalog is instantiated. self.class.relationship_params.collect do |klass| |