Sha256: 1733f0f513aae0bf8dba10261b6891f6b58ac58cce8fd3c718ef639c175e5427

Contents?: true

Size: 1.03 KB

Versions: 20

Compression:

Stored size: 1.03 KB

Contents

class App

  def self.running
    @running ? true : false
  end

  def self.port
    ENV['PORT'] || 5000
  end

  def self.cometio_url
    "http://localhost:#{port}/cometio/io"
  end

  def self.pid_file
    ENV['PID_FILE'] || "/tmp/sinatra-cometio-testapp.pid"
  end

  def self.app_dir
    File.expand_path 'app', File.dirname(__FILE__)
  end

  def self.pid
    return unless @running
    File.open(pid_file) do |f|
      pid = f.gets.strip.to_i
      return pid if pid > 0
    end
    return
  end

  def self.start
    return if @running
    File.delete pid_file if File.exists? pid_file
    Thread.new do
      IO::popen "cd #{app_dir} && PID_FILE=#{pid_file} rackup config.ru -p #{port} > /dev/null 2>&1"
    end
    @running = true
    100.times do
      if File.exists? pid_file
        sleep 0.1
        return true
      end
      sleep 1
    end
    @running = false
    return false
  end

  def self.stop
    return unless @running
    system "kill #{pid}"
    File.delete pid_file if File.exists? pid_file
    @running = false
  end

end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
sinatra-cometio-0.5.9 test/app.rb
sinatra-cometio-0.5.8 test/app.rb
sinatra-cometio-0.5.7 test/app.rb
sinatra-cometio-0.5.6 test/app.rb
sinatra-cometio-0.5.5 test/app.rb
sinatra-cometio-0.5.4 test/app.rb
sinatra-cometio-0.5.3 test/app.rb
sinatra-cometio-0.5.2 test/app.rb
sinatra-cometio-0.5.1 test/app.rb
sinatra-cometio-0.5.0 test/app.rb
sinatra-cometio-0.4.3 test/app.rb
sinatra-cometio-0.4.2 test/app.rb
sinatra-cometio-0.4.1 test/app.rb
sinatra-cometio-0.4.0 test/app.rb
sinatra-cometio-0.3.9 test/app.rb
sinatra-cometio-0.3.8 test/app.rb
sinatra-cometio-0.3.7 test/app.rb
sinatra-cometio-0.3.6 test/app.rb
sinatra-cometio-0.3.5 test/app.rb
sinatra-cometio-0.3.4 test/app.rb