Permalink
Browse files

Huge change to de-rubygemify RQ plus a few small cleanups

CR: please
  • Loading branch information...
1 parent ff776c7 commit 75e4e028b0407520c261ca2f3d2b1936d413f8e2 Dru Nelson committed May 24, 2010
Showing 349 changed files with 58,083 additions and 393 deletions.
View
@@ -2,16 +2,4 @@ config
queue
queue.noindex
.#*
-log/*
-bin/*
-!bin/rc.rq
-!bin/rq
-!bin/server.rb
-!bin/server_daemon.sh
-!bin/server_daemon.rb
-!bin/server_daemon.rb.off
-!bin/web_server.sh
-!bin/web_server.rb
-!bin/queuemgr_ctl
-gems/*
-!gems/cache
+log/*.log
View
@@ -1,7 +0,0 @@
-bundle_path "gems"
-
-gem "rack", "1.0.0"
-gem "sinatra", "0.9.4"
-gem "json_pure", "1.1.6"
-
-disable_system_gems
View
@@ -1,4 +1,3 @@
-require "rubygems"
include FileUtils
View
@@ -1,3 +1,2 @@
#!/usr/bin/env ruby
-$:.unshift(File.join(File.dirname(__FILE__), ".."))
require 'code/queuemgr_ctl'
View
@@ -1,24 +0,0 @@
-#!/usr/bin/ruby
-
-$:.unshift(File.join(File.dirname(__FILE__), ".."))
-
-Dir.glob(File.join("gems", "gems", "*", "lib")).each do |lib|
- $LOAD_PATH.unshift(File.expand_path(lib))
-end
-
-require 'rubygems'
-gem_paths = [File.expand_path(File.join("gems")), Gem.default_dir]
-Gem.clear_paths
-Gem.send :set_paths, gem_paths.join(":")
-
-require 'code/router.rb'
-
-builder = MiniRouter.new
-
-if ENV["RQ_PORT"].nil?
- rq_port = 3333
-else
- rq_port = ENV["RQ_PORT"].to_i
-end
-
-Rack::Handler::WEBrick.run(builder, :Port => rq_port)
@@ -1,43 +0,0 @@
-#!/usr/bin/ruby
-
-$:.unshift(File.join(File.dirname(__FILE__), ".."))
-
-Dir.glob(File.join("gems", "gems", "*", "lib")).each do |lib|
- $LOAD_PATH.unshift(File.expand_path(lib))
-end
-
-Dir.chdir(File.join(File.dirname(__FILE__), ".."))
-
-require 'rubygems'
-gem_paths = [File.expand_path(File.join("gems")), Gem.default_dir]
-Gem.clear_paths
-Gem.send :set_paths, gem_paths.join(":")
-
-require 'code/router.rb'
-
-builder = MiniRouter.new
-
-if ENV["RQ_PORT"].nil?
- rq_port = 3333
-else
- rq_port = ENV["RQ_PORT"].to_i
-end
-
-pid = fork do
- Signal.trap('HUP', 'IGNORE') # Don't die upon logout
- FileUtils.mkdir_p("log")
-
- STDIN.reopen("/dev/null")
- STDOUT.reopen("log/server.log", "a+")
- STDOUT.sync = true
- $stderr = STDOUT
-
- Signal.trap("TERM") do
- Process.kill("KILL", Process.pid)
- end
-
- Rack::Handler::WEBrick.run(builder, :Port => rq_port)
-end
-
-Process.detach(pid)
-
@@ -1,9 +0,0 @@
-#!/bin/sh
-
-if [ "X$RQ_PORT" = "X" ] ; then
- RQ_PORT=3333
- export RQ_PORT
-fi
-
-exit 1
-
View
@@ -0,0 +1,61 @@
+#!/usr/bin/ruby
+#$:.unshift(File.join(File.dirname(__FILE__), ".."))
+
+#Dir.glob(File.join("gems", "gems", "*", "lib")).each do |lib|
+# $LOAD_PATH.unshift(File.expand_path(lib))
+#end
+
+Dir.chdir(File.join(File.dirname(__FILE__), ".."))
+
+#require 'rubygems'
+#gem_paths = [File.expand_path(File.join("gems")), Gem.default_dir]
+#Gem.clear_paths
+#Gem.send :set_paths, gem_paths.join(":")
+
+require 'code/unixrack.rb'
+require 'code/router.rb'
+
+require 'json'
+
+def load_config
+ begin
+ data = File.read('config/config.json')
+ config = JSON.parse(data)
+ $host = config['host']
+ $port = config['port']
+ $addr = config['addr']
+ rescue
+ puts "Couldn't read config/config.json file properly. Exiting"
+ exit! 1
+ end
+end
+
+if ARGV[0] == "install"
+ $host = "127.0.0.1"
+ $port = "3333"
+ $addr = "0.0.0.0"
+else
+ load_config
+end
+
+pid = fork do
+ Signal.trap('HUP', 'IGNORE') # Don't die upon logout
+ FileUtils.mkdir_p("log")
+
+ STDIN.reopen("/dev/null")
+ STDOUT.reopen("log/server.log", "a+")
+ STDOUT.sync = true
+ $stderr = STDOUT
+
+ Signal.trap("TERM") do
+ Process.kill("KILL", Process.pid)
+ end
+
+ builder = MiniRouter.new
+ Rack::Handler::UnixRack.run(builder, {:port => $port,
+ :host => $host,
+ :listen => $addr})
+end
+
+Process.detach(pid)
+
View
@@ -1,27 +1,43 @@
#!/usr/bin/ruby
-$:.unshift(File.join(File.dirname(__FILE__), ".."))
+Dir.chdir(File.join(File.dirname(__FILE__), ".."))
-Dir.glob(File.join("gems", "gems", "*", "lib")).each do |lib|
- $LOAD_PATH.unshift(File.expand_path(lib))
-end
+require 'vendor/environment.rb'
+require 'code/unixrack.rb'
+require 'code/router.rb'
+require 'json'
-Dir.chdir(File.join(File.dirname(__FILE__), ".."))
-require 'rubygems'
-gem_paths = [File.expand_path(File.join("gems")), Gem.default_dir]
-Gem.clear_paths
-Gem.send :set_paths, gem_paths.join(":")
+def run
+ Signal.trap('HUP', 'IGNORE') # Don't die upon logout
+ FileUtils.mkdir_p("log")
-require 'code/router.rb'
+ exit(1) unless File.directory?("log")
-require 'json'
+ STDIN.reopen("/dev/null")
+ STDOUT.reopen("log/web_server.log", "a")
+ #STDOUT.sync = true
+ $stderr = STDOUT
-require 'unixrack.rb'
+ Signal.trap("TERM") do
+ Process.kill("KILL", Process.pid)
+ end
+
+ router = MiniRouter.new
+ Rack::Handler::UnixRack.run(router, {:port => $port,
+ :host => $host,
+ :listen => $addr})
+end
-router = MiniRouter.new
-def load_config
+#
+# HANDLE CONFIG
+
+if ARGV[0] == "install"
+ $host = "127.0.0.1"
+ $port = "3333"
+ $addr = "0.0.0.0"
+else
begin
data = File.read('config/config.json')
config = JSON.parse(data)
@@ -34,31 +50,19 @@ def load_config
end
end
-if ARGV[0] == "install"
- $host = "127.0.0.1"
- $port = "3333"
- $addr = "0.0.0.0"
-else
- load_config
-end
-
-#pid = fork do
-# Signal.trap('HUP', 'IGNORE') # Don't die upon logout
-# FileUtils.mkdir_p("log")
-
-# STDIN.reopen("/dev/null")
-# STDOUT.reopen("log/server.log", "a+")
-# STDOUT.sync = true
-# $stderr = STDOUT
-# Signal.trap("TERM") do
-# Process.kill("KILL", Process.pid)
-# end
+#
+# HANDLE ARGV
- Rack::Handler::UnixRack.run(router, {:port => $port,
- :host => $host,
- :listen => $addr})
-#end
+if ARGV[0] == "server"
+ puts "Starting in background..."
+ pid = fork do
+ run()
+ end
-#Process.detach(pid)
+ Process.detach(pid)
+else
+ puts "Staying in foreground..."
+ run()
+end
View
@@ -1,61 +1,4 @@
-#!/usr/bin/ruby
-$:.unshift(File.join(File.dirname(__FILE__), ".."))
+#!/bin/bash
-Dir.glob(File.join("gems", "gems", "*", "lib")).each do |lib|
- $LOAD_PATH.unshift(File.expand_path(lib))
-end
-
-Dir.chdir(File.join(File.dirname(__FILE__), ".."))
-
-require 'rubygems'
-gem_paths = [File.expand_path(File.join("gems")), Gem.default_dir]
-Gem.clear_paths
-Gem.send :set_paths, gem_paths.join(":")
-
-require 'unixrack.rb'
-require 'code/router.rb'
-
-require 'json'
-
-def load_config
- begin
- data = File.read('config/config.json')
- config = JSON.parse(data)
- $host = config['host']
- $port = config['port']
- $addr = config['addr']
- rescue
- puts "Couldn't read config/config.json file properly. Exiting"
- exit! 1
- end
-end
-
-if ARGV[0] == "install"
- $host = "127.0.0.1"
- $port = "3333"
- $addr = "0.0.0.0"
-else
- load_config
-end
-
-pid = fork do
- Signal.trap('HUP', 'IGNORE') # Don't die upon logout
- FileUtils.mkdir_p("log")
-
- STDIN.reopen("/dev/null")
- STDOUT.reopen("log/server.log", "a+")
- STDOUT.sync = true
- $stderr = STDOUT
-
- Signal.trap("TERM") do
- Process.kill("KILL", Process.pid)
- end
-
- builder = MiniRouter.new
- Rack::Handler::UnixRack.run(builder, {:port => $port,
- :host => $host,
- :listen => $addr})
-end
-
-Process.detach(pid)
+./bin/web_server.rb server
View
@@ -3,6 +3,7 @@
require 'json'
require 'fcntl'
require 'digest'
+require 'fileutils'
module RQ
class Queue
View
@@ -7,7 +7,7 @@
require 'version'
def log(mesg)
- File.open('config/queuemgr.log', "a") do
+ File.open('log/queuemgr.log', "a") do
|f|
f.write("#{Process.pid} - #{Time.now} - #{mesg}\n")
end
@@ -91,21 +91,15 @@ def handle_request(sock)
end
if data[0].index('queues') == 0
data = @queues.map { |q| q.name }.to_json
- File.open('config/queuemgr.log', "a") do
- |f|
- f.write("#{Process.pid} - #{Time.now} - RESP [ #{data} ]\n")
- end
+ log("RESP [ queues - #{data} ]")
sock.send(data, 0)
sock.close
return
end
if data[0].index('uptime') == 0
data = [(Time.now - @start_time).to_i, ].to_json #['local','brserv_push'].to_json
- File.open('config/queuemgr.log', "a") do
- |f|
- f.write("#{Process.pid} - #{Time.now} - RESP [ #{data} ]\n")
- end
+ log("RESP [ uptime - #{data} ]")
sock.send(data, 0)
sock.close
return
@@ -120,10 +114,7 @@ def handle_request(sock)
else
resp = ['fail', 'queue not created'].to_json
results = RQ::Queue.create(options)
- File.open('config/queuemgr.log', "a") do
- |f|
- f.write("#{Process.pid} - #{Time.now} - STARTED [ #{options['name']}#{results[0]} ]\n")
- end
+ log("create_queue STARTED [ #{options['name']}#{results[0]} ]")
if results
qc = QueueClient.new(options['name'])
worker = Worker.new
Oops, something went wrong.

0 comments on commit 75e4e02

Please sign in to comment.