Class: Server

Inherits:
Sinatra::Base
  • Object
show all
Defined in:
lib/server.rb

Overview

Sinatra server to host the statistics for the CobwebCrawler

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.cobweb_optionsObject



103
104
105
# File 'lib/server.rb', line 103

def self.cobweb_options
  @options
end

.start(options = {}) ⇒ Object

Starts the Sinatra server, and kills the processes when shutdown



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/server.rb', line 83

def self.start(options={})
  @options = options
  @options[:redis_options] = {} unless @options.has_key? :redis_options
  unless Server.running?
    if @options[:run_as_server]
      puts "Starting Sinatra for cobweb v#{Cobweb.version}"
      Server.run!
      puts "Stopping crawl..."
    else
      thread = Thread.new do
        puts "Starting Sinatra"
        Server.run!
        puts "Stopping crawl..."
        ## we need to manually kill the main thread as sinatra traps the interrupts
        Thread.main.kill
      end
    end
  end    
end

Instance Method Details

#cobweb_version(crawl_id) ⇒ Object



70
71
72
73
74
75
76
# File 'lib/server.rb', line 70

def cobweb_version(crawl_id)
  redis = Redis.new(redis_options)
  key = redis.keys("cobweb-*-#{crawl_id}:queued").first
  
  key =~ /cobweb-(.*?)-(.*?):queued/
  cobweb_version = $1
end

#redis_optionsObject



78
79
80
# File 'lib/server.rb', line 78

def redis_options
  Server.cobweb_options[:redis_options]
end