Changeset 580

Show
Ignore:
Timestamp:
03/28/07 13:44:08 (2 years ago)
Author:
sacha
Message:

better support for shutdown of tasker. checkes if there are files to be removed

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/taskers/hefeweizen_tasker_application_http_server.rb

    r569 r580  
    3939require 'logger' 
    4040require 'pp' 
     41require 'monitor' 
    4142 
    4243$exit = false 
    4344 
    44 Signal.trap("INT") do  $stderr.puts "#{$0}: HefeWeizen Tasker HTTP Server caught INT signal. not exitting"; end 
    45 Signal.trap("USR1") do  $stderr.puts "#{$0}: HefeWeizen Tasker HTTP Server caught USR1 signal. Exitting ... "; $exit = true; end 
     45$instance = 0 
     46$pipes = [] 
     47$pipes.extend MonitorMixin 
     48 
     49$mutex = Mutex.new 
     50 
     51 
     52Signal.trap("INT") do  $stdout.puts "#{$0}: HefeWeizen Tasker HTTP Server caught INT signal. not exitting"; end 
     53Signal.trap("USR1") { 
     54  $stdout.puts "#{$0}: HefeWeizen Tasker HTTP Server caught USR1 signal. Exitting ... " 
     55  # TODO check where process is. Eg clean up pipe to HTTP Server. 
     56 
     57  $mutex.synchronize do 
     58    if $instance > 0 then 
     59      $pipes.synchronize do 
     60        $stdout.puts "HTTP Server Tasker needs to cleanup files." 
     61        $pipes.each{ | pipe | 
     62          begin 
     63            FileUtils.rm_rf(pipe) 
     64          rescue Exception => e 
     65            $stdout.puts "Exception: #{e.to_s}" 
     66          end 
     67        } 
     68      end 
     69    end 
     70    $stdout.puts "HTTP Server Taserk Exitting." 
     71    Process.exit! 0 
     72  end 
     73
    4674 
    4775module HefeWeizen 
     
    7098 
    7199      def do_POST(req, resp) 
    72  
     100         
     101        $mutex.synchronize do 
     102          $instance += 1 
     103        end 
    73104        # 0. if we are in the testing environment 
    74105        if @config['BIG_ANIA_LOAD_TEST_ENVIRONMENT'] == 'true' then 
     
    86117              #              resp.body = "blah blah blah" 
    87118              #              resp.status = 204 
    88               return 
     119              return finished 
    89120            end 
    90121          end 
     
    130161         
    131162        my_pipe = "#{@config['PIPE_DIR']}/pipe_to_http_server_#{now.to_f.to_s}" 
     163        $pipes.synchronize do 
     164          $pipes.push my_pipe 
     165        end 
    132166        command = "mkfifo #{my_pipe}" 
    133167        system(command) 
     
    244278        pipe_to_me.close 
    245279        FileUtils.rm(my_pipe) 
    246  
    247         return true 
    248       end 
     280        $pipes.synchronize do 
     281          $pipes.delete my_pipe 
     282        end 
     283        return finished 
     284      end 
     285 
     286      private 
     287      def finished 
     288        $mutex.synchronize do 
     289          $instance -= 1 
     290        end 
     291      end 
     292 
    249293    end 
    250294