From kato-k at rubyforge.org Mon Dec 10 04:33:01 2007 From: kato-k at rubyforge.org (kato-k at rubyforge.org) Date: Mon, 10 Dec 2007 04:33:01 -0500 (EST) Subject: [ap4r-devel] [355] trunk/ap4r/History.txt: Fixed: a extra line break for correct rdoc. Message-ID: <20071210093301.4DF6B159806D@rubyforge.org> Revision: 355 Author: kato-k Date: 2007-12-10 04:33:00 -0500 (Mon, 10 Dec 2007) Log Message: ----------- Fixed: a extra line break for correct rdoc. Modified Paths: -------------- trunk/ap4r/History.txt Modified: trunk/ap4r/History.txt =================================================================== --- trunk/ap4r/History.txt 2007-11-29 11:03:19 UTC (rev 354) +++ trunk/ap4r/History.txt 2007-12-10 09:33:00 UTC (rev 355) @@ -1,8 +1,7 @@ == 0.3.x === 0.3.5 (November 29, 2007) -* Fixed: bug that SAF transaction is NOT guaranteed when some models are created/updated - before using of ap4r.async_to API in ap4r.transaction block. +* Fixed: bug that SAF transaction is NOT guaranteed when some models are created/updated before using of ap4r.async_to API in ap4r.transaction block. === 0.3.4 (October 31, 2007) * Added: Support ActiveRecord as reliable RDBMS persistence. From kato-k at rubyforge.org Wed Dec 12 04:31:53 2007 From: kato-k at rubyforge.org (kato-k at rubyforge.org) Date: Wed, 12 Dec 2007 04:31:53 -0500 (EST) Subject: [ap4r-devel] [356] trunk: Supported Rails2.0 provisionally. Message-ID: <20071212093154.0D7951858614@rubyforge.org> Revision: 356 Author: kato-k Date: 2007-12-12 04:31:52 -0500 (Wed, 12 Dec 2007) Log Message: ----------- Supported Rails2.0 provisionally. Modified Paths: -------------- trunk/ap4r/lib/ap4r/retention_history.rb trunk/samples/HelloWorld/config/environment.rb Modified: trunk/ap4r/lib/ap4r/retention_history.rb =================================================================== --- trunk/ap4r/lib/ap4r/retention_history.rb 2007-12-10 09:33:00 UTC (rev 355) +++ trunk/ap4r/lib/ap4r/retention_history.rb 2007-12-12 09:31:52 UTC (rev 356) @@ -7,14 +7,16 @@ module ReliableMsg #:nodoc: # This class is too much experimental. - # The aim: for performance monitoring, records unprocessed message count + # The aim: for performance monitoring, records unprocessed message count # in every queues at some interval. class RetentionHistory include DRbUndumped - LOOP_INTERVAL = 1.seconds - SHELF_LIFE = 10.minutes -# SHELF_LIFE = 10.seconds + # to_i method is required for ActiveSupport 2.0 where return value of seconds method + # is not Fixnum. + LOOP_INTERVAL = 1.seconds.to_i + SHELF_LIFE = 10.minutes.to_i +# SHELF_LIFE = 10.seconds.to_i attr_reader :data def initialize(qm, logger, config) Modified: trunk/samples/HelloWorld/config/environment.rb =================================================================== --- trunk/samples/HelloWorld/config/environment.rb 2007-12-10 09:33:00 UTC (rev 355) +++ trunk/samples/HelloWorld/config/environment.rb 2007-12-12 09:31:52 UTC (rev 356) @@ -5,7 +5,7 @@ # ENV['RAILS_ENV'] ||= 'production' # Specifies gem version of Rails to use when vendor/rails is not present -RAILS_GEM_VERSION = '1.2.3' unless defined? RAILS_GEM_VERSION +RAILS_GEM_VERSION = '1.2.6' unless defined? RAILS_GEM_VERSION # Bootstrap the Rails environment, frameworks, and default configuration require File.join(File.dirname(__FILE__), 'boot') @@ -26,6 +26,17 @@ # (by default production uses :info, the others :debug) # config.log_level = :debug + if RAILS_GEM_VERSION.to_i == 2 + # Your secret key for verifying cookie session data integrity. + # If you change this key, all old sessions will become invalid! + # Make sure the secret is at least 30 characters and all random, + # no regular words or you'll be exposed to dictionary attacks. + config.action_controller.session = { + :session_key => '_HelloWorld_on_Rails20_session', + :secret => '842ed669f0a2139d3919f50b4044e4226810fc8eab12b23a2a3475b001b6f083985fc0083d800d19b9d908c25945e1367da329d424b3b05b0b5bd73e0a088e9a' + } + end + # Use the database for sessions instead of the file system # (create the session table with 'rake db:sessions:create') # config.action_controller.session_store = :active_record_store From kato-k at rubyforge.org Fri Dec 14 05:48:13 2007 From: kato-k at rubyforge.org (kato-k at rubyforge.org) Date: Fri, 14 Dec 2007 05:48:13 -0500 (EST) Subject: [ap4r-devel] [357] trunk/ap4r/lib/ap4r: Added: experimental implementation of RESTified messaging API. Message-ID: <20071214104813.5E66718585E7@rubyforge.org> Revision: 357 Author: kato-k Date: 2007-12-14 05:48:12 -0500 (Fri, 14 Dec 2007) Log Message: ----------- Added: experimental implementation of RESTified messaging API. Modified Paths: -------------- trunk/ap4r/lib/ap4r/mongrel.rb trunk/ap4r/lib/ap4r/mongrel_ap4r.rb Modified: trunk/ap4r/lib/ap4r/mongrel.rb =================================================================== --- trunk/ap4r/lib/ap4r/mongrel.rb 2007-12-12 09:31:52 UTC (rev 356) +++ trunk/ap4r/lib/ap4r/mongrel.rb 2007-12-14 10:48:12 UTC (rev 357) @@ -55,7 +55,7 @@ def initialize(options) # TODO: needs various modes for easy operations 2007/05/02 by shino - # e.g. not to initialize message store, not to start dispatchers, etc. + # e.g. not to initialize message store, not to start dispatchers, etc. # TODO what is "false" here? 2007/04/13 by shinohara @files = ::Mongrel::DirHandler.new(options[:docroot], false) @@ -100,5 +100,196 @@ end + # This class is an experimental implementation of RESTified message API. + # Send to queue: + # using HTTP POST + # a message is sent as HTTP body which format is depending on MIME type + # (now supported only text/plain) + # + # options are sent as HTTP header which header name is "X-AP4R" + # url consists of prefix ("/queues") and queue name + # + # + # === Request example === + # POST /queues/queue.test HTTP/1.1 + # Content-Type: text/plain + # X-AP4R: dispatch_mode=HTTP, target_method=POST, target_url=http://localhost:3000/async_shop/execute_via_http/ + # + # hoge + # + # + # === Response example === + # HTTP/1.1 200 Ok + # Date: The, 11 Dec 2007 17:17:11 GMT + # + # 7bb181f0-7ee0-012a-300a-001560abd426 + # + class Ap4rSendMessageHandler < ::Mongrel::HttpHandler + + def initialize(options) + @tick = Time.now + @queues = {} + end + + def process(request, response) + if response.socket.closed? + return + end + + queue_name = request.params[::Mongrel::Const::PATH_INFO][1..-1] + header = make_header(request.params["HTTP_X_AP4R"]) # Todo: assign as constant 2007/11/27 by kiwamu + + if "POST".include? request.params[::Mongrel::Const::REQUEST_METHOD] + begin + q = if @queues.key? queue_name + @queues[queue_name] + else + @queues[queue_name] = ::ReliableMsg::Queue.new(queue_name) + end + mid = q.put(request.body.string, header) + + response.start(200) do |head, out| + head['Content-Type'] = 'text/plain' + out.write mid + end + rescue + response.start(500) do |head, out| + head['Content-Type'] = 'text/plain' + out.write "Failed to send message. #{request.body.string}" + end + end + else + raise "HTTP method is not POST..." # Todo + end + end + + def make_header(x_ap4r_header) + header = {} + if x_ap4r_header + x_ap4r_header.split(',').map do |e| + key, value = e.strip.split('=') + if %w(dispatch_mode target_method delivery).include?(key) + header[key.to_sym] = value.to_sym + else + header[key.to_sym] = value + end + end + end + header + end + + def log_threads_waiting_for(event) + if Time.now - @tick > 10 + @tick = Time.now + end + end + + # Does the internal reload for Rails. It might work for most cases, but + # sometimes you get exceptions. In that case just do a real restart. + def reload! + begin + #TODO not implemented 2007/04/09 by shino + raise "not yet implemented!" + end + end + + end + + # This class is an experimental implementation of RESTified message API. + # Subscribe to queue: + # using HTTP POST + # a message is subscribed as HTTP body + # + # options are sent as HTTP header which header name is "X-AP4R" + # (now not supported) + # + # url consists of prefix ("/subscribes") and queue name + # + # response body is now return value of ReliableMsg#inspct + # In the future, it will be possible to assign the format by the request header X-AP4R + # + # + # === Rrequest example === + # POST /subscribes/queue.test HTTP/1.1 + # + # + # === Response example === + # HTTP/1.1 200 Ok + # Content-Type: text/plain + # Date: The, 11 Dec 2007 17:17:11 GMT + # + # #0, :created=>1197628231, :expires=>nil, :delivery=>:best_effort, :id=>\"856016b0-8c5d-012a-79f3-0016cb9ad524\", :max_deliveries=>5}, @object=\"hoge\", @id=\"856016b0-8c5d-012a-79f3-0016cb9ad524\"> + # + class Ap4rSubscribeMessageHandler < ::Mongrel::HttpHandler + + def initialize(options) + @tick = Time.now + @queues = {} + end + + def process(request, response) + if response.socket.closed? + return + end + + queue_name = request.params[::Mongrel::Const::PATH_INFO][1..-1] + # header = make_header(request.params["HTTP_X_AP4R"]) # Todo: assign as constant 2007/11/27 by kiwamu + + if "POST".include? request.params[::Mongrel::Const::REQUEST_METHOD] + begin + q = if @queues.key? queue_name + @queues[queue_name] + else + @queues[queue_name] = ::ReliableMsg::Queue.new(queue_name) + end + mes = q.get + + response.start(200) do |head, out| + head['Content-Type'] = 'text/plain' + out.write mes.inspect + end + rescue + response.start(500) do |head, out| + head['Content-Type'] = 'text/plain' + out.write "Failed to get message for #{queue_name}" + end + end + else + raise "HTTP method is not POST..." + end + end + + def make_header(x_ap4r_header) + header = {} + if x_ap4r_header + x_ap4r_header.split(',').map do |e| + key, value = e.strip.split('=') + if %w(dispatch_mode target_method delivery).include?(key) + header[key.to_sym] = value.to_sym + else + header[key.to_sym] = value + end + end + end + header + end + + def log_threads_waiting_for(event) + if Time.now - @tick > 10 + @tick = Time.now + end + end + + # Does the internal reload for Rails. It might work for most cases, but + # sometimes you get exceptions. In that case just do a real restart. + def reload! + begin + #TODO not implemented 2007/04/09 by shino + raise "not yet implemented!" + end + end + + end + end end Modified: trunk/ap4r/lib/ap4r/mongrel_ap4r.rb =================================================================== --- trunk/ap4r/lib/ap4r/mongrel_ap4r.rb 2007-12-12 09:31:52 UTC (rev 356) +++ trunk/ap4r/lib/ap4r/mongrel_ap4r.rb 2007-12-14 10:48:12 UTC (rev 357) @@ -116,6 +116,8 @@ listener do log "Starting AP4R Handler with #{defaults[:ap4r_config_file]}" uri "/", :handler => ::Ap4r::Mongrel::Ap4rHandler.new(defaults) + uri "/queues", :handler => ::Ap4r::Mongrel::Ap4rSendMessageHandler.new(defaults) + uri "/subscribes", :handler => ::Ap4r::Mongrel::Ap4rSubscribeMessageHandler.new(defaults) end setup_signals(settings) end From kato-k at rubyforge.org Tue Dec 18 05:56:15 2007 From: kato-k at rubyforge.org (kato-k at rubyforge.org) Date: Tue, 18 Dec 2007 05:56:15 -0500 (EST) Subject: [ap4r-devel] [358] trunk/ap4r/spec/local/send_message_handler_spec.rb: Added: spec for restful send message handler. Message-ID: <20071218105615.3CEDA159806F@rubyforge.org> Revision: 358 Author: kato-k Date: 2007-12-18 05:56:14 -0500 (Tue, 18 Dec 2007) Log Message: ----------- Added: spec for restful send message handler. Added Paths: ----------- trunk/ap4r/spec/local/send_message_handler_spec.rb Added: trunk/ap4r/spec/local/send_message_handler_spec.rb =================================================================== --- trunk/ap4r/spec/local/send_message_handler_spec.rb (rev 0) +++ trunk/ap4r/spec/local/send_message_handler_spec.rb 2007-12-18 10:56:14 UTC (rev 358) @@ -0,0 +1,48 @@ +require File.join(File.dirname(__FILE__), "../spec_helper") + +require "reliable-msg" +require "ap4r/mongrel" + +describe Ap4r::Mongrel::Ap4rSendMessageHandler, " on accepting a message" do + + + before(:each) do + @manager = ::ReliableMsg::QueueManager.new + @manager.start_original + + params = { + Mongrel::Const::PATH_INFO => "/queue.test", + Mongrel::Const::REQUEST_METHOD => "POST", + } + class << params + def http_body + "hoge" + end + end + + class MockSocket + def initialize;end + def closed?;false;end + end + + @handler = Ap4r::Mongrel::Ap4rSendMessageHandler.new(nil) + @request = Mongrel::HttpRequest.new(params, nil, nil) + @response = Mongrel::HttpResponse.new(MockSocket.new) + @handler.process(@request, @response) + end + + after(:each)do + @manager.stop_original + end + + it "should have one message in the queue" do + q = ReliableMsg::Queue.new "queue.test" + q.get.should_not be_nil + q.get.should be_nil + end + + it "should have the same message body as http body" do + q = ReliableMsg::Queue.new "queue.test" + q.get.object.should == "hoge" + end +end From kato-k at rubyforge.org Fri Dec 21 04:32:43 2007 From: kato-k at rubyforge.org (kato-k at rubyforge.org) Date: Fri, 21 Dec 2007 04:32:43 -0500 (EST) Subject: [ap4r-devel] [359] trunk/ap4r/spec/local: Added: tests for RESTful send / subscribe to queue. Message-ID: <20071221093243.B71DD18585D3@rubyforge.org> Revision: 359 Author: kato-k Date: 2007-12-21 04:32:42 -0500 (Fri, 21 Dec 2007) Log Message: ----------- Added: tests for RESTful send / subscribe to queue. Modified Paths: -------------- trunk/ap4r/spec/local/send_message_handler_spec.rb Added Paths: ----------- trunk/ap4r/spec/local/subscribe_message_handler_spec.rb Modified: trunk/ap4r/spec/local/send_message_handler_spec.rb =================================================================== --- trunk/ap4r/spec/local/send_message_handler_spec.rb 2007-12-18 10:56:14 UTC (rev 358) +++ trunk/ap4r/spec/local/send_message_handler_spec.rb 2007-12-21 09:32:42 UTC (rev 359) @@ -3,9 +3,54 @@ require "reliable-msg" require "ap4r/mongrel" -describe Ap4r::Mongrel::Ap4rSendMessageHandler, " on accepting a message" do +describe Ap4r::Mongrel::Ap4rSendMessageHandler, " on accepting a simple message" do + before(:each) do + @manager = ::ReliableMsg::QueueManager.new + @manager.start_original + q = ::ReliableMsg::Queue.new "queue.test" + while q.get; end + + params = { + Mongrel::Const::PATH_INFO => "/queue.test", + Mongrel::Const::REQUEST_METHOD => "POST", + } + class << params + def http_body + "hoge" + end + end + + class MockSocket + def initialize;end + def closed?;false;end + end + + @handler = Ap4r::Mongrel::Ap4rSendMessageHandler.new(nil) + @request = Mongrel::HttpRequest.new(params, nil, nil) + @response = Mongrel::HttpResponse.new(MockSocket.new) + @handler.process(@request, @response) + end + + after(:each)do + @manager.stop_original + end + + it "should have one message in the queue" do + q = ReliableMsg::Queue.new "queue.test" + q.get.should_not be_nil + q.get.should be_nil + end + + it "should have the same message body as http body" do + q = ReliableMsg::Queue.new "queue.test" + q.get.object.should == "hoge" + end +end + +describe Ap4r::Mongrel::Ap4rSendMessageHandler, " on accepting a message with options" do + before(:each) do @manager = ::ReliableMsg::QueueManager.new @manager.start_original @@ -13,6 +58,8 @@ params = { Mongrel::Const::PATH_INFO => "/queue.test", Mongrel::Const::REQUEST_METHOD => "POST", + "HTTP_X_AP4R" => "priority=1, delivery=once, dispatch_mode=HTTP, target_method=POST, " + + "target_url=http://sample.com:3000" } class << params def http_body @@ -45,4 +92,15 @@ q = ReliableMsg::Queue.new "queue.test" q.get.object.should == "hoge" end + + it "should have the same message header as http header" do + q = ReliableMsg::Queue.new "queue.test" + m = q.get + m.headers[:priority].should == 1 + m.headers[:delivery].should == :once + m.headers[:dispatch_mode].should == :HTTP + m.headers[:target_method].should == :POST + m.headers[:target_url].should == "http://sample.com:3000" + end + end Added: trunk/ap4r/spec/local/subscribe_message_handler_spec.rb =================================================================== --- trunk/ap4r/spec/local/subscribe_message_handler_spec.rb (rev 0) +++ trunk/ap4r/spec/local/subscribe_message_handler_spec.rb 2007-12-21 09:32:42 UTC (rev 359) @@ -0,0 +1,47 @@ +require File.join(File.dirname(__FILE__), "../spec_helper") + +require "reliable-msg" +require "ap4r/mongrel" + +describe Ap4r::Mongrel::Ap4rSubscribeMessageHandler, " on subscribing a simple message" do + + before(:each) do + @manager = ::ReliableMsg::QueueManager.new + @manager.start_original + + q = ::ReliableMsg::Queue.new "queue.test" + while q.get; end + q.put "hgoe" + + params = { + Mongrel::Const::PATH_INFO => "/queue.test", + Mongrel::Const::REQUEST_METHOD => "POST", + } + class << params + def http_body + "hoge" + end + end + + class MockSocket + def initialize;end + def closed?;false;end + end + + @handler = Ap4r::Mongrel::Ap4rSubscribeMessageHandler.new(nil) + @request = Mongrel::HttpRequest.new(params, nil, nil) + @response = Mongrel::HttpResponse.new(MockSocket.new) + @handler.process(@request, @response) + end + + after(:each)do + @manager.stop_original + end + + it "should have no message in the queue" do + q = ReliableMsg::Queue.new "queue.test" + q.get.should be_nil + end + +end + From shino at rubyforge.org Tue Dec 25 20:36:07 2007 From: shino at rubyforge.org (shino at rubyforge.org) Date: Tue, 25 Dec 2007 20:36:07 -0500 (EST) Subject: [ap4r-devel] [360] trunk/ap4r/Rakefile: Fix: hoe requires an environment variable 'HOME' . Message-ID: <20071226013607.1A94718585BC@rubyforge.org> Revision: 360 Author: shino Date: 2007-12-25 20:36:06 -0500 (Tue, 25 Dec 2007) Log Message: ----------- Fix: hoe requires an environment variable 'HOME'. It is not suitable for CI. So wrap it by begin-rescue clause. Modified Paths: -------------- trunk/ap4r/Rakefile Modified: trunk/ap4r/Rakefile =================================================================== --- trunk/ap4r/Rakefile 2007-12-21 09:32:42 UTC (rev 359) +++ trunk/ap4r/Rakefile 2007-12-26 01:36:06 UTC (rev 360) @@ -1,50 +1,53 @@ require 'rubygems' -require 'hoe' require 'erb' require 'active_record' require File.join(File.dirname(__FILE__), 'lib/ap4r', 'version') -namespace :hoe do - hoe = Hoe.new('ap4r', Ap4r::VERSION::STRING) do |p| - p.author = ["Shunichi Shinohara", "Kiwamu Kato"] - p.changes = p.paragraphs_of('History.txt', 1..2).join("\n\n") - #p.clean_globs = - p.description = <<-EOF +begin + namespace :hoe do + require 'hoe' + + hoe = Hoe.new('ap4r', Ap4r::VERSION::STRING) do |p| + p.author = ["Shunichi Shinohara", "Kiwamu Kato"] + p.changes = p.paragraphs_of('History.txt', 1..2).join("\n\n") + #p.clean_globs = + p.description = <<-EOF Asynchronous Processing for Ruby. EOF - p.email = %q{shinohara.shunichi at future.co.jp, kato.kiwamu at future.co.jp} + p.email = %q{shinohara.shunichi at future.co.jp, kato.kiwamu at future.co.jp} - p.extra_deps << ['reliable-msg', '=1.1.0'] - p.extra_deps << ['activesupport'] - p.extra_deps << ['mongrel'] - p.extra_deps << ['rake'] - p.extra_deps << ['hoe'] + p.extra_deps << ['reliable-msg', '=1.1.0'] + p.extra_deps << ['activesupport'] + p.extra_deps << ['mongrel'] + p.extra_deps << ['rake'] + p.extra_deps << ['hoe'] - p.name = 'ap4r' - p.need_tar = false - p.need_zip = false - p.rdoc_pattern = /^(lib|bin|ext|rails_plugin)|txt$/ + p.name = 'ap4r' + p.need_tar = false + p.need_zip = false + p.rdoc_pattern = /^(lib|bin|ext|rails_plugin)|txt$/ - #p.remote_rdoc_dir = - #p.rsync = - p.rubyforge_name = 'ap4r' - #p.spec_extra = - p.summary = 'Asynchronous Processing for Ruby.' - p.test_globs = 'spec/**/*_spec.rb' - p.url = 'http://ap4r.rubyforge.org/wiki/wiki.pl?HomePage' - p.version = Ap4r::VERSION::STRING + #p.remote_rdoc_dir = + #p.rsync = + p.rubyforge_name = 'ap4r' + #p.spec_extra = + p.summary = 'Asynchronous Processing for Ruby.' + p.test_globs = 'spec/**/*_spec.rb' + p.url = 'http://ap4r.rubyforge.org/wiki/wiki.pl?HomePage' + p.version = Ap4r::VERSION::STRING + end + hoe.spec.dependencies.delete_if {|dep| dep.name == "hoe"} + end - hoe.spec.dependencies.delete_if {|dep| dep.name == "hoe"} - +rescue end -task :pkg => "release:copy_plugin" # AP4R release tasks -------------------------------------------------------- HelloWorld = '../samples/HelloWorld' namespace :release do - desc "copy rails plugin from sample before gem build" + desc "copy rails plugin from sample before gem build" task :copy_plugin do # TODO: Should use file task ? 2007/09/27 by shino FileUtils.rm_rf('./rails_plugin/ap4r') @@ -79,7 +82,7 @@ task :sample do FileUtils.mkdir_p('./pkg/samples') FileUtils.rm_rf('./pkg/samples/HelloWorld') - + FileUtils.cp_r(HelloWorld, './pkg/samples/') Find.find('./pkg/samples') do |path| next unless File.file? path @@ -89,12 +92,13 @@ Dir.chdir('./pkg/samples/HelloWorld') `rake db:migrate` Dir.chdir('../../') - + `tar czf HelloWorld-#{Ap4r::VERSION::STRING}.tar.gz ./samples/HelloWorld/` Dir.chdir('../') end end +task :pkg => "release:copy_plugin" # Spec tasks ---------------------------------------------------------------- require 'spec/rake/spectask' @@ -140,7 +144,7 @@ end namespace :qdb do - desc "Make queue and topic tables through scripts in lib/ap4r/db/migrate." + desc "Make queue and topic tables through scripts in lib/ap4r/db/migrate." task :migrate do # Todo: configurable file name, 2007/10/01 kiwamu