yup 0.0.0 → 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -4,7 +4,7 @@ This is the small daemon for transparent asynchronous delegating HTTP requests w
4
4
 
5
5
  When a http request is arrived the yup daemon (yupd) answers to the client configured answer (by default 200 OK). Then the yupd forwards the http request to the specified host and retries if a timeout error was happend.
6
6
 
7
- == On of use cases
7
+ == One of use cases
8
8
 
9
9
  For example we can have a rails app which send exceptions to an errbit by the gem hoptoad_notifier. We know the errbit can be not available by network issues or some else reasons, but we do not want lose exceptions. To resolve this problem we can start yupd on the same host with the rails app:
10
10
  yupd --listen localhost:8081 --status-code 201 errbit.host.somewhere
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.0
1
+ 0.0.1
data/bin/yupd CHANGED
@@ -15,6 +15,7 @@ Options:
15
15
  --listen <host:port>, -l Listen on an address (default localhost:8080)
16
16
  --status-code <code> Send status code to a client on request (default 200)
17
17
  --resend-delay <seconds> Resend failed requests in seconds (default 5.0)
18
+ --watermark <number> Maximum of concurrent requests (default 100)
18
19
 
19
20
  Examples:
20
21
  yupd --listen 0.0.0.0:8081 --status-code 201 errbit.host.somewhere
@@ -22,12 +23,12 @@ Examples:
22
23
  EOF
23
24
  end
24
25
 
25
- opts = GetoptLong.new(
26
- ['--help', '-h', GetoptLong::NO_ARGUMENT],
27
- ['--listen', '-l', GetoptLong::REQUIRED_ARGUMENT],
28
- ['--status-code', GetoptLong::REQUIRED_ARGUMENT],
29
- ['--resend-delay', '-d', GetoptLong::REQUIRED_ARGUMENT],
30
- )
26
+ opts = GetoptLong.new(*[['--help', '-h', GetoptLong::NO_ARGUMENT],
27
+ ['--listen', '-l', GetoptLong::REQUIRED_ARGUMENT],
28
+ ['--status-code', GetoptLong::REQUIRED_ARGUMENT],
29
+ ['--resend-delay', '-d', GetoptLong::REQUIRED_ARGUMENT],
30
+ ['--watermark', GetoptLong::REQUIRED_ARGUMENT],
31
+ ])
31
32
  config = {}
32
33
  opts.each do |opt, arg|
33
34
  case opt
@@ -40,6 +41,8 @@ opts.each do |opt, arg|
40
41
  config[:resend_delay] = arg.to_f
41
42
  when '--status-code'
42
43
  config[:status_code] = arg.to_i
44
+ when '--watermark'
45
+ config[:watermark] = arg.to_i
43
46
  end
44
47
  end
45
48
 
@@ -51,5 +54,6 @@ end
51
54
 
52
55
  config[:forward_to] = ARGV.shift
53
56
 
57
+ Yup.watermark = config[:watermark] if config.has_key?(:watermark)
54
58
  Yup.resend_delay = config[:resend_delay] if config.has_key?(:resend_delay)
55
59
  Yup.run(config)
@@ -18,6 +18,8 @@ module Yup
18
18
  :body => @body)
19
19
 
20
20
  http.callback do
21
+ Yup.watermark += 1
22
+
21
23
  if http.response_header.status / 100 == 2
22
24
  puts '--- SUCCESS'
23
25
  else
@@ -39,8 +39,14 @@ module Yup
39
39
  resp['Server'] = 'yupd'
40
40
  send_data resp.to_s
41
41
 
42
- EventMachine.next_tick do
43
- RequestForwarder.new(@parser, @body, @forward_to).run
42
+ unless Yup.watermark.zero?
43
+ Yup.watermark -= 1
44
+
45
+ EventMachine.next_tick do
46
+ RequestForwarder.new(@parser, @body, @forward_to).run
47
+ end
48
+ else
49
+ puts "-- watermark is reached, drop"
44
50
  end
45
51
  end
46
52
  end
data/lib/yup.rb CHANGED
@@ -6,12 +6,12 @@ require 'yup/request_handler'
6
6
 
7
7
  module Yup
8
8
  @@resend_delay = 5.0
9
- def self.resend_delay
10
- @@resend_delay
11
- end
12
- def self.resend_delay=(seconds)
13
- @@resend_delay = seconds
14
- end
9
+ def self.resend_delay; @@resend_delay end
10
+ def self.resend_delay=(seconds); @@resend_delay = seconds end
11
+
12
+ @@watermark = 100
13
+ def self.watermark; @@watermark end
14
+ def self.watermark=(seconds); @@watermark = seconds end
15
15
 
16
16
  def self.run(config)
17
17
  host = config[:listen_host] || 'localhost'
data/yup.gemspec ADDED
@@ -0,0 +1,81 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{yup}
8
+ s.version = "0.0.1"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Denis Sukhonin"]
12
+ s.date = %q{2011-08-08}
13
+ s.default_executable = %q{yupd}
14
+ s.description = %q{Just answers 200 (or specified) to a client and asynchronously forwards HTTP request to a configured host}
15
+ s.email = %q{d.sukhonin@gmail.com}
16
+ s.executables = ["yupd"]
17
+ s.extra_rdoc_files = [
18
+ "LICENSE.txt",
19
+ "README.rdoc"
20
+ ]
21
+ s.files = [
22
+ ".document",
23
+ "Gemfile",
24
+ "Gemfile.lock",
25
+ "LICENSE.txt",
26
+ "README.rdoc",
27
+ "Rakefile",
28
+ "VERSION",
29
+ "bin/yupd",
30
+ "lib/yup.rb",
31
+ "lib/yup/request_forwarder.rb",
32
+ "lib/yup/request_handler.rb",
33
+ "test/helper.rb",
34
+ "test/test_yup.rb",
35
+ "yup.gemspec"
36
+ ]
37
+ s.homepage = %q{http://github.com/neglectedvalue/yup}
38
+ s.licenses = ["MIT"]
39
+ s.require_paths = ["lib"]
40
+ s.rubygems_version = %q{1.3.7}
41
+ s.summary = %q{Asynchronous HTTP delegate}
42
+ s.test_files = [
43
+ "test/helper.rb",
44
+ "test/test_yup.rb"
45
+ ]
46
+
47
+ if s.respond_to? :specification_version then
48
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
49
+ s.specification_version = 3
50
+
51
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
+ s.add_runtime_dependency(%q<eventmachine>, [">= 0"])
53
+ s.add_runtime_dependency(%q<em-http-request>, [">= 0"])
54
+ s.add_runtime_dependency(%q<http_parser.rb>, [">= 0"])
55
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
56
+ s.add_development_dependency(%q<yard>, ["~> 0.6.0"])
57
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
59
+ s.add_development_dependency(%q<rcov>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<eventmachine>, [">= 0"])
62
+ s.add_dependency(%q<em-http-request>, [">= 0"])
63
+ s.add_dependency(%q<http_parser.rb>, [">= 0"])
64
+ s.add_dependency(%q<shoulda>, [">= 0"])
65
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
66
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
67
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
68
+ s.add_dependency(%q<rcov>, [">= 0"])
69
+ end
70
+ else
71
+ s.add_dependency(%q<eventmachine>, [">= 0"])
72
+ s.add_dependency(%q<em-http-request>, [">= 0"])
73
+ s.add_dependency(%q<http_parser.rb>, [">= 0"])
74
+ s.add_dependency(%q<shoulda>, [">= 0"])
75
+ s.add_dependency(%q<yard>, ["~> 0.6.0"])
76
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
77
+ s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
78
+ s.add_dependency(%q<rcov>, [">= 0"])
79
+ end
80
+ end
81
+
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 0
9
- version: 0.0.0
8
+ - 1
9
+ version: 0.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Denis Sukhonin
@@ -150,6 +150,7 @@ files:
150
150
  - lib/yup/request_handler.rb
151
151
  - test/helper.rb
152
152
  - test/test_yup.rb
153
+ - yup.gemspec
153
154
  has_rdoc: true
154
155
  homepage: http://github.com/neglectedvalue/yup
155
156
  licenses:
@@ -164,7 +165,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
164
165
  requirements:
165
166
  - - ">="
166
167
  - !ruby/object:Gem::Version
167
- hash: -969212524035482496
168
+ hash: 4139204877131472821
168
169
  segments:
169
170
  - 0
170
171
  version: "0"