hayabusa 0.0.4 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.0.4
1
+ 0.0.5
data/hayabusa.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{hayabusa}
8
- s.version = "0.0.4"
8
+ s.version = "0.0.5"
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-08-19}
12
+ s.date = %q{2012-08-22}
13
13
  s.description = %q{A threadded web/app-server that focuses on threadding, shared ressources, speed and more.}
14
14
  s.email = %q{k@spernj.org}
15
15
  s.executables = ["check_running.rb", "hayabusa_benchmark.rb", "hayabusa_cgi.rb", "hayabusa_fcgi.fcgi", "hayabusa_fcgi.rb", "knjappserver_start.rb"]
data/lib/hayabusa.rb CHANGED
@@ -34,7 +34,8 @@ class Hayabusa
34
34
  :default_filetype => "text/html",
35
35
  :max_requests_working => 20,
36
36
  :size_send => 1024,
37
- :cleaner_timeout => 300
37
+ :cleaner_timeout => 300,
38
+ :mailing_time => 30
38
39
  }.merge(config)
39
40
 
40
41
  @config[:smtp_args] = {"smtp_host" => "localhost", "smtp_port" => 25} if !@config[:smtp_args]
@@ -422,14 +423,17 @@ class Hayabusa
422
423
 
423
424
  #This should be done first to be sure it finishes (else we have a serious bug).
424
425
  self.log_puts "Flush out loaded sessions." if @debug
425
- self.sessions_flush
426
+
427
+ #Flush sessions and mails (only if the modules are loaded).
428
+ self.sessions_flush if self.respond_to?(:sessions_flush)
429
+ self.mail_flush if self.respond_to?(:mail_flush)
426
430
 
427
431
  self.log_puts "Stopping done..." if @debug
428
432
  }
429
433
 
430
434
  #If we cant get a paused-execution in 5 secs - we just force the stop.
431
435
  begin
432
- Timeout.timeout(5) do
436
+ Timeout.timeout(7) do
433
437
  self.paused_exec(&proc_stop)
434
438
  end
435
439
  rescue Timeout::Error, SystemExit, Interrupt
@@ -5,12 +5,11 @@ class Hayabusa
5
5
 
6
6
  def initialize_mailing
7
7
  require "knj/autoload/ping"
8
- require "monitor"
9
8
 
10
9
  @mails_waiting = []
11
10
  @mails_mutex = Monitor.new
12
11
  @mails_queue_mutex = Monitor.new
13
- @mails_timeout = self.timeout(:time => 30, &self.method(:mail_flush))
12
+ @mails_timeout = self.timeout(:time => @config[:mailing_time], &self.method(:mail_flush))
14
13
  end
15
14
 
16
15
  #Queue a mail for sending. Possible keys are: :subject, :from, :to, :text and :html.
@@ -31,7 +30,13 @@ class Hayabusa
31
30
  mailobj = Hayabusa::Mail.new({:hb => self, :errors => {}, :status => :waiting}.merge(mail_args))
32
31
  STDOUT.print "Added mail '#{mailobj.__id__}' to the mail-send-queue.\n" if debug
33
32
  @mails_waiting << mailobj
34
- self.mail_flush if mail_args[:now]
33
+
34
+ #Try to send right away and raise error instantly if something happens if told to do so.
35
+ if mail_args[:now] or @config[:mailing_instant]
36
+ self.mail_flush
37
+ raise mailobj.args[:error] if mailobj.args[:error]
38
+ end
39
+
35
40
  return mailobj
36
41
  end
37
42
  end
@@ -53,11 +58,9 @@ class Hayabusa
53
58
  return false #Dont run if we dont have a connection to the internet and then properly dont have a connection to the SMTP as well.
54
59
  end
55
60
 
56
- begin
57
- #Use subprocessing to avoid the mail-framework (activesupport and so on, also possible memory leaks in those large frameworks).
58
- STDOUT.print "Starting subprocess for mailing.\n" if @debug
59
- require "knj/process_meta"
60
- subproc = Knj::Process_meta.new("debug" => @debug, "debug_err" => true, "id" => "hayabusa_mailing")
61
+ #Use subprocessing to avoid the mail-framework (activesupport and so on, also possible memory leaks in those large frameworks).
62
+ STDOUT.print "Starting subprocess for mailing.\n" if @debug
63
+ Knj::Process_meta.new("debug" => @debug, "debug_err" => true, "id" => "hayabusa_mailing") do |subproc|
61
64
  subproc.static("Object", "require", "rubygems")
62
65
  subproc.static("Object", "require", "mail")
63
66
  subproc.static("Object", "require", "#{@config[:knjrbfw_path]}knjrbfw")
@@ -80,9 +83,6 @@ class Hayabusa
80
83
 
81
84
  sleep 1 #sleep so we dont take up too much bandwidth.
82
85
  end
83
- ensure
84
- subproc.destroy if subproc
85
- subproc = nil
86
86
  end
87
87
 
88
88
  return nil
@@ -91,12 +91,23 @@ class Hayabusa
91
91
 
92
92
  #This class represents the queued mails.
93
93
  class Mail
94
+ attr_reader :args
95
+
94
96
  def initialize(args)
95
97
  @args = args
96
98
 
97
99
  raise "No hayabusa-object was given (as :hb)." if !@args[:hb].is_a?(Hayabusa)
98
100
  raise "No :to was given." if !@args[:to]
99
101
  raise "No content was given (:html or :text)." if !@args[:html] and !@args[:text]
102
+
103
+ #Test from-argument.
104
+ if !@args[:from].to_s.strip.empty?
105
+ #Its ok.
106
+ elsif !@args[:hb].config[:error_report_from].to_s.strip.empty?
107
+ @args[:from] = @args[:hb].config[:error_report_from]
108
+ else
109
+ raise "Dont know where to take the 'from'-paramter from - none given in appserver config or mail-method-arguments?"
110
+ end
100
111
  end
101
112
 
102
113
  #Returns a key from the arguments.
@@ -108,14 +119,6 @@ class Hayabusa
108
119
  def send(args = {})
109
120
  STDOUT.print "Sending mail '#{__id__}'.\n" if @args[:hb].debug
110
121
 
111
- if @args[:from]
112
- from = @args[:from]
113
- elsif @args[:hb].config[:error_report_from]
114
- from = @args[:hb].config[:error_report_from]
115
- else
116
- raise "Dont know where to take the 'from'-paramter from - none given in appserver config or mail-method-arguments?"
117
- end
118
-
119
122
  if args["proc"]
120
123
  args["proc"].static("Object", "require", "knj/mailobj")
121
124
  mail = args["proc"].new("Knj::Mailobj", @args[:hb].config[:smtp_args])
@@ -123,16 +126,15 @@ class Hayabusa
123
126
  mail._pm_send_noret("subject=", @args[:subject]) if @args[:subject]
124
127
  mail._pm_send_noret("html=", Knj::Strings.email_str_safe(@args[:html])) if @args[:html]
125
128
  mail._pm_send_noret("text=", Knj::Strings.email_str_safe(@args[:text])) if @args[:text]
126
- mail._pm_send_noret("from=", from)
129
+ mail._pm_send_noret("from=", @args[:from])
127
130
  mail._pm_send_noret("send")
128
131
  else
129
- require "knj/mailobj"
130
132
  mail = Knj::Mailobj.new(@args[:hb].config[:smtp_args])
131
133
  mail.to = @args[:to]
132
134
  mail.subject = @args[:subject] if @args[:subject]
133
135
  mail.html = Knj::Strings.email_str_safe(@args[:html]) if @args[:html]
134
136
  mail.text = Knj::Strings.email_str_safe(@args[:text]) if @args[:text]
135
- mail.from = from
137
+ mail.from = @args[:from]
136
138
  mail.send
137
139
  end
138
140
 
data/lib/hayabusa_fcgi.rb CHANGED
@@ -31,6 +31,8 @@ class Hayabusa::Fcgi
31
31
  hayabusa_conf = Hayabusa::FCGI_CONF[:hayabusa]
32
32
  hayabusa_conf.merge!(
33
33
  :cmdline => false,
34
+ :mailing_timeout => 1,
35
+ :mailing_instant => true,
34
36
  :port => 0 #Ruby picks random port and we get the actual port after starting the appserver.
35
37
  )
36
38
 
@@ -84,49 +86,54 @@ class Hayabusa::Fcgi
84
86
 
85
87
  def fcgi_loop
86
88
  $stderr.puts "[hayabusa] Starting FCGI." if @debug
87
- FCGI.each_cgi do |cgi|
88
- begin
89
- #cgi.print "Content-Type: text/html\r\n"
90
- #cgi.print "\r\n"
91
-
92
- #Set 'cgi'-variable for CGI-tools.
93
- @cgi_tools.cgi = cgi
94
- @cgi = cgi
95
-
96
- #Evaluate the mode of this instance.
97
- self.evaluate_mode
98
-
99
- #Ensure the same FCGI-process isnt active for more than one website.
100
- raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{@hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if @hayabusa_fcgi_conf_path and @hayabusa_fcgi_conf_path != cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
101
-
102
- if @fcgi_proxy
103
- #Proxy request to the host-FCGI-process.
104
- $stderr.puts "[hayabusa] Proxying request." if @debug
105
- begin
106
- @cgi_tools.proxy_request_to(:cgi => cgi, :http => @fcgi_proxy[:http], :fp_log => @fcgi_proxy[:fp_log])
107
- rescue Errno::ECONNABORTED
108
- @fcgi_proxy = nil #Force re-evaluate if this process should be host or proxy.
109
- raise
89
+
90
+ begin
91
+ FCGI.each_cgi do |cgi|
92
+ begin
93
+ #cgi.print "Content-Type: text/html\r\n"
94
+ #cgi.print "\r\n"
95
+
96
+ #Set 'cgi'-variable for CGI-tools.
97
+ @cgi_tools.cgi = cgi
98
+ @cgi = cgi
99
+
100
+ #Evaluate the mode of this instance.
101
+ self.evaluate_mode
102
+
103
+ #Ensure the same FCGI-process isnt active for more than one website.
104
+ raise "Expected 'HTTP_HAYABUSA_FCGI_CONFIG' to be '#{@hayabusa_fcgi_conf_path}' but it wasnt: '#{cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]}'." if @hayabusa_fcgi_conf_path and @hayabusa_fcgi_conf_path != cgi.env_table["HTTP_HAYABUSA_FCGI_CONFIG"]
105
+
106
+ if @fcgi_proxy
107
+ #Proxy request to the host-FCGI-process.
108
+ $stderr.puts "[hayabusa] Proxying request." if @debug
109
+ begin
110
+ @cgi_tools.proxy_request_to(:cgi => cgi, :http => @fcgi_proxy[:http], :fp_log => @fcgi_proxy[:fp_log])
111
+ rescue Errno::ECONNABORTED
112
+ @fcgi_proxy = nil #Force re-evaluate if this process should be host or proxy.
113
+ raise
114
+ end
115
+ else
116
+ self.handle_fcgi_request(:cgi => cgi)
110
117
  end
111
- else
112
- self.handle_fcgi_request(:cgi => cgi)
113
- end
114
- rescue Exception => e
115
- cgi.print "Content-Type: text/html\r\n"
116
- cgi.print "\r\n"
117
- cgi.print Knj::Errors.error_str(e, :html => true)
118
-
119
- if @hayabusa
120
- @hayabusa.log_puts e.inspect
121
- @hayabusa.log_puts e.backtrace
122
- else
123
- STDERR.puts e.inspect
124
- STDERR.puts e.backtrace
118
+ rescue Exception => e
119
+ cgi.print "Content-Type: text/html\r\n"
120
+ cgi.print "\r\n"
121
+ cgi.print Knj::Errors.error_str(e, :html => true)
122
+
123
+ if @hayabusa
124
+ @hayabusa.log_puts e.inspect
125
+ @hayabusa.log_puts e.backtrace
126
+ else
127
+ STDERR.puts e.inspect
128
+ STDERR.puts e.backtrace
129
+ end
130
+ ensure
131
+ @cgi = nil
132
+ @cgi_tools.cgi = nil
125
133
  end
126
- ensure
127
- @cgi = nil
128
- @cgi_tools.cgi = nil
129
134
  end
135
+ ensure
136
+ @hayabusa.stop if @hayabusa
130
137
  end
131
138
  end
132
139
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: hayabusa
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.4
5
+ version: 0.0.5
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-08-19 00:00:00 +02:00
13
+ date: 2012-08-22 00:00:00 +02:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -249,7 +249,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
249
249
  requirements:
250
250
  - - ">="
251
251
  - !ruby/object:Gem::Version
252
- hash: -4467639254146667780
252
+ hash: -1836290877562781605
253
253
  segments:
254
254
  - 0
255
255
  version: "0"