knjappserver 0.0.23 → 0.0.24

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.23
1
+ 0.0.24
data/knjappserver.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{knjappserver}
8
- s.version = "0.0.23"
8
+ s.version = "0.0.24"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kasper Johansen"]
12
- s.date = %q{2012-05-22}
12
+ s.date = %q{2012-06-10}
13
13
  s.description = %q{Which supports a lot of undocumented stuff.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.executables = ["check_running.rb", "knjappserver_start.rb"]
@@ -42,39 +42,12 @@ class Knjappserver::Httpserver
42
42
  STDOUT.print Knj::Errors.error_str(e)
43
43
  end
44
44
  end
45
-
46
- @thread_restart = Thread.new do
47
- begin
48
- loop do
49
- sleep 10
50
- break if @kas.should_restart and @kas.should_restart_done
51
-
52
- if !@kas.should_restart and (!@server or @server.closed?)
53
- STDOUT.print "Socket does not exist or is closed - restarting HTTP-server!\n"
54
- @server = TCPServer.new(@kas.config[:host], @kas.config[:port])
55
- STDOUT.print "Done.\n"
56
- end
57
- end
58
- rescue => e
59
- if @kas
60
- @kas.handle_error(e)
61
- else
62
- STDOUT.print Knj::Errors.error_str(e)
63
- end
64
- end
65
- end
66
45
  end
67
46
 
68
47
  def stop
69
- begin
70
- STDOUT.print "Stopping accept-thread.\n" if @debug
71
- @thread_accept.kill if @thread_accept and @thread_accept.alive?
72
- @thread_restart.kill if @thread_restart and @thread_restart.alive?
73
- rescue => e
74
- STDOUT.print "Could not stop threads.\n" if @debug
75
- STDOUT.puts e.inspect
76
- STDOUT.puts e.backtrace
77
- end
48
+ STDOUT.print "Stopping accept-thread.\n" if @debug
49
+ @thread_accept.kill if @thread_accept and @thread_accept.alive?
50
+ @thread_restart.kill if @thread_restart and @thread_restart.alive?
78
51
 
79
52
  STDOUT.print "Stopping all HTTP sessions.\n" if @debug
80
53
  if @http_sessions
@@ -1,14 +1,13 @@
1
+ #This class handels the HTTP-sessions.
1
2
  class Knjappserver::Httpsession
2
3
  attr_accessor :data, :alert_sent
3
4
  attr_reader :cookie, :get, :session, :session_id, :session_hash, :kas, :active, :out, :eruby, :browser, :debug, :resp, :page_path, :post, :cgroup, :meta, :httpsession_var, :handler, :working
4
5
 
5
- dir = File.dirname(__FILE__)
6
-
7
- autoload :Contentgroup, "#{dir}/class_httpsession_contentgroup.rb"
8
- autoload :Http_request, "#{dir}/class_httpsession_http_request.rb"
9
- autoload :Http_response, "#{dir}/class_httpsession_http_response.rb"
10
- autoload :Page_environment, "#{dir}/class_httpsession_page_environment.rb"
11
- autoload :Post_multipart, "#{dir}/class_httpsession_post_multipart.rb"
6
+ #Autoloader for subclasses.
7
+ def self.const_missing(name)
8
+ require "#{File.dirname(__FILE__)}/class_httpsession_#{name.to_s.downcase}.rb"
9
+ return Knjappserver::Httpsession.const_get(name.to_s.to_sym)
10
+ end
12
11
 
13
12
  def initialize(httpserver, socket)
14
13
  @data = {}
@@ -2,10 +2,11 @@ class Knjappserver
2
2
  attr_reader :cio, :config, :httpserv, :debug, :db, :db_handler, :ob, :translations, :paused, :should_restart, :events, :mod_event, :db_handler, :gettext, :sessions, :logs_access_pending, :threadpool, :vars, :magic_procs, :magic_vars, :types, :eruby_cache, :httpsessions_ids
3
3
  attr_accessor :served, :should_restart, :should_restart_done
4
4
 
5
- appsrv_dir = File.dirname(__FILE__)
6
- autoload :ERBHandler, "#{appsrv_dir}/class_erbhandler"
7
- autoload :Log, "#{appsrv_dir}/class_log.rb"
8
- autoload :Log_link, "#{appsrv_dir}/class_log_link.rb"
5
+ #Autoloader for subclasses.
6
+ def self.const_missing(name)
7
+ require "#{File.dirname(__FILE__)}/class_#{name.to_s.downcase}.rb"
8
+ return Knjappserver.const_get(name)
9
+ end
9
10
 
10
11
  def initialize(config)
11
12
  raise "No arguments given." if !config.is_a?(Hash)
@@ -374,13 +375,17 @@ class Knjappserver
374
375
  rescue Interrupt => e
375
376
  STDOUT.print "Got interrupt - trying to stop appserver.\n" if @debug
376
377
  self.stop
378
+ raise e
377
379
  end
378
380
  end
379
381
 
380
382
  #Stops the entire app and releases join.
381
383
  def stop
384
+ return nil if @stop_called
385
+ @stop_called = true
386
+
382
387
  proc_stop = proc{
383
- STDOUT.print "Stopping appserver for real.\n" if @debug
388
+ STDOUT.print "Stopping appserver.\n" if @debug
384
389
  @httpserv.stop if @httpserv and @httpserv.respond_to?(:stop)
385
390
 
386
391
  STDOUT.print "Stopping threadpool.\n" if @debug
@@ -389,6 +394,8 @@ class Knjappserver
389
394
  #This should be done first to be sure it finishes (else we have a serious bug).
390
395
  STDOUT.print "Flush out loaded sessions.\n" if @debug
391
396
  self.sessions_flush
397
+
398
+ STDOUT.print "Stopping done...\n" if @debug
392
399
  }
393
400
 
394
401
  #If we cant get a paused-execution in 5 secs - we just force the stop.
@@ -453,7 +460,7 @@ class Knjappserver
453
460
  begin
454
461
  @httpserv.thread_accept.join
455
462
  @httpserv.thread_restart.join if @httpserv and @httpserv.thread_restart
456
- rescue Interrupt
463
+ rescue Interrupt => e
457
464
  self.stop
458
465
  end
459
466
 
@@ -79,7 +79,7 @@ class Knjappserver
79
79
  @should_restart_done = true
80
80
  print exec(mycmd)
81
81
  exit
82
- rescue Exception => e
82
+ rescue => e
83
83
  STDOUT.puts e.inspect
84
84
  STDOUT.puts e.backtrace
85
85
  end
@@ -4,27 +4,26 @@ class Knjappserver
4
4
 
5
5
  Thread.new do
6
6
  begin
7
- line = $stdin.gets
8
- next if line == "\n"
9
-
10
- called = 0
11
- @cmds.each do |key, connects|
12
- data = {}
13
-
14
- if key.is_a?(Regexp)
15
- if line.match(key)
16
- connects.each do |conn|
17
- called += 1
18
- conn[:block].call(data)
7
+ $stdin.each_line do |line|
8
+ called = 0
9
+ @cmds.each do |key, connects|
10
+ data = {}
11
+
12
+ if key.is_a?(Regexp)
13
+ if line.match(key)
14
+ connects.each do |conn|
15
+ called += 1
16
+ conn[:block].call(data)
17
+ end
19
18
  end
19
+ else
20
+ raise "Unknown class for 'cmd_connect': '#{key.class.name}'."
20
21
  end
21
- else
22
- raise "Unknown class for 'cmd_connect': '#{key.class.name}'."
23
22
  end
24
- end
25
-
26
- if called == 0
27
- print "Unknown command: '#{line.strip}'.\n"
23
+
24
+ if called == 0
25
+ print "Unknown command: '#{line.strip}'.\n"
26
+ end
28
27
  end
29
28
  rescue => e
30
29
  self.handle_error(e)
@@ -8,7 +8,8 @@ class Knjappserver
8
8
  @mails_waiting = []
9
9
  @mails_mutex = Monitor.new
10
10
  @mails_queue_mutex = Monitor.new
11
- @mails_timeout = self.timeout(:time => 10) do
11
+ @mails_timeout = self.timeout(:time => 30) do
12
+ STDOUT.print "Flushing mails.\n" if @debug
12
13
  self.mail_flush
13
14
  end
14
15
  end
@@ -30,8 +31,8 @@ class Knjappserver
30
31
 
31
32
  mailobj = Knjappserver::Mail.new({:kas => self, :errors => {}, :status => :waiting}.merge(mail_args))
32
33
  STDOUT.print "Added mail '#{mailobj.__id__}' to the mail-send-queue.\n" if debug
33
- @mails_waiting << mailobj if mail_args[:now]
34
- self.mail_flush
34
+ @mails_waiting << mailobj
35
+ self.mail_flush if mail_args[:now]
35
36
  return mailobj
36
37
  end
37
38
  end
@@ -39,8 +40,12 @@ class Knjappserver
39
40
  #Sends all queued mails to the respective servers, if we are online.
40
41
  def mail_flush
41
42
  @mails_mutex.synchronize do
42
- return false if @mails_waiting.length <= 0
43
+ if @mails_waiting.length <= 0
44
+ STDOUT.print "No mails to flush - skipping.\n" if @debug
45
+ return false
46
+ end
43
47
 
48
+ STDOUT.print "Trying to ping Google to figure out if we are online...\n" if @debug
44
49
  status = Ping.pingecho("google.dk", 10, 80)
45
50
  if !status
46
51
  STDOUT.print "We are not online - skipping mail flush.\n"
@@ -49,6 +54,7 @@ class Knjappserver
49
54
 
50
55
  begin
51
56
  #Use subprocessing to avoid the mail-framework (activesupport and so on, also possible memory leaks in those large frameworks).
57
+ STDOUT.print "Starting subprocess for mailing.\n" if @debug
52
58
  require "knj/process_meta"
53
59
  subproc = Knj::Process_meta.new("debug" => @debug, "debug_err" => true, "id" => "knjappserver_mailing")
54
60
  subproc.static("Object", "require", "rubygems")
@@ -130,7 +136,7 @@ class Knjappserver
130
136
  @args[:status] = :sent
131
137
  STDOUT.print "Sent email #{self.__id__}\n" if @args[:kas].debug
132
138
  return true
133
- rescue Exception => e
139
+ rescue => e
134
140
  if @args[:kas].debug
135
141
  STDOUT.print "Could not send email.\n"
136
142
  STDOUT.puts e.inspect
@@ -39,13 +39,18 @@ class Knjappserver
39
39
  begin
40
40
  thread_obj.args[:running] = true
41
41
  yield(*args[:args])
42
- rescue Exception => e
43
- handle_error(e)
42
+ rescue => e
43
+ self.handle_error(e)
44
44
  thread_obj.args[:error] = true
45
45
  thread_obj.args[:error_obj] = e
46
46
  ensure
47
+ STDOUT.print "Free thread ob-db.\n" if @debug
47
48
  @ob.db.free_thread if @ob.db.opts[:threadsafe]
49
+
50
+ STDOUT.print "Free thread db-handler.\n" if @debug
48
51
  @db_handler.free_thread if @db_handler.opts[:threadsafe]
52
+
53
+ STDOUT.print "Set args on thread.\n" if @debug
49
54
  thread_obj.args[:running] = false
50
55
  thread_obj.args[:done] = true
51
56
  end
@@ -64,7 +64,7 @@ class Knjappserver::Threadding_timeout
64
64
  end
65
65
  end
66
66
  end
67
- rescue Exception => e
67
+ rescue => e
68
68
  @kas.handle_error(e)
69
69
  end
70
70
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: knjappserver
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.23
5
+ version: 0.0.24
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kasper Johansen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-05-22 00:00:00 +02:00
13
+ date: 2012-06-10 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -208,7 +208,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
208
208
  requirements:
209
209
  - - ">="
210
210
  - !ruby/object:Gem::Version
211
- hash: -4394912517920739657
211
+ hash: -2439640920706539794
212
212
  segments:
213
213
  - 0
214
214
  version: "0"