whimsy-asf 0.0.70 → 0.0.71

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f924b1857e96a3bd4a2bd75839d149c7878a00e6
4
- data.tar.gz: 09c84284eb5d791040fb2289d2c4ee6ac5d9ee63
3
+ metadata.gz: 7488584a6f4cafc47dc234295ad6e046f1e491eb
4
+ data.tar.gz: 3b2adc822404304bad77f14a4dd76262660a77cf
5
5
  SHA512:
6
- metadata.gz: 654ef995bd682ff067ccaafe09bbbab30356fe5e367201057d89bc990466e95ae438029fb53390490887da510518f3ce177d4d568831c2562845b700242d53b5
7
- data.tar.gz: 1c69d9652038b168085544dae93b210e1b4bb1be931820ae50e3bc94e3c707178b81654d2f1ab3f8685c94ab8b2bbff7ef2e1951dd950cb5de2120c3a3afed7f
6
+ metadata.gz: 9093b11de30d5247c570fff9d491b41868688d74b208399f17a29a9183b11c91ebc0680b71100a385d03bc819edc6906f50f86e0878f43fa2279fc4db8e51c84
7
+ data.tar.gz: dbeb058102b873298f396e6cc5d44ac6d1dd1a37bf185a7df9c957035f9f96ae4a1771cf1afb3739df5ab4be91e9ea28f4f6e72f27b109187ae98828933ebd0c
data/asf.version CHANGED
@@ -1 +1 @@
1
- 0.0.70
1
+ 0.0.71
@@ -1,5 +1,6 @@
1
1
  require 'wunderbar'
2
2
  require 'ldap'
3
+ require 'weakref'
3
4
 
4
5
  module ASF
5
6
  module LDAP
@@ -107,22 +108,32 @@ module ASF
107
108
  end
108
109
 
109
110
  def self.[] name
110
- collection[name] || new(name)
111
+ new(name)
111
112
  end
112
113
 
113
114
  def self.find name
114
- collection[name] || new(name)
115
+ new(name)
115
116
  end
116
117
 
117
118
  def self.new name
118
- collection[name] || super
119
+ begin
120
+ object = collection[name]
121
+ return object.reference if object and object.weakref_alive?
122
+ rescue
123
+ end
124
+
125
+ super
119
126
  end
120
127
 
121
128
  def initialize name
122
- self.class.collection[name] = self
129
+ self.class.collection[name] = WeakRef.new(self)
123
130
  @name = name
124
131
  end
125
132
 
133
+ def reference
134
+ self
135
+ end
136
+
126
137
  unless Object.respond_to? :id
127
138
  def id
128
139
  @name
@@ -1,6 +1,7 @@
1
1
  require_relative '../asf.rb'
2
2
  require 'rack'
3
3
  require 'etc'
4
+ require 'thread'
4
5
 
5
6
  module ASF
6
7
  module Auth
@@ -33,7 +34,7 @@ module ASF
33
34
  ASF::Person.new(env.user)
34
35
  end
35
36
 
36
- # Simply 'use' the following class in config.ru to limit access
37
+ # 'use' the following class in config.ru to limit access
37
38
  # to the application to ASF committers
38
39
  class Committers < Rack::Auth::Basic
39
40
  def initialize(app)
@@ -53,7 +54,7 @@ module ASF
53
54
  end
54
55
  end
55
56
 
56
- # Simply 'use' the following class in config.ru to limit access
57
+ # 'use' the following class in config.ru to limit access
57
58
  # to the application to ASF members and officers and the accounting group.
58
59
  class MembersAndOfficers < Rack::Auth::Basic
59
60
  def initialize(app)
@@ -84,6 +85,87 @@ module ASF
84
85
  end
85
86
  end
86
87
 
88
+ # 'use' the following class in config.ru to automatically run
89
+ # Garbage Collection every 'n' requests, or 'm' minutes.
90
+ #
91
+ # This tries to run garbage collection "out of band" (i.e., between
92
+ # requests), and when other requests are active (which can happen
93
+ # with threaded servers like Puma).
94
+ #
95
+ # In addition to keeping memory usage bounded, this keeps the LDAP
96
+ # cache from going stale.
97
+ #
98
+ class AutoGC
99
+ @@background = nil
100
+
101
+ def initialize(app, frequency=100, minutes=15)
102
+ @app = app
103
+ @frequency = frequency
104
+ @request_count = 0
105
+ @queue = Queue.new
106
+ @mutex = Mutex.new
107
+
108
+ if defined?(PhusionPassenger)
109
+ # https://github.com/suyccom/yousell/blob/master/config.ru
110
+ # https://www.phusionpassenger.com/library/indepth/ruby/out_of_band_work.html
111
+ if PhusionPassenger.respond_to?(:require_passenger_lib)
112
+ PhusionPassenger.require_passenger_lib 'rack/out_of_band_gc'
113
+ else
114
+ # Phusion Passenger < 4.0.33
115
+ require 'phusion_passenger/rack/out_of_band_gc'
116
+ end
117
+ @passenger = PhusionPassenger::Rack::OutOfBandGc.new(app.count)
118
+ end
119
+
120
+ Thread.kill(@@background) if @@background
121
+
122
+ if minutes
123
+ # divide minutes by frequency and use the result to determine the
124
+ # time between simulated requests
125
+ @@background = Thread.new do
126
+ seconds = minutes * 60.0 / frequency
127
+ loop do
128
+ sleep seconds
129
+ maybe_perform_gc
130
+ end
131
+ end
132
+ end
133
+ end
134
+
135
+ def call(env)
136
+ @queue.push 1
137
+
138
+ if @passenger
139
+ @passenger.call(env)
140
+ else
141
+ # https://github.com/puma/puma/issues/450
142
+ status, header, body = @app.call(env)
143
+
144
+ if ary = env['rack.after_reply']
145
+ ary << lambda {maybe_perform_gc}
146
+ else
147
+ Thread.new {sleep 0.1; maybe_perform_gc}
148
+ end
149
+
150
+ [status, header, body]
151
+ end
152
+ ensure
153
+ @queue.pop
154
+ end
155
+
156
+ def maybe_perform_gc
157
+ @mutex.synchronize do
158
+ @request_count += 1
159
+ if @queue.empty? and @request_count >= @frequency
160
+ @request_count = 0
161
+ disabled = GC.enable
162
+ GC.start
163
+ GC.disable if disabled
164
+ end
165
+ end
166
+ end
167
+ end
168
+
87
169
  # Apache httpd on whimsy-vm is behind a proxy that converts https
88
170
  # requests into http requests. Update the environment variables to
89
171
  # match.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: whimsy-asf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.70
4
+ version: 0.0.71
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Ruby
@@ -14,84 +14,84 @@ dependencies:
14
14
  name: nokogiri
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rack
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: ruby-ldap
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: tzinfo
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: tzinfo-data
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: wunderbar
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  description: |2
@@ -137,12 +137,12 @@ require_paths:
137
137
  - lib
138
138
  required_ruby_version: !ruby/object:Gem::Requirement
139
139
  requirements:
140
- - - ">="
140
+ - - '>='
141
141
  - !ruby/object:Gem::Version
142
142
  version: '0'
143
143
  required_rubygems_version: !ruby/object:Gem::Requirement
144
144
  requirements:
145
- - - ">="
145
+ - - '>='
146
146
  - !ruby/object:Gem::Version
147
147
  version: '0'
148
148
  requirements: []