Skip to content

Commit

Permalink
move the class methods for starting watchers to the watcher class
Browse files Browse the repository at this point in the history
  • Loading branch information
Maciek Sufa committed Nov 18, 2015
1 parent dd5601b commit a26e8dd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def new
def create
@cluster = Kubernetes::Cluster.new(new_cluster_params)
success = @cluster.save
Kubernetes::Util::start_watcher(@cluster) if success
Watchers::ClusterPodWatcher::start_watcher(@cluster) if success

respond_to do |format|
format.html do
Expand Down Expand Up @@ -43,7 +43,7 @@ def edit
def update
@cluster.assign_attributes(new_cluster_params)
success = @cluster.save
Kubernetes::Util::restart_watcher(@cluster) if success
Watchers::ClusterPodWatcher::restart_watcher(@cluster) if success

respond_to do |format|
format.html do
Expand Down
17 changes: 0 additions & 17 deletions plugins/kubernetes/app/models/kubernetes/util.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require 'celluloid/current'

module Kubernetes
module Util
def self.parse_file(contents, filepath)
Expand All @@ -22,20 +20,5 @@ def self.log(message, extra_info = {})
@output_file.flush
message
end

def self.pod_watcher_symbol(cluster)
"cluster_pod_watcher_#{cluster.id}".to_sym
end

def self.start_watcher(cluster)
watcher_name = pod_watcher_symbol(cluster)
Watchers::ClusterPodWatcher.supervise as: watcher_name, args: [cluster.client]
end

def self.restart_watcher(cluster)
watcher = Celluloid::Actor[pod_watcher_symbol(cluster)]
watcher.terminate if watcher and watcher.alive?
start_watcher(cluster)
end
end
end
17 changes: 16 additions & 1 deletion plugins/kubernetes/app/models/watchers/cluster_pod_watcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,21 @@ def stop_watching
end
end

def self.pod_watcher_symbol(cluster)
"cluster_pod_watcher_#{cluster.id}".to_sym
end

def self.start_watcher(cluster)
watcher_name = pod_watcher_symbol(cluster)
supervise as: watcher_name, args: [cluster.client]
end

def self.restart_watcher(cluster)
watcher = Actor[pod_watcher_symbol(cluster)]
watcher.terminate if watcher and watcher.alive?
start_watcher(cluster)
end

private

def handle_error(notice)
Expand All @@ -49,7 +64,7 @@ def handle_notice(notice)
debug notice.to_s
return if handle_error(notice)
rc_name = notice.object.metadata.labels['replication_controller']
publish rc_name, notice if rc_name
publish(rc_name, notice) if rc_name
end

%w{debug info warn error}.each do |level|
Expand Down
2 changes: 1 addition & 1 deletion plugins/kubernetes/config/initializers/watchers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,4 @@ def build_client_options
Celluloid.logger = Rails.logger
$CELLULOID_DEBUG = true

Kubernetes::Cluster.all.each { |cluster| Kubernetes::Util::start_watcher(cluster) } if ENV['SERVER_MODE']
Kubernetes::Cluster.all.each { |cluster| Watchers::ClusterPodWatcher::start_watcher(cluster) } if ENV['SERVER_MODE']

0 comments on commit a26e8dd

Please sign in to comment.