Commit 915d3153 authored by John E. Vincent's avatar John E. Vincent

basic watcher support.

parent f760cbd7
...@@ -9,10 +9,14 @@ class Application < Ohm::Model ...@@ -9,10 +9,14 @@ class Application < Ohm::Model
index :name index :name
after :create, :notify_via_redis after :save, :notify_via_redis_save
after :update, :notify_via_redis after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate def validate
super
assert_present :name assert_present :name
assert_unique :name assert_unique :name
end end
...@@ -20,7 +24,7 @@ class Application < Ohm::Model ...@@ -20,7 +24,7 @@ class Application < Ohm::Model
def to_hash def to_hash
arr = [] arr = []
configurations.sort.each {|c| arr << c.to_hash} configurations.sort.each {|c| arr << c.to_hash}
super.merge(:name => name, :updated_at => updated_at, :configurations => arr) super.merge(:name => name, :created_at => created_at, :updated_at => updated_at, :configurations => arr)
end end
def is_new? def is_new?
...@@ -42,9 +46,17 @@ class Application < Ohm::Model ...@@ -42,9 +46,17 @@ class Application < Ohm::Model
end end
protected protected
def notify_via_redis def stash_name
msg = self.to_hash.merge({:class => self.class}) @deleted_name = self.name
Ohm.redis.publish(:noah, msg.to_json) end
["save", "create", "update", "delete"].each do |meth|
class_eval do
define_method("notify_via_redis_#{meth}".to_sym) do
pub_category = "noah.#{self.class.to_s}[#{self.name ||= @deleted_name}].#{meth}"
Ohm.redis.publish(pub_category, self.to_json)
end
end
end end
end end
......
...@@ -14,10 +14,14 @@ class Configuration < Ohm::Model ...@@ -14,10 +14,14 @@ class Configuration < Ohm::Model
index :format index :format
index :body index :body
after :create, :notify_via_redis after :save, :notify_via_redis_save
after :update, :notify_via_redis after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate def validate
super
assert_present :name assert_present :name
assert_present :format assert_present :format
assert_present :body assert_present :body
...@@ -25,7 +29,8 @@ class Configuration < Ohm::Model ...@@ -25,7 +29,8 @@ class Configuration < Ohm::Model
end end
def to_hash def to_hash
super.merge(:name => name, :format => format, :body => body, :update_at => updated_at, :application => Application[application_id].name) application.nil? ? app=nil : app=Application[application_id].name
super.merge(:name => name, :format => format, :body => body, :created_at => created_at, :updated_at => updated_at, :application => app)
end end
def is_new? def is_new?
...@@ -47,9 +52,17 @@ class Configuration < Ohm::Model ...@@ -47,9 +52,17 @@ class Configuration < Ohm::Model
end end
protected protected
def notify_via_redis def stash_name
msg = self.to_hash.merge({:class => self.class}) @deleted_name = self.name
Ohm.redis.publish(:noah, msg.to_json) end
["save", "create", "update", "delete"].each do |meth|
class_eval do
define_method("notify_via_redis_#{meth}".to_sym) do
pub_category = "noah.#{self.class.to_s}[#{self.name ||= @deleted_name}].#{meth}"
Ohm.redis.publish(pub_category, self.to_json)
end
end
end end
end end
......
...@@ -11,10 +11,14 @@ class Host < Ohm::Model ...@@ -11,10 +11,14 @@ class Host < Ohm::Model
index :name index :name
index :status index :status
after :create, :notify_via_redis after :save, :notify_via_redis_save
after :update, :notify_via_redis after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate def validate
super
assert_present :name assert_present :name
assert_present :status assert_present :status
assert_unique :name assert_unique :name
...@@ -50,9 +54,18 @@ class Host < Ohm::Model ...@@ -50,9 +54,18 @@ class Host < Ohm::Model
end end
protected protected
def notify_via_redis def stash_name
msg = self.to_hash.merge({:class => self.class}) @deleted_name = self.name
Ohm.redis.publish(:noah, msg.to_json) end
["save", "create", "update", "delete"].each do |meth|
class_eval do
define_method("notify_via_redis_#{meth}".to_sym) do
self.name.nil? ? name=@delete_name : name=self.name
pub_category = "noah.#{self.class.to_s}[#{name}].#{meth}"
Ohm.redis.publish(pub_category, self.to_json)
end
end
end end
end end
......
...@@ -11,10 +11,14 @@ class Service < Ohm::Model ...@@ -11,10 +11,14 @@ class Service < Ohm::Model
index :name index :name
index :status index :status
after :create, :notify_via_redis after :save, :notify_via_redis_save
after :update, :notify_via_redis after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate def validate
super
assert_present :name assert_present :name
assert_present :status assert_present :status
assert_present :host_id assert_present :host_id
...@@ -23,7 +27,8 @@ class Service < Ohm::Model ...@@ -23,7 +27,8 @@ class Service < Ohm::Model
end end
def to_hash def to_hash
super.merge(:name => name, :status => status, :updated_at => updated_at, :host => Host[host_id].name) Host[host_id].nil? ? host_name=nil : host_name=Host[host_id].name
super.merge(:name => name, :status => status, :updated_at => updated_at, :host => host_name)
end end
def is_new? def is_new?
...@@ -53,9 +58,18 @@ class Service < Ohm::Model ...@@ -53,9 +58,18 @@ class Service < Ohm::Model
end end
protected protected
def notify_via_redis def stash_name
msg = self.to_hash.merge({:class => self.class}) @deleted_name = self.name
Ohm.redis.publish(:noah, msg.to_json) end
["save", "create", "update", "delete"].each do |meth|
class_eval do
define_method("notify_via_redis_#{meth}".to_sym) do
self.name.nil? ? name=@deleted_name : name=self.name
pub_category = "noah.#{self.class.to_s}[name].#{meth}"
Ohm.redis.publish(pub_category, self.to_json)
end
end
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment