From 856d321fb135a0b453046e99c266231681bd5ffe Mon Sep 17 00:00:00 2001 From: Jonathan Wilkins Date: Sat, 4 Oct 2008 12:38:24 -0700 Subject: [PATCH] added file_mtime(path, max_age) - checks file mtime so you can restart if a file hasn't been modified for a certain length of time --- lib/god/conditions/file_mtime.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 lib/god/conditions/file_mtime.rb diff --git a/lib/god/conditions/file_mtime.rb b/lib/god/conditions/file_mtime.rb new file mode 100644 index 00000000..8a2385de --- /dev/null +++ b/lib/god/conditions/file_mtime.rb @@ -0,0 +1,28 @@ +module God + module Conditions + + class FileMtime < PollCondition + attr_accessor :path, :max_age + + def initialize + super + self.path = nil + self.max_age = nil + end + + def valid? + valid = true + valid &= complain("Attribute 'path' must be specified", self) if self.path.nil? + valid &= complain("Attribute 'max_age' must be specified", self) if self.max_age.nil? + valid + end + + def test + (Time.now - File.mtime(self.path)) > self.max_age + end + end + + end +end + +