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
index :name
after :create, :notify_via_redis
after :update, :notify_via_redis
after :save, :notify_via_redis_save
after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate
super
assert_present :name
assert_unique :name
end
......@@ -20,7 +24,7 @@ class Application < Ohm::Model
def to_hash
arr = []
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
def is_new?
......@@ -42,9 +46,17 @@ class Application < Ohm::Model
end
protected
def notify_via_redis
msg = self.to_hash.merge({:class => self.class})
Ohm.redis.publish(:noah, msg.to_json)
def stash_name
@deleted_name = self.name
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
......
......@@ -14,10 +14,14 @@ class Configuration < Ohm::Model
index :format
index :body
after :create, :notify_via_redis
after :update, :notify_via_redis
after :save, :notify_via_redis_save
after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate
super
assert_present :name
assert_present :format
assert_present :body
......@@ -25,7 +29,8 @@ class Configuration < Ohm::Model
end
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
def is_new?
......@@ -47,9 +52,17 @@ class Configuration < Ohm::Model
end
protected
def notify_via_redis
msg = self.to_hash.merge({:class => self.class})
Ohm.redis.publish(:noah, msg.to_json)
def stash_name
@deleted_name = self.name
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
......
......@@ -11,10 +11,14 @@ class Host < Ohm::Model
index :name
index :status
after :create, :notify_via_redis
after :update, :notify_via_redis
after :save, :notify_via_redis_save
after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate
super
assert_present :name
assert_present :status
assert_unique :name
......@@ -50,9 +54,18 @@ class Host < Ohm::Model
end
protected
def notify_via_redis
msg = self.to_hash.merge({:class => self.class})
Ohm.redis.publish(:noah, msg.to_json)
def stash_name
@deleted_name = self.name
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
......
......@@ -11,10 +11,14 @@ class Service < Ohm::Model
index :name
index :status
after :create, :notify_via_redis
after :update, :notify_via_redis
after :save, :notify_via_redis_save
after :create, :notify_via_redis_create
after :update, :notify_via_redis_update
before :delete, :stash_name
after :delete, :notify_via_redis_delete
def validate
super
assert_present :name
assert_present :status
assert_present :host_id
......@@ -23,7 +27,8 @@ class Service < Ohm::Model
end
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
def is_new?
......@@ -53,9 +58,18 @@ class Service < Ohm::Model
end
protected
def notify_via_redis
msg = self.to_hash.merge({:class => self.class})
Ohm.redis.publish(:noah, msg.to_json)
def stash_name
@deleted_name = self.name
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
......
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