spiderfw 0.6.17 → 0.6.18

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,11 @@
1
+ = 0.6.18
2
+ == 16 September, 2011
3
+ * Thread management (keeps track of threads to wait for when exiting)
4
+ * Under Phusion Passenger, controller's 'after' is now executed when the response is sent
5
+ * Table widget now accepts a link_id not in the Table's shown elements
6
+ * CLDR fixes
7
+ * Updater fixes
8
+
1
9
  = 0.6.17
2
10
  == 13 September, 2011
3
11
  * AppManager rewrite, with setup tasks; Migrations
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.6.17
1
+ 0.6.18
@@ -15,7 +15,7 @@
15
15
  <tpl:pass sp:each_index="@rows |row_i|">
16
16
  <tr class="row { (row_i%2==0) ? 'odd' : 'even' }">
17
17
  <td sp:each="@elements |element|">
18
- <a sp:tag-if="@link_el && element == @link_el" href="{ @link }{ Spider::HTTP.urlencode(@rows[row_i][@link_id]) }">
18
+ <a sp:tag-if="@link_el && element == @link_el" href="{ @link }{ Spider::HTTP.urlencode(@data[row_i][@link_id]) }">
19
19
  { @rows[row_i][element] }
20
20
  </a>
21
21
  </td>
@@ -46,4 +46,4 @@
46
46
  <div sp:if="!@rows || @rows.length < 1" class="no_result">
47
47
  _(No element)
48
48
  </div>
49
- </div>
49
+ </div>
@@ -1,7 +1,2 @@
1
1
  set test:
2
- messenger.email.backend: test
3
-
4
-
5
- apps:
6
- - portal
7
- - demografici
2
+ messenger.email.backend: test
@@ -30,10 +30,11 @@ module Spider
30
30
  :default => Proc.new{ Spider.config.get('runmode') == 'devel' ? true : false }
31
31
  config_option 'webserver.port', _("Port to use for the http server"), :type => Fixnum, :default => 8080
32
32
  config_option 'webserver.force_threads', _("Force threading on non-threaded adapters"), :type => Spider::DataTypes::Bool,
33
- :default => Proc.new{ Spider.runmode != 'test' && RUBY_VERSION_PARTS[1] == '8' && !Object.const_defined?(:PhusionPassenger) ? true : false }
33
+ :default => Proc.new{ Spider.runmode != 'test' && RUBY_VERSION_PARTS[1] == '8'}
34
34
  config_option 'webserver.timeout', _("Time allowed for each request (in seconds)"), :type=> Fixnum, :default => nil
35
35
  config_option 'webserver.respawn_on_change', _("Restart the webserver when application code changes"), :type => Spider::Bool,
36
36
  :default => Proc.new{ RUBY_PLATFORM !~ /win32|mingw32/ && Spider.config.get('runmode') == 'devel' ? true : false }
37
+ config_option 'process.shutdown_timeout', _("Number of seconds a process is given to end"), :type => Fixnum, :default => 60
37
38
  config_option 'static_content.mode', _("Mode to use for serving static files"), :type => String,
38
39
  :choices => [nil, 'x-sendfile', 'x-accel-redirect', 'published'], :default => nil
39
40
  config_option 'static_content.auto_publish', _("Automatically publish content to the home's public folder"),
@@ -77,8 +77,9 @@ module Spider; module HTTP
77
77
  controller_request.action = path
78
78
  controller_request.request_time = DateTime.now
79
79
 
80
+ w = nil
80
81
  controller_response = Spider::Response.new
81
- if (Spider.conf.get('webserver.force_threads'))
82
+ if Spider.conf.get('webserver.force_threads')
82
83
  r, w = IO.pipe
83
84
  rack_response_hash = {:body => r}
84
85
  controller_response.server_output = RackIO.new(rack_response_hash, controller_response, w)
@@ -89,6 +90,7 @@ module Spider; module HTTP
89
90
  end
90
91
 
91
92
 
93
+ controller = nil
92
94
  controller_done = false
93
95
 
94
96
  run_block = lambda do
@@ -97,39 +99,59 @@ module Spider; module HTTP
97
99
  controller.extend(Spider::FirstResponder)
98
100
  controller.before(path)
99
101
  controller.execute(path)
102
+ if Spider.conf.get('webserver.force_threads')
103
+ w.close
104
+ controller_response.server_output.send_headers unless controller_response.server_output.headers_sent?
105
+ end
100
106
  controller.after(path)
107
+ controller_done = true
101
108
  Spider::Logger.debug("Controller done")
102
109
  rescue => exc
103
110
  Spider.logger.debug("Error:")
104
111
  Spider.logger.debug(exc)
105
- controller.ensure() if controller
112
+ controller.ensure if controller
113
+ controller = nil
106
114
  ensure
107
- if (Spider.conf.get('webserver.force_threads'))
108
- controller_response.server_output.send_headers unless controller_response.server_output.headers_sent?
109
- else
110
- controller_response.prepare_headers
111
- rack_response_hash[:status] = controller_response.status
112
- rack_response_hash[:headers] = {}
113
- controller_response.headers.each do |key, val|
114
- if (val.is_a?(Array))
115
- val.each{ |v| rack_response_hash[:headers][key] = v.to_s }
116
- else
117
- rack_response_hash[:headers][key] = val.to_s
115
+ begin
116
+ if Spider.conf.get('webserver.force_threads')
117
+ controller_response.server_output.send_headers unless controller_response.server_output.headers_sent?
118
+ else
119
+ controller_response.prepare_headers
120
+ rack_response_hash[:status] = controller_response.status
121
+ rack_response_hash[:headers] = {}
122
+ controller_response.headers.each do |key, val|
123
+ if (val.is_a?(Array))
124
+ val.each{ |v| rack_response_hash[:headers][key] = v.to_s }
125
+ else
126
+ rack_response_hash[:headers][key] = val.to_s
127
+ end
118
128
  end
129
+ w.rewind
130
+ end
131
+ Spider.request_finished
132
+ ensure
133
+ if Spider.conf.get('webserver.force_threads')
134
+ begin
135
+ w.close
136
+ rescue
137
+ end
138
+ Spider.remove_thread(Thread.current)
139
+ Thread.exit
119
140
  end
120
- w.rewind
121
141
  end
122
- controller_done = true
123
- Spider.request_finished
124
142
  end
125
143
  end
126
144
 
127
- if (Spider.conf.get('webserver.force_threads'))
145
+ if Spider.conf.get('webserver.force_threads')
128
146
  controllerThread = Thread.start &run_block
129
- while (!controller_done && !controller_response.server_output.headers_sent?)
147
+ t = Time.now
148
+ while !controller_done && !controller_response.server_output.headers_sent? && (Time.now - t) < 60
130
149
  Thread.stop
131
150
  end
132
- controllerThread.join
151
+ if (Time.now - t) >= 60
152
+ controllerThread.kill
153
+ end
154
+ Spider.add_thread(controllerThread) unless controller_done
133
155
  else
134
156
  run_block.call
135
157
  end
@@ -20,14 +20,18 @@ module Spider; module I18n
20
20
  time_format = nil
21
21
  date_format = nil
22
22
  format_string = nil
23
+ calendar = options[:calendar].to_sym
23
24
  if (object.respond_to?(:sec) && !options[:no_time])
24
- time_format = @cldr.calendar.timeformats[options[:calendar].to_sym][format.to_s].dup
25
+ time_format = @cldr.calendar.timeformats[calendar][format.to_s].dup
25
26
  end
26
27
  if (object.is_a?(Date))
27
- date_format = @cldr.calendar.dateformats[options[:calendar].to_sym][format.to_s].dup
28
+ date_format = @cldr.calendar.dateformats[calendar][format.to_s].dup
28
29
  end
29
30
  if (date_format && time_format)
30
- dt_f = @cldr.calendar.datetimeformats[options[:calendar].to_sym][format.to_s]
31
+ # in CLDR 1.x, datetimeformats is an hash of strings indexed by strings;
32
+ # in CLDR 2.x, it is a hash of hashes indexed by symbols
33
+ fts = @cldr.calendar.datetimeformats[calendar] || @cldr.calendar.datetimeformats[calendar.to_s]
34
+ dt_f = fts.is_a?(String) ? fts : fts[format.to_s]
31
35
  format_string = dt_f.sub('{1}', date_format).sub('{0}', time_format)
32
36
  else
33
37
  format_string = date_format ? date_format : time_format
@@ -137,17 +141,36 @@ module Spider; module I18n
137
141
 
138
142
  def week_start(calendar = self.default_calendar)
139
143
  wdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
140
- wdays.index @cldr.calendar.week_firstdays[calendar.to_s]
144
+ day = if @cldr.respond_to?(:supplemental)
145
+ @cldr.supplemental.week_data["firstDay"]
146
+ elsif @cldr.calendar.respond_to?(:week_firstdays) # CLDR 1
147
+ @cldr.calendar.week_firstdays[calendar.to_s]
148
+ end
149
+ day ||= 'mon'
150
+ wdays.index day
151
+
141
152
  end
142
153
 
143
154
  def weekend_start(calendar = self.default_calendar)
144
155
  wdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
145
- wdays.index @cldr.calendar.weekend_starts[calendar.to_s]
156
+ day = if @cldr.respond_to?(:supplemental)
157
+ @cldr.supplemental.week_data["weekendStart"]
158
+ elsif @cldr.calendar.respond_to?(:weekend_starts) # CLDR 1
159
+ @cldr.calendar.weekend_starts[calendar.to_s]
160
+ end
161
+ day ||= 'sat'
162
+ wdays.index day
146
163
  end
147
164
 
148
165
  def weekend_end(calendar = self.default_calendar)
149
166
  wdays = ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
150
- wdays.index @cldr.calendar.weekend_ends[calendar.to_s]
167
+ day = if @cldr.respond_to?(:supplemental)
168
+ @cldr.supplemental.week_data["weekendEnd"]
169
+ elsif @cldr.calendar.respond_to?(:weekend_ends) # CLDR 1
170
+ @cldr.calendar.weekend_ends[calendar.to_s]
171
+ end
172
+ day ||= 'sun'
173
+ wdays.index day
151
174
  end
152
175
 
153
176
  def localize_number(object, precision=nil, options={})
@@ -195,4 +218,4 @@ module Spider; module I18n
195
218
 
196
219
  end
197
220
 
198
- end; end
221
+ end; end
@@ -62,8 +62,8 @@ module Spider
62
62
 
63
63
  def self.get_apps(apps, options={})
64
64
  specs = resolve(apps, options)
65
- manager = self.new(options)
66
- manager.install(specs)
65
+ manager = self.new
66
+ manager.install(specs, options)
67
67
  return specs
68
68
  end
69
69
 
@@ -181,9 +181,11 @@ module Spider
181
181
  tmp_path = File.join(self.tmp_path, "update-#{DateTime.now.strftime('%Y%m%d-%H%M')}")
182
182
  @backup_path = tmp_path
183
183
  FileUtils.mkdir_p(tmp_path)
184
+ @previous_apps = {}
184
185
  specs.each do |spec|
185
186
  app_path = File.join(@home_path, 'apps', spec.id)
186
187
  FileUtils.cp_r(app_path, tmp_path)
188
+ @previous_apps[spec.app_id] = App::AppSpec.load(File.join(app_path, "#{spec.id}.appspec"))
187
189
  end
188
190
  end
189
191
 
@@ -193,7 +195,7 @@ module Spider
193
195
  Spider.init_base
194
196
  @done_tasks = {}
195
197
  specs.each do |spec|
196
- prev_spec = Spider.home.apps[spec.app_id][:spec]
198
+ prev_spec = @previous_apps[spec.app_id]
197
199
  prev_v = prev_spec.version if prev_spec
198
200
  @done_tasks[spec.app_id] = setup(spec.app_id, prev_v, spec.version)
199
201
  end
@@ -8,6 +8,7 @@ require 'spiderfw/autoload'
8
8
  require 'spiderfw/requires'
9
9
 
10
10
  require 'spiderfw/version'
11
+ require 'timeout'
11
12
 
12
13
  begin
13
14
  require 'fssm'
@@ -218,6 +219,23 @@ module Spider
218
219
  end
219
220
  @shutdown_done = true
220
221
  Spider.logger.debug("Shutdown")
222
+ if @running_threads
223
+ begin
224
+ Timeout.timeout(Spider.conf.get('process.shutdown_timeout')) do
225
+ @running_threads.each do |thr|
226
+ thr.join if thr.alive?
227
+ end
228
+ end
229
+ rescue => exc
230
+ Spider.logger.error(exc)
231
+ @running_threads.each do |thr|
232
+ begin
233
+ thr.kill
234
+ rescue => exc
235
+ end
236
+ end
237
+ end
238
+ end
221
239
  Debugger.post_mortem = false if Object.const_defined?(:Debugger) && Debugger.post_mortem?
222
240
  @apps.each do |name, mod|
223
241
  mod.app_shutdown if mod.respond_to?(:app_shutdown)
@@ -230,6 +248,20 @@ module Spider
230
248
  def shutdown!
231
249
  shutdown(true)
232
250
  end
251
+
252
+ def add_thread(thr)
253
+ @running_threads ||= []
254
+ @threads_mutex ||= Mutex.new
255
+ @threads_mutex.synchronize do
256
+ @running_threads << thr
257
+ end
258
+ end
259
+
260
+ def remove_thread(thr)
261
+ @threads_mutex.synchronize do
262
+ @running_threads.delete(thr)
263
+ end
264
+ end
233
265
 
234
266
  def main_process_shutdown
235
267
  if startup_done?
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: spiderfw
3
3
  version: !ruby/object:Gem::Version
4
- hash: 37
4
+ hash: 35
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 6
9
- - 17
10
- version: 0.6.17
9
+ - 18
10
+ version: 0.6.18
11
11
  platform: ruby
12
12
  authors:
13
13
  - Ivan Pirlik
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-13 00:00:00 +02:00
18
+ date: 2011-09-16 00:00:00 +02:00
19
19
  default_executable: spider
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency