servitude 0.8.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0f13c74949c47d98ecb7be0cfdd1fc46a32e6496
4
- data.tar.gz: c8995f9320f6777635b6f261bb998893c3af67f5
3
+ metadata.gz: 3bc5c02aa6f0759b2c023219955399164bc1fb7f
4
+ data.tar.gz: ed9b38cdedb0f0a593619abd71ae5e23ceb0a351
5
5
  SHA512:
6
- metadata.gz: 36bae4285106e9ace2eb9bb25b9a10e5b5de7c0e8ba727b8123198b0d9b004c9121253d219efdec755bd4a71bd31cc4cddf1029f37e81136d844856a85044047
7
- data.tar.gz: 3227a9d4d2d0ba4e292d31072b3f5ba73cf5b47219f95a94ed1fe6165e40b65f82b69c3e0e45dfc6b04d0f0df74f6f2eeb54805f4b865c592e505ce56ef37f2e
6
+ metadata.gz: 9aed8c3cfb27f402763f0cbb60291d4c8d3f46c4b8afe4ad76860812210071f60e8a74a25101925c5d8f2e8922e159b666703c2b695bc4237924f20d3caf7916
7
+ data.tar.gz: 0722743586090901fbe060ee76f26efe40540e89fd7795b10ea2459eb319eac8bbcc872a5deebbd611a6905ac5914501039e4ffd7784078d15cfe56ad69f90b8
data/README.md CHANGED
@@ -70,10 +70,7 @@ If you do not call ::boot, an error is raised before your server can be started.
70
70
  app_name: 'Aswesome Server',
71
71
  attribution: "v#{VERSION} \u00A9#{Time.now.year} Awesome, Inc."
72
72
  author: 'Awesome, Inc.',
73
- default_config_path: "/etc/awesome/awesome-server.conf",
74
- default_log_path: "/var/log/awesome/awesome-server.log",
75
- default_pid_path: "/var/run/awesome/awesome-server.pid",
76
- default_thread_count: 1
73
+ default_config_path: "/etc/awesome/awesome-server.conf"
77
74
  end
78
75
 
79
76
  ### Servitude::Cli
@@ -29,9 +29,6 @@ module SimpleServer
29
29
  author: 'LFE',
30
30
  use_config: false,
31
31
  default_config_path: nil,
32
- default_log_path: nil,
33
- default_pid_path: nil,
34
- default_thread_count: nil
35
32
 
36
33
  class Server
37
34
 
@@ -35,9 +35,6 @@ module EchoServer
35
35
  author: 'LFE',
36
36
  use_config: false,
37
37
  default_config_path: nil,
38
- default_log_path: nil,
39
- default_pid_path: nil,
40
- default_thread_count: nil
41
38
 
42
39
  class Server
43
40
 
@@ -46,9 +46,6 @@ module EchoServer
46
46
  author: 'LFE',
47
47
  use_config: false,
48
48
  default_config_path: "#{PROJECT_ROOT}}/config/#{APP_FOLDER}.conf",
49
- default_log_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.log",
50
- default_pid_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.pid",
51
- default_thread_count: nil
52
49
 
53
50
  class Cli < Servitude::Cli::Service
54
51
  end
@@ -46,9 +46,6 @@ module EchoServer
46
46
  author: 'LFE',
47
47
  use_config: true,
48
48
  default_config_path: "#{PROJECT_ROOT}/config/4.conf",
49
- default_log_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.log",
50
- default_pid_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.pid",
51
- default_thread_count: nil
52
49
 
53
50
  class Cli < Servitude::Cli::Service
54
51
  end
@@ -54,9 +54,6 @@ module EchoServer
54
54
  author: 'LFE',
55
55
  use_config: true,
56
56
  default_config_path: "#{PROJECT_ROOT}/config/5.conf",
57
- default_log_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.log",
58
- default_pid_path: "#{PROJECT_ROOT}/tmp/#{APP_FOLDER}.pid",
59
- default_thread_count: nil
60
57
 
61
58
  class Cli < Servitude::Cli::Service
62
59
  end
@@ -24,9 +24,6 @@ module Servitude
24
24
  attribution: ( "v#{host_namespace::VERSION} Copyright © #{Time.now.year} #{author || company}" rescue nil ),
25
25
  use_config: false,
26
26
  default_config_path: nil,
27
- default_log_path: nil,
28
- default_pid_path: nil,
29
- default_thread_count: nil,
30
27
  server_class: ( host_namespace::Server rescue "#{host_namespace.name}::Server" ),
31
28
  version_copyright: nil ) # TODO: Remove when version_copyright keyword deprecation expires
32
29
  unless host_namespace
@@ -70,9 +67,6 @@ module Servitude
70
67
  const_set :COMPANY, author # TODO: Remove when company keyword deprecation expires
71
68
  const_set :ATTRIBUTION, attribution
72
69
  const_set :DEFAULT_CONFIG_PATH, default_config_path
73
- const_set :DEFAULT_LOG_PATH, default_log_path
74
- const_set :DEFAULT_PID_PATH, default_pid_path
75
- const_set :DEFAULT_THREAD_COUNT, default_thread_count
76
70
  const_set :USE_CONFIG, use_config
77
71
  const_set :VERSION_COPYRIGHT, attribution # TODO: Remove when version_copyright keyword deprecation expires
78
72
 
@@ -82,9 +76,6 @@ module Servitude
82
76
  Servitude.const_set :COMPANY, author # TODO: Remove when company keyword deprecation expires
83
77
  Servitude.const_set :ATTRIBUTION, attribution
84
78
  Servitude.const_set :DEFAULT_CONFIG_PATH, default_config_path
85
- Servitude.const_set :DEFAULT_LOG_PATH, default_log_path
86
- Servitude.const_set :DEFAULT_PID_PATH, default_pid_path
87
- Servitude.const_set :DEFAULT_THREAD_COUNT, default_thread_count
88
79
  Servitude.const_set :SERVER_CLASS, server_class
89
80
  Servitude.const_set :USE_CONFIG, use_config
90
81
  Servitude.const_set :VERSION_COPYRIGHT, attribution # TODO: Remove when version_copyright keyword deprecation expires
@@ -7,15 +7,15 @@ module Servitude
7
7
  end
8
8
 
9
9
  def self.pid_option
10
- method_option :pid, desc: "The path for the PID file", type: :string, default: Servitude::DEFAULT_PID_PATH
10
+ method_option :pid, desc: "The path for the PID file", type: :string
11
11
  end
12
12
 
13
13
  def self.common_start_options
14
14
  method_option :config, type: :string, aliases: '-c', desc: "The path for the config file", default: Servitude::DEFAULT_CONFIG_PATH
15
15
  environment_option
16
- method_option :log_level, desc: "The log level", type: :string, aliases: '-o', default: 'info'
17
- method_option :log, desc: "The path for the log file", type: :string, aliases: '-l', default: Servitude::DEFAULT_LOG_PATH
18
- method_option :threads, desc: "The number of threads", type: :numeric, aliases: '-t', default: Servitude::DEFAULT_THREAD_COUNT
16
+ method_option :log_level, desc: "The log level", type: :string, aliases: '-o'
17
+ method_option :log, desc: "The path for the log file", type: :string, aliases: '-l'
18
+ method_option :threads, desc: "The number of threads", type: :numeric, aliases: '-t'
19
19
  end
20
20
 
21
21
  desc "restart", "Stop and start the server"
@@ -1,33 +1,58 @@
1
- require 'delegate'
2
1
  require 'hashie'
3
- require 'oj'
2
+ #require 'oj'
3
+ require 'pathname'
4
+ require 'yaml'
4
5
 
5
6
  module Servitude
6
- class Configuration < SimpleDelegator
7
+ class Configuration < Hashie::Mash
7
8
 
8
- def initialize( options={} )
9
- options.reject! { |k,v| v.nil? }
9
+ def self.load( options={} )
10
+ merged_options = defaults.merge( file_options )
11
+ merged_options = merged_options.merge( options )
12
+ new( merged_options )
13
+ end
14
+
15
+ def self.config_filepath
16
+ Servitude::DEFAULT_CONFIG_PATH
17
+ end
10
18
 
11
- if options[:use_config]
12
- @_config = Hashie::Mash.new( file_options( options[:config] ))
13
- _config.merge!( options )
14
- else
15
- @_config = Hashie::Mash.new( options )
16
- end
19
+ def config_filepath
20
+ Pathname.new( self.class.config_filepath )
21
+ end
22
+
23
+ def slice( *keys )
24
+ klass.new( select { |k,v| keys.map( &:to_s ).include?( k ) } )
25
+ end
17
26
 
18
- super _config
27
+ def for_env
28
+ return Hashie::Mash.new({}) unless env
29
+ self[env]
19
30
  end
20
31
 
21
32
  protected
22
33
 
23
- attr_reader :_config
34
+ # Override to povide default config values
35
+ #
36
+ def self.defaults
37
+ {
38
+ threads: 1
39
+ }
40
+ end
41
+
42
+ def self.file_options
43
+ return {} unless config_filepath
24
44
 
25
- def file_options( file_path )
26
- unless File.file?( file_path )
27
- raise "Configuration file #{file_path} does not exist"
28
- end
45
+ File.exists?( config_filepath ) ?
46
+ load_file_options :
47
+ {}
48
+ end
49
+
50
+ def self.load_file_options
51
+ YAML::load( File.read( config_filepath ))
52
+ end
29
53
 
30
- Oj.load( File.read( file_path ))
54
+ def klass
55
+ self.class
31
56
  end
32
57
 
33
58
  end
@@ -53,7 +53,7 @@ module Servitude
53
53
  end
54
54
 
55
55
  def initialize_config
56
- Servitude.configuration = configuration_class.new( cli_options )
56
+ Servitude.configuration = configuration_class.load( cli_options )
57
57
  end
58
58
 
59
59
  def configuration_class
@@ -42,7 +42,6 @@ module Servitude
42
42
  %w(
43
43
  help
44
44
  interactive
45
- interactive_given
46
45
  )
47
46
  end
48
47
 
@@ -9,27 +9,51 @@ module Servitude
9
9
 
10
10
  protected
11
11
 
12
+ def handler_class
13
+ raise NotImplementedError
14
+ end
15
+
16
+ def run
17
+ raise NotImplementedError
18
+ end
19
+
12
20
  def with_supervision( &block )
13
21
  begin
14
22
  block.call
15
23
  rescue Servitude::SupervisionError
16
24
  # supervisor is restarting actor
17
- #warn ANSI.cyan { "RETRYING due to waiting on supervisor to restart actor ..." }
25
+ warn_for_supevision_error
26
+ sleep( config.supervision_retry_timeout || 0 )
18
27
  retry
19
28
  rescue Celluloid::DeadActorError
20
29
  # supervisor has yet to begin restarting actor
21
- #warn ANSI.blue { "RETRYING due to Celluloid::DeadActorError ..." }
30
+ warn_for_dead_actor_error
31
+ sleep( config.supervision_retry_timeout || 0 )
22
32
  retry
33
+ rescue => e
34
+ handle_error( payload, delivery_info, e )
23
35
  end
24
36
  end
25
37
 
38
+ def warn_for_supevision_error
39
+ warn "RETRYING due to waiting on supervisor to restart actor ..."
40
+ end
41
+
42
+ def warn_for_dead_actor_error
43
+ warn "RETRYING due to Celluloid::DeadActorError ..."
44
+ end
45
+
46
+ def handle_error( payload, delivery_info, e )
47
+ error( "#{e.class.name} | #{e.message} | #{e.backtrace.inspect}" )
48
+ end
49
+
26
50
  # Correctly calls a single supervised actor when the threads configuraiton is set
27
51
  # to 1, or a pool of actors if threads configuration is > 1. Also protects against
28
52
  # a supervised actor from being nil if the supervisor is reinitializing when access
29
53
  # is attempted.
30
54
  #
31
55
  def call_handler_respecting_thread_count( options )
32
- if options[:threads] > 1
56
+ if config.threads > 1
33
57
  pool.async.call( options )
34
58
  else
35
59
  raise Servitude::SupervisionError unless handler
@@ -37,16 +61,8 @@ module Servitude
37
61
  end
38
62
  end
39
63
 
40
- def handler_class
41
- raise NotImplementedError
42
- end
43
-
44
- def run
45
- raise NotImplementedError
46
- end
47
-
48
64
  def pool
49
- @pool ||= handler_class.pool( size: options[:threads] )
65
+ @pool ||= handler_class.pool( size: config.threads )
50
66
  end
51
67
 
52
68
  def handler
@@ -54,7 +70,7 @@ module Servitude
54
70
  end
55
71
 
56
72
  def initialize_thread
57
- return unless options[:threads] == 1
73
+ return unless config.threads == 1
58
74
  handler_class.supervise_as :handler
59
75
  end
60
76
 
@@ -1,3 +1,3 @@
1
1
  module Servitude
2
- VERSION = "0.8.2"
2
+ VERSION = "1.0.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: servitude
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Harrelson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-05 00:00:00.000000000 Z
11
+ date: 2014-12-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler