apps/worker/worker.rb in spiderfw-0.5.7 vs apps/worker/worker.rb in spiderfw-0.5.9

- old
+ new

@@ -27,14 +27,16 @@ def self.app_startup end def self.app_startup + return unless Spider.conf.get('worker.enable') @runner = start_runner unless running? end def self.app_shutdown + return unless Spider.conf.get('worker.enable') @mutex.try_lock || return Spider::Logger.info("Shutting down worker in #{Process.pid}") if @runner unless @runner == Thread.current @runner.stop @@ -76,13 +78,22 @@ Dir.new(@scripts_dir).each do |script| next if script[0].chr == '.' load @scripts_dir+'/'+script end end - # every(Spider.conf.get('worker.jobs_interval').to_s+'s') do - # self.run_jobs - # end + Spider.apps.each do |name, mod| + if File.directory?(mod.path+'/config/worker') + Dir.glob(mod.path+'/config/worker/*.rb').each do |path| + file = File.basename(path, '.rb') + next if file[0].chr == '.' + res = Spider.find_resource(:worker, file, nil, mod) + if res + load res.path + end + end + end + end @mutex.unlock end end if (options[:fork]) forked = Spider.fork do @@ -106,10 +117,12 @@ return false unless File.exist?(@pid_file) pid = IO.read(@pid_file).to_i begin Process::kill 0, pid return pid + rescue Errno::EPERM + return pid rescue Errno::ESRCH File.unlink(pid_file) return false end end @@ -163,6 +176,6 @@ end end -end \ No newline at end of file +end