Class: CodeSync::Manager

Inherits:
Object
  • Object
show all
Defined in:
lib/code_sync/manager.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (protected)



234
235
236
# File 'lib/code_sync/manager.rb', line 234

def method_missing meth, *args, &block
  puts "Need to implement #{ meth }"
end

Instance Attribute Details

#client_managerObject

Returns the value of attribute client_manager.



48
49
50
# File 'lib/code_sync/manager.rb', line 48

def client_manager
  @client_manager
end

#optionsObject

Returns the value of attribute options.



48
49
50
# File 'lib/code_sync/manager.rb', line 48

def options
  @options
end

#process_mapObject

Returns the value of attribute process_map.



48
49
50
# File 'lib/code_sync/manager.rb', line 48

def process_map
  @process_map
end

#processesObject

Returns the value of attribute processes.



48
49
50
# File 'lib/code_sync/manager.rb', line 48

def processes
  @processes
end

#serverObject

Returns the value of attribute server.



48
49
50
# File 'lib/code_sync/manager.rb', line 48

def server
  @server
end

#sprocketsObject

Returns the value of attribute sprockets.



48
49
50
# File 'lib/code_sync/manager.rb', line 48

def sprockets
  @sprockets
end

Class Method Details

.cleanup_stale_processesObject

FIXME: You know this aint right



38
39
40
41
42
43
44
45
46
# File 'lib/code_sync/manager.rb', line 38

def self.cleanup_stale_processes
  PTY.spawn("ps aux |grep 'codesyn[c]'") do |stdin,stdout,pid|
    stdin.each do |output|
      if pid = output.split[1]
        `kill -9 #{ pid }`
      end
    end
  end
end

.start(options = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/code_sync/manager.rb', line 13

def self.start options={}
  begin
    manager = new(options)

    cleanup_stale_processes

    if options[:forked]
      pid = fork do
        manager.start
      end

      Process.detach(pid)
    else
      manager.start(options)
    end
  rescue
    puts "Error Manager. #{ $! }"
  ensure
    puts "Clesning up finally"
    cleanup_stale_processes
  end
end

Instance Method Details

#start(options = {}) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/code_sync/manager.rb', line 50

def start options={}
  if already_running?
    puts "== Codesync is already running"
    return
  end

  $0 = "codesync process: manager"

  build_process_map

  trap("SIGINT") do
    exit_gracefully # :)
  end


  puts "== All CodeSync processes exited cleanly."
end