sails 0.1.4 → 0.1.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.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -16
  3. data/CHANGELOG.md +13 -0
  4. data/Gemfile.lock +2 -2
  5. data/README.md +37 -11
  6. data/lib/sails/base.rb +225 -208
  7. data/lib/sails/cli.rb +13 -14
  8. data/lib/sails/config.rb +5 -5
  9. data/lib/sails/console.rb +9 -9
  10. data/lib/sails/daemon.rb +72 -27
  11. data/lib/sails/log_subscriber.rb +40 -0
  12. data/lib/sails/rails.rb +5 -1
  13. data/lib/sails/service/base.rb +8 -8
  14. data/lib/sails/service/callbacks.rb +2 -3
  15. data/lib/sails/service/interface.rb +34 -27
  16. data/lib/sails/service.rb +2 -2
  17. data/lib/sails/tasks.rb +61 -0
  18. data/lib/sails/templates/Gemfile +4 -4
  19. data/lib/sails/templates/Rakefile.tt +1 -41
  20. data/lib/sails/templates/app/services/application_service.rb.tt +6 -2
  21. data/lib/sails/templates/app/services/gen-rb/%app_name%.rb.tt +78 -3
  22. data/lib/sails/templates/app/services/gen-rb/%app_name%_constants.rb.tt +11 -0
  23. data/lib/sails/templates/app/services/gen-rb/%app_name%_types.rb.tt +46 -0
  24. data/lib/sails/templates/config/application.rb.tt +8 -8
  25. data/lib/sails/templates/config/{database.yml → database.yml.tt} +2 -5
  26. data/lib/sails/templates/config/initializers/active_record.rb +6 -0
  27. data/lib/sails/templates/config/locales/rails.zh-CN.yml +5 -5
  28. data/lib/sails/templates/config/locales/zh-CN.yml +1 -2
  29. data/lib/sails/templates/lib/tasks/client.rake.tt +25 -0
  30. data/lib/sails/version.rb +2 -2
  31. data/lib/sails.rb +12 -6
  32. data/sails.gemspec +1 -1
  33. data/spec/cli_spec.rb +6 -6
  34. data/spec/dummy/.keep +0 -0
  35. data/spec/dummy/log/.keep +0 -0
  36. data/spec/dummy/tmp/.keep +0 -0
  37. data/spec/dummy/tmp/cache/.keep +0 -0
  38. data/spec/dummy/tmp/pids/.keep +0 -0
  39. data/spec/rails_spec.rb +1 -0
  40. data/spec/sails_spec.rb +39 -11
  41. data/spec/spec_helper.rb +1 -1
  42. data/spec/support/service_support.rb +2 -2
  43. metadata +28 -8
  44. data/lib/sails/templates/Gemfile.lock +0 -45
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5f45fd6f786f64cce9eba7b122b22e29aa7e337a
4
- data.tar.gz: 78eac1b7c08a56f29af0e56c97aa2bcf9ad23dfb
3
+ metadata.gz: 9752501c98161e8b95d109743e4f9ce2091d0127
4
+ data.tar.gz: 24a4dcca7f3748da76c715f4d97cb46857308d0c
5
5
  SHA512:
6
- metadata.gz: 47fb7a78f01a40bffe5bcbc4abaac978d9230a240fc1e22f66f8336293075d1961605682709e3cfc1b8771f8050e0c1ab048d5df90fb5ee2bdea127e9a74dc95
7
- data.tar.gz: 68ef692559d3be35f00d714872d3453842f6cf635f99be1b4cd537a23a3fd0e949fa9c5b45e9d3b7e773bc9eaf7b216fbcebc6f436f3bdab951c7c403a6b44cc
6
+ metadata.gz: 703defe29c4488dfce4147d86416cea85c1d5834cc6b10c535cfc24f2ad0c62bd6f6463d3618b394919302e35bffdefd9daabdcfe3023d1fd78ded56a0ecfa1a
7
+ data.tar.gz: 90f1944aed8c06b9c98c49f2fc0602bc189a7b02ab326d5b2fa623b40f3381967d65a966d9a252b02aa3d5cc59439a9015f7f97e4bb4e0771e6e430b95210c92
data/.gitignore CHANGED
@@ -9,28 +9,14 @@
9
9
  /test/version_tmp/
10
10
  /tmp/
11
11
  log/*
12
-
13
- ## Specific to RubyMotion:
14
12
  .dat*
15
- .repl_history
16
13
  build/
17
-
18
- ## Documentation cache and generated files:
19
14
  /.yardoc/
20
15
  /_yardoc/
21
16
  /doc/
22
17
  /rdoc/
23
-
24
- ## Environment normalisation:
25
18
  /.bundle/
26
19
  /lib/bundler/man/
27
-
28
- # for a library or gem, you might want to ignore these files since the code is
29
- # intended to run in multiple environments; otherwise, check them in:
30
- # Gemfile.lock
31
- # .ruby-version
32
- # .ruby-gemset
33
-
34
- # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
35
20
  .rvmrc
36
- spec/dummy/log/
21
+ spec/dummy/log/*.log
22
+ spec/dummy/log/*.log
data/CHANGELOG.md CHANGED
@@ -1,3 +1,16 @@
1
+ ## 0.1.5
2
+
3
+ - Fix stdout error in daemon mode.
4
+ - Clear ActiveRecord connections after method call in ensure.
5
+ - Do not output exception info when raise 404.
6
+ - Add more default code with new project template.
7
+ - Add `rake client` task for thrift client connect test, and you can edit client test code in lib/tasks/client.rake.
8
+ - Move ActiveRecord migration rake tasks into Sails.
9
+ - Add `rake db:migrate:create` command to generate a new migration file.
10
+ - Add default ActiveRecord initialize code.
11
+ - Default use SQLite.
12
+ - Use ActiveSupport::Notifications to output service action logs.
13
+
1
14
  ## 0.1.4 / 2014-12-24
2
15
 
3
16
  - Sails.root use Linux pwd command, to support symlink dir, for example like Capistrano's project/current path.
data/Gemfile.lock CHANGED
@@ -1,8 +1,8 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sails (0.1.3)
5
- activesupport (>= 3.2.0)
4
+ sails (0.1.4)
5
+ activesupport (> 3.2.0, < 5.0)
6
6
  thor
7
7
  thrift (>= 0.9.0)
8
8
 
data/README.md CHANGED
@@ -41,27 +41,50 @@ $ sails start
41
41
  You can edit Thrift IDL in `app_name.thrift`, and then generate it to ruby source code.
42
42
 
43
43
  ```
44
- $ rake gen
44
+ $ rake generate
45
45
  ```
46
46
 
47
- ## Client Connect
47
+ ## Rake tasks
48
48
 
49
- ```ruby
50
- require "app/services/gen-rb/you_app_name"
51
- @transport ||= Thrift::FramedTransport.new(::Thrift::Socket.new('127.0.0.1', 4000, 10))
52
- @protocol ||= Thrift::BinaryProtocol.new(@transport)
53
- @client ||= Thrift::YouAppName::Client.new(@protocol)
54
- @transport.open()
55
- puts @client.ping()
56
- => Ping pong
49
+ ```bash
50
+ rake client:ping # client ping test
51
+ rake db:create # Creates the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:create:all to create all databases in the config)
52
+ rake db:drop # Drops the database from DATABASE_URL or config/database.yml for the current RAILS_ENV (use db:drop:all to drop all databases in the config)
53
+ rake db:fixtures:load # Load fixtures into the current environment's database
54
+ rake db:migrate # Migrate the database (options: VERSION=x, VERBOSE=false, SCOPE=blog)
55
+ rake db:migrate:create # Create new migration file
56
+ rake db:migrate:status # Display status of migrations
57
+ rake db:rollback # Rolls the schema back to the previous version (specify steps w/ STEP=n)
58
+ rake db:schema:cache:clear # Clear a db/schema_cache.dump file
59
+ rake db:schema:cache:dump # Create a db/schema_cache.dump file
60
+ rake db:schema:dump # Create a db/schema.rb file that is portable against any DB supported by AR
61
+ rake db:schema:load # Load a schema.rb file into the database
62
+ rake db:seed # Load the seed data from db/seeds.rb
63
+ rake db:setup # Create the database, load the schema, and initialize with the seed data (use db:reset to also drop the database first)
64
+ rake db:structure:dump # Dump the database structure to db/structure.sql
65
+ rake db:structure:load # Recreate the databases from the structure.sql file
66
+ rake db:version # Retrieves the current schema version number
67
+ rake generate # Generate code from thrift IDL file
68
+ ```
69
+
70
+ ## Client connect to test
71
+
72
+ You can write test code in `lib/tasks/client.rake` to test your thrift methods.
73
+
74
+ And then start sails server, and run rake task to test, for example:
75
+
76
+ ```bash
77
+ sails s --daemon
78
+ rake client:ping
57
79
  ```
58
80
 
81
+
59
82
  ## Deploy
60
83
 
61
84
  ```
62
85
  $ sails s --daemon
63
86
  $ ps aux
64
- jason 2408 0.1 0.2 2648176 13532 s003 S 12:14下午 0:00.02 you_sails_app
87
+ jason 2408 0.1 0.2 2648176 13532 s003 S 12:14下午 0:00.02 you_sails_app
65
88
  jason 2407 0.0 0.0 2604916 1016 s003 S 12:14下午 0:00.00 you_sails_app [master]
66
89
  $ sails restart
67
90
  $ sails stop
@@ -77,3 +100,6 @@ http://www.rubydoc.info/github/huacnlee/sails
77
100
  - [ ] Reload without restart;
78
101
  - [ ] Scaffold generator;
79
102
  - [X] Multi processes;
103
+ - [ ] Default test case templates;
104
+ - [ ] Client rake task to test services;
105
+ - [ ] Write more framework test cases.
data/lib/sails/base.rb CHANGED
@@ -1,244 +1,261 @@
1
- Bundler.require()
1
+ Bundler.require
2
2
 
3
3
  module Sails
4
4
  extend ActiveSupport::Autoload
5
5
 
6
6
  autoload :Config
7
7
 
8
- # Sails.config
9
- #
10
- # Configs with Sails
11
- # For example:
12
- #
13
- # Sails.config.app_name
14
- # # => returns "You App Name"
15
- #
16
- # Sails.config.autoload_paths
17
- # # => returns ['app/models','app/models/concerns', 'app/workers', 'app/services'...]
18
- #
19
- # Sails.config.cache_store = [:dalli_store, '127.0.0.1', { pool_size: 100 }]
20
- # Sails.config.i18n.default_locale = 'zh-CN'
21
- #
22
- def self.config
23
- return @config if defined?(@config)
24
- @config = Config.new.config
25
- end
8
+ class << self
9
+ # Sails.config
10
+ #
11
+ # Configs with Sails
12
+ # For example:
13
+ #
14
+ # Sails.config.app_name
15
+ # # => returns "You App Name"
16
+ #
17
+ # Sails.config.autoload_paths
18
+ # # => returns ['app/models','app/models/concerns', 'app/workers', 'app/services'...]
19
+ #
20
+ # Sails.config.cache_store = [:dalli_store, '127.0.0.1', { pool_size: 100 }]
21
+ # Sails.config.i18n.default_locale = 'zh-CN'
22
+ #
23
+ def config
24
+ return @config if defined?(@config)
25
+ @config = Config.new.config
26
+ end
26
27
 
27
- # Sails.cache
28
- #
29
- # An abstract cache store class. There are multiple cache store
30
- # implementations, each having its own additional features. See the classes
31
- # under the ActiveSupport::Cache module, e.g.
32
- # ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most
33
- # popular cache store for large production websites.
34
- #
35
- # Some implementations may not support all methods beyond the basic cache
36
- # methods of +fetch+, +write+, +read+, +exist?+, and +delete+.
37
- #
38
- # ActiveSupport::Cache::Store can store any serializable Ruby object.
39
- #
40
- # Sails.cache.read('city') # => nil
41
- # Sails.cache.write('city', "Duckburgh")
42
- # Sails.cache.read('city') # => "Duckburgh"
43
- #
44
- # Keys are always translated into Strings and are case sensitive. When an
45
- # object is specified as a key and has a +cache_key+ method defined, this
46
- # method will be called to define the key. Otherwise, the +to_param+
47
- # method will be called. Hashes and Arrays can also be used as keys. The
48
- # elements will be delimited by slashes, and the elements within a Hash
49
- # will be sorted by key so they are consistent.
50
- #
51
- # Sails.cache.read('city') == Sails.cache.read(:city) # => true
52
- #
53
- # Nil values can be cached.
54
- def self.cache
55
- return @cache if defined?(@cache)
56
- @cache = ActiveSupport::Cache.lookup_store(self.config.cache_store)
57
- end
28
+ # Sails.cache
29
+ #
30
+ # An abstract cache store class. There are multiple cache store
31
+ # implementations, each having its own additional features. See the classes
32
+ # under the ActiveSupport::Cache module, e.g.
33
+ # ActiveSupport::Cache::MemCacheStore. MemCacheStore is currently the most
34
+ # popular cache store for large production websites.
35
+ #
36
+ # Some implementations may not support all methods beyond the basic cache
37
+ # methods of +fetch+, +write+, +read+, +exist?+, and +delete+.
38
+ #
39
+ # ActiveSupport::Cache::Store can store any serializable Ruby object.
40
+ #
41
+ # Sails.cache.read('city') # => nil
42
+ # Sails.cache.write('city', "Duckburgh")
43
+ # Sails.cache.read('city') # => "Duckburgh"
44
+ #
45
+ # Keys are always translated into Strings and are case sensitive. When an
46
+ # object is specified as a key and has a +cache_key+ method defined, this
47
+ # method will be called to define the key. Otherwise, the +to_param+
48
+ # method will be called. Hashes and Arrays can also be used as keys. The
49
+ # elements will be delimited by slashes, and the elements within a Hash
50
+ # will be sorted by key so they are consistent.
51
+ #
52
+ # Sails.cache.read('city') == Sails.cache.read(:city) # => true
53
+ #
54
+ # Nil values can be cached.
55
+ def cache
56
+ return @cache if defined?(@cache)
57
+ @cache = ActiveSupport::Cache.lookup_store(self.config.cache_store)
58
+ end
58
59
 
59
- # Sails.root
60
- #
61
- # This method returns a Pathname object which handles paths starting with a / as absolute (starting from the root of the filesystem). Compare:
62
- #
63
- # For example:
64
- # >> Sails.root
65
- # => #<Pathname:/some/path/to/project>
66
- # >> Sails.root + "file"
67
- # => #<Pathname:/some/path/to/project/file>
68
- #
69
- def self.root
70
- return @root if defined?(@root)
71
- path = `pwd -L`.sub(/\n/,'') rescue Dir.pwd
72
- @root ||= Pathname.new(path)
73
- end
60
+ # Sails.root
61
+ #
62
+ # This method returns a Pathname object which handles paths starting with a / as absolute (starting from the root of the filesystem). Compare:
63
+ #
64
+ # For example:
65
+ # >> Sails.root
66
+ # => #<Pathname:/some/path/to/project>
67
+ # >> Sails.root + "file"
68
+ # => #<Pathname:/some/path/to/project/file>
69
+ #
70
+ def root
71
+ return @root if defined?(@root)
72
+ path = `pwd -L`.sub(/\n/,'') rescue Dir.pwd
73
+ @root ||= Pathname.new(path)
74
+ end
74
75
 
75
- def self.root=(root)
76
- @root = Pathname.new(root)
77
- end
76
+ def root=(root)
77
+ @root = Pathname.new(root)
78
+ end
78
79
 
79
- # Sails.env
80
- #
81
- # returns a string representing the current Sails environment.
82
- # This will read from ENV['RAILS_ENV'] like Rails
83
- #
84
- # For example:
85
- #
86
- # Sails.env # in development mode
87
- # => "development"
88
- # Sails.env.development?
89
- # => true
90
- #
91
- def self.env
92
- @env ||= ActiveSupport::StringInquirer.new(ENV['RAILS_ENV'].presence || 'development')
93
- end
80
+ # Sails.env
81
+ #
82
+ # returns a string representing the current Sails environment.
83
+ # This will read from ENV['RAILS_ENV'] like Rails
84
+ #
85
+ # For example:
86
+ #
87
+ # Sails.env # in development mode
88
+ # => "development"
89
+ # Sails.env.development?
90
+ # => true
91
+ #
92
+ def env
93
+ @env ||= ActiveSupport::StringInquirer.new(ENV['RAILS_ENV'].presence || 'development')
94
+ end
94
95
 
95
- # Sails.logger
96
- #
97
- # returns a Logger class
98
- # For example:
99
- #
100
- # Sails.logger.info "Hello world"
101
- # Sails.logger.error "Hello world"
102
- #
103
- def self.logger
104
- return @logger if defined?(@logger)
105
- log_file = File.join(Sails.root, "log/#{self.env}.log")
106
- @logger = Logger.new(log_file)
107
- @logger.formatter = proc { |severity, datetime, progname, msg|
108
- "#{msg}\n"
109
- }
110
- @logger
111
- end
96
+ # Sails.logger
97
+ #
98
+ # returns a Logger class
99
+ # For example:
100
+ #
101
+ # Sails.logger.info "Hello world"
102
+ # Sails.logger.error "Hello world"
103
+ #
104
+ def logger
105
+ return @logger if defined?(@logger)
106
+ @logger = Logger.new(logger_path)
107
+ @logger.formatter = proc { |severity, datetime, progname, msg|
108
+ "#{msg}\n"
109
+ }
110
+ @logger
111
+ end
112
112
 
113
- def self.init
114
- # init root
115
- return false if @inited == true
116
- $:.unshift self.root.join("lib")
113
+ def logger_path
114
+ @logger_path ||= Sails.root.join("log/#{self.env}.log")
115
+ end
117
116
 
118
- self.root
117
+ def init
118
+ # init root
119
+ return false if @inited == true
120
+ $:.unshift self.root.join("lib")
119
121
 
120
- ActiveSupport::Dependencies.autoload_paths += Sails.config.autoload_paths
122
+ self.root
123
+ self.check_create_dirs
121
124
 
122
- env_file = self.root.join('config/environments/',Sails.env + ".rb")
123
- if File.exist?(env_file)
124
- require env_file
125
- end
125
+ ActiveSupport::Dependencies.autoload_paths += Sails.config.autoload_paths
126
126
 
127
- require "sails/service"
127
+ env_file = self.root.join('config/environments/',Sails.env + ".rb")
128
+ if File.exist?(env_file)
129
+ require env_file
130
+ end
128
131
 
129
- load_initialize
130
- @inited = true
131
- end
132
+ require "sails/service"
132
133
 
133
- # Sails.service
134
- #
135
- # return a instance of Sails Service layer
136
- #
137
- # for example:
138
- #
139
- # class UsersService < Sails::Service::Base
140
- # def check_name_exist?(name)
141
- # User.check_name_exist?(name)
142
- # end
143
- # end
144
- #
145
- # class UsersServiceTest
146
- # def test_check_name_exist?
147
- # assert_equal(Sails.service.check_name_exist?(name), true)
148
- # end
149
- # end
150
- #
151
- def self.service
152
- @service ||= Sails::Service::Interface.new
153
- end
134
+ self.load_initialize
135
+ @inited = true
136
+ end
154
137
 
155
- # Force reload Sails cache classes in config.autoload_paths
156
- def self.reload!(opts = {})
157
- force = opts[:force] || false
158
- if force || config.cache_classes == false
159
- # @service = nil
160
- ActiveSupport::Dependencies.clear
161
- # reload_server!
138
+ # Sails.service
139
+ #
140
+ # return a instance of Sails Service layer
141
+ #
142
+ # for example:
143
+ #
144
+ # class UsersService < Sails::Service::Base
145
+ # def check_name_exist?(name)
146
+ # User.check_name_exist?(name)
147
+ # end
148
+ # end
149
+ #
150
+ # class UsersServiceTest
151
+ # def test_check_name_exist?
152
+ # assert_equal(Sails.service.check_name_exist?(name), true)
153
+ # end
154
+ # end
155
+ #
156
+ def service
157
+ @service ||= Sails::Service::Interface.new
162
158
  end
163
- return true
164
- end
165
159
 
166
- def self.reload_server!
167
- if @server
168
- new_processor = config.processor.new(self.service)
169
- @server.instance_variable_set(:@processor, new_processor)
160
+ # Force reload Sails cache classes in config.autoload_paths
161
+ def reload!(opts = {})
162
+ force = opts[:force] || false
163
+ if force || config.cache_classes == false
164
+ # @service = nil
165
+ ActiveSupport::Dependencies.clear
166
+ # reload_server!
167
+ end
168
+ true
169
+ end
170
+
171
+ def reload_server!
172
+ if @server
173
+ new_processor = config.processor.new(self.service)
174
+ @server.instance_variable_set(:@processor, new_processor)
175
+ end
170
176
  end
171
- end
172
177
 
173
- def self.start!(type)
174
- logger.info "ENV: #{Sails.env}"
178
+ def start!(type)
179
+ logger.info "ENV: #{Sails.env}"
175
180
 
176
- @server_type = type
177
- if @server_type == "thread"
178
- start_thread_pool_server!
179
- else
180
- start_non_blocking_server!
181
+ @server_type = type
182
+ if @server_type == "thread"
183
+ start_thread_pool_server!
184
+ else
185
+ start_non_blocking_server!
186
+ end
181
187
  end
182
- end
183
188
 
184
- def self.thrift_protocol_class
185
- case config.protocol
186
- when :compact
187
- return ::Thrift::CompactProtocolFactory
188
- when :json
189
- return ::Thrift::JsonProtocolFactory
190
- else
191
- return ::Thrift::BinaryProtocolFactory
189
+ def thrift_protocol_class
190
+ case config.protocol
191
+ when :compact
192
+ return ::Thrift::CompactProtocolFactory
193
+ when :json
194
+ return ::Thrift::JsonProtocolFactory
195
+ else
196
+ return ::Thrift::BinaryProtocolFactory
197
+ end
192
198
  end
193
- end
194
199
 
195
- # Start Thrift Server with Threaded mode
196
- #
197
- def self.start_thread_pool_server!
198
- transport = ::Thrift::ServerSocket.new(nil, config.thread_port)
199
- transport_factory = ::Thrift::BufferedTransportFactory.new
200
- protocol_factory = thrift_protocol_class.new
201
- processor = config.processor.new(self.service)
202
- @server = ::Thrift::ThreadPoolServer.new(processor, transport, transport_factory, protocol_factory, config.thread_size)
203
-
204
- logger.info "Boot on: #{Sails.root}"
205
- logger.info "[#{Time.now}] Starting the Sails with ThreadPool size: #{Setting.pool_size}..."
206
- logger.info "serve: 127.0.0.1:#{config.thread_port}"
207
-
208
- begin
209
- @server.serve
210
- rescue => e
211
- puts "Start thrift server exception! \n #{e.inspect}"
212
- puts e.backtrace
200
+ # Start Thrift Server with Threaded mode
201
+ #
202
+ def start_thread_pool_server!
203
+ transport = ::Thrift::ServerSocket.new(nil, config.thread_port)
204
+ transport_factory = ::Thrift::BufferedTransportFactory.new
205
+ protocol_factory = thrift_protocol_class.new
206
+ processor = config.processor.new(self.service)
207
+ @server = ::Thrift::ThreadPoolServer.new(processor, transport, transport_factory, protocol_factory, config.thread_size)
208
+
209
+ logger.info "Boot on: #{Sails.root}"
210
+ logger.info "[#{Time.now}] Starting the Sails with ThreadPool size: #{Setting.pool_size}..."
211
+ logger.info "serve: 127.0.0.1:#{config.thread_port}"
212
+
213
+ begin
214
+ @server.serve
215
+ rescue => e
216
+ puts "Start thrift server exception! \n #{e.inspect}"
217
+ puts e.backtrace
218
+ end
213
219
  end
214
- end
215
220
 
216
- # Start Thrift Server with Event drive mode
217
- def self.start_non_blocking_server!
218
- transport = ::Thrift::ServerSocket.new(nil, config.port)
219
- transport_factory = ::Thrift::FramedTransportFactory.new
220
- protocol_factory = thrift_protocol_class.new
221
- processor = config.processor.new(self.service)
222
- @server = ::Thrift::NonblockingServer.new(processor, transport, transport_factory, protocol_factory, config.thread_size)
223
-
224
- logger.info "Boot on: #{Sails.root}"
225
- logger.info "[#{Time.now}] Starting the Sails with NonBlocking..."
226
- logger.info "Protocol: #{thrift_protocol_class.name}"
227
- logger.info "serve: 127.0.0.1:#{config.port}"
228
-
229
- begin
230
- @server.serve
231
- rescue => e
232
- puts "Start thrift server exception! \n #{e.inspect}"
233
- puts e.backtrace
221
+ # Start Thrift Server with Event drive mode
222
+ def start_non_blocking_server!
223
+ transport = ::Thrift::ServerSocket.new(nil, config.port)
224
+ transport_factory = ::Thrift::FramedTransportFactory.new
225
+ protocol_factory = thrift_protocol_class.new
226
+ processor = config.processor.new(self.service)
227
+ @server = ::Thrift::NonblockingServer.new(processor, transport, transport_factory, protocol_factory, config.thread_size)
228
+
229
+ logger.info "Boot on: #{Sails.root}"
230
+ logger.info "[#{Time.now}] Starting the Sails with NonBlocking..."
231
+ logger.info "Protocol: #{thrift_protocol_class.name}"
232
+ logger.info "serve: 127.0.0.1:#{config.port}"
233
+
234
+ begin
235
+ @server.serve
236
+ rescue => e
237
+ puts "Start thrift server exception! \n #{e.inspect}"
238
+ puts e.backtrace
239
+ end
240
+ end
241
+
242
+ def load_initialize
243
+ Dir["#{Sails.root}/config/initializers/*.rb"].each do |f|
244
+ require f
245
+ end
234
246
  end
235
- end
236
247
 
237
- def self.load_initialize
238
- Dir["#{Sails.root}/config/initializers/*.rb"].each do |f|
239
- require f
248
+ def check_create_dirs
249
+ %w(log tmp tmp/cache tmp/pids).each do |name|
250
+ if not Dir.exist? Sails.root.join(name)
251
+ require "fileutils"
252
+ dir_path = Sails.root.join(name)
253
+ FileUtils.mkdir_p dir_path
254
+ FileUtils.touch [dir_path,".keep"].join("/")
255
+ end
256
+ end
240
257
  end
241
258
  end
242
259
  end
243
260
 
244
- Sails.init()
261
+ Sails.init