Class: Application::Watcher

Inherits:
Win32::Daemon
  • Object
show all
Defined in:
lib/cantemo/portal/agent/cli/commands/watch_folders.rb,
lib/cantemo/portal/agent/cli/commands/watch_folders.rb

Constant Summary collapse

APP_NAME =
'cantemo-portal-watch-folders'

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.daemons_run_proc_with_cleanup(options, &block) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 129

def self.daemons_run_proc_with_cleanup(options, &block)
  options[:dir_mode] = :normal
  options[:dir]      = File.split(__FILE__)[0]

  if block_given?
    options[:mode] = :proc
    options[:proc] = block
  end

  controller                            = Daemons::Controller.new(options, ARGV)
  _command, _controller_part, _app_part = controller.class.split_argv(ARGV)

  controller_group                 = Daemons::ApplicationGroup.new(controller.app_name, controller.options)
  controller_group.controller_argv = _controller_part
  controller_group.app_argv        = _app_part

  controller_group.setup
  applications = controller_group.applications

  is_running = applications.find { |a| a.running? }
  if !applications.empty?
    puts "Found #{applications.length} existing pid file(s) #{applications.map { |a| a.pid.pid }}"
    should_zap_all = !is_running || (applications.length == 1 && applications.first.pid.pid == 0)
    if should_zap_all
      warn "Found stale pid file(s)"
      controller_group.zap_all
      controller_group.options[:force] = true
      # controller_group.applications = []

      controller.options[:force] = true
    end
  end

  Daemons.run_proc(options[:app_name], options, &block)
  # controller.catch_exceptions do
  #   controller.run
  # end

end

.run(args) ⇒ Object



125
126
127
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 125

def self.run(args)
  WATCH_FOLDER_MANAGER_CLASS.run(args)
end

.run_in_foreground(args, options = { }) ⇒ Object



182
183
184
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 182

def self.run_in_foreground(args, options = { })
  self.run(args)
end

.run_with_process_manager(args, options = {}) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 169

def self.run_with_process_manager(args, options = {})
  # ARGV.unshift 'run' unless %w(start stop restart run zap killall status).include? ARGV.first
  require 'daemons'
  proc     = Proc.new { self.run(args) }
  app_name = APP_NAME

  # options[:app_name] = app_name
  # daemons_run_proc_with_cleanup(options, &proc)

  # options[:force] = true
  Daemons.run_proc(app_name, options, &proc)
end

Instance Method Details

#service_initObject



98
99
100
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 98

def service_init

end

#service_main(*args) ⇒ Object



102
103
104
105
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 102

def service_main(*args)
  @WatchFolderManager = WATCH_FOLDER_MANAGER_CLASS.new(args)
  @WatchFolderManager.run
end

#service_pauseObject



111
112
113
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 111

def service_pause
  @WatchFolderManager.pause
end

#service_resumeObject



115
116
117
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 115

def service_resume
  @WatchFolderManager.resume
end

#service_stopObject



107
108
109
# File 'lib/cantemo/portal/agent/cli/commands/watch_folders.rb', line 107

def service_stop
  @WatchFolderManager.stop
end