spawno 0.0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f3305d0950d0ebcd02097aea391b4ec4bd39949f
4
+ data.tar.gz: 1121d26a5954ddaad8f96f4a7ef78b56562e5a47
5
+ SHA512:
6
+ metadata.gz: 9616d4738933139a7ed9d30c3cc2a50e1daf3e2cb53cbd9842a2fc6500dff8a62a9945049f668456af64078dc69c7ea78517974749d3c7c4ea8abac86b19de95
7
+ data.tar.gz: 711fad63bc64ccba5ec3656e30b26eda72143efa8eb08389166c9634d1f19dc59d1e3825b72f6e4b09b2cd7c21ac11529e6a42e5b792eac27515cfbbc3f76524
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .idea
@@ -0,0 +1 @@
1
+ spawno
@@ -0,0 +1 @@
1
+ 2.1.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in spawno.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 megorei Software
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Dieter Pisarewski
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,73 @@
1
+ # Spawno
2
+
3
+ Spawno starts parallel processes upon rails initialization. Just configure which processes you want to spawn using YAML file.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'spawno', github: 'megorei/spawno'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Add this line on top of your config.ru file:
16
+
17
+ ```ruby
18
+ ENV['SERVER_MODE'] = '1'
19
+ ```
20
+
21
+ or set `SERVER_MODE` enviroment variable another way. For example:
22
+
23
+ SERVER_MODE=1 rails server
24
+
25
+ ## Usage
26
+
27
+ Create configuration file in your config directory. For example:
28
+
29
+ config/spawno.yml
30
+
31
+ processes:
32
+ -
33
+ environment: production
34
+ command: clockwork clock.rb
35
+ options:
36
+ :out:
37
+ - log/clockwork.log
38
+ - w+
39
+ :err: :out
40
+ -
41
+ environment: test
42
+ command: another_process
43
+ env:
44
+ RACK_ENV: test
45
+ -
46
+ command: third
47
+ env, command and options should be the same as for [spawn](http://www.ruby-doc.org/core-2.1.5/Kernel.html#method-i-spawn) method.
48
+ Spawno sets RAILS_ENV to the rails environment it was started from.
49
+
50
+
51
+ ## Caveats
52
+
53
+ If your application runs in [passenger](https://www.phusionpassenger.com/) or similar dispatcher started processes won't be stopped properly upon shutdown as passenger does not terminate parent process.
54
+ In this case you can stop processes by stopping them manually like:
55
+
56
+ config/spawno.yml
57
+
58
+ processes:
59
+ - environment: production
60
+ command: pkill -f clockwork
61
+
62
+ -
63
+ environment: production
64
+ command: clockwork clock.rb
65
+
66
+
67
+ ## Contributing
68
+
69
+ 1. Fork it ( http://github.com/<my-github-username>/spawno/fork )
70
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
71
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
72
+ 4. Push to the branch (`git push origin my-new-feature`)
73
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,14 @@
1
+ processes:
2
+ -
3
+ environment: production
4
+ command: clockwork clock.rb
5
+ options:
6
+ :out:
7
+ - log/clockwork.log
8
+ - w+
9
+ :err: :out
10
+ -
11
+ environment: test
12
+ command: another_process
13
+ -
14
+ command: third
@@ -0,0 +1,23 @@
1
+ require 'spawno/version'
2
+ require 'spawno/config'
3
+ require 'spawno/spawner'
4
+
5
+ module Spawno
6
+ def self.root
7
+ Dir.pwd
8
+ end
9
+
10
+ def self.setup(root = self.root)
11
+ Config.setup(File.join(root, 'config', 'spawno.yml'))
12
+
13
+ Config.processes.each do |process_conf|
14
+ Spawner.new.spawn(process_conf)
15
+ end
16
+ end
17
+ end
18
+
19
+ if defined?(Rails)
20
+ require 'spawno/railtie'
21
+ else
22
+ Spawno.setup
23
+ end
@@ -0,0 +1,26 @@
1
+ require 'yaml'
2
+
3
+ module Spawno
4
+ class Configuration
5
+ attr_accessor :settings
6
+
7
+ def initialize
8
+ self.settings = {}
9
+ end
10
+
11
+ def load_from_file(path)
12
+ self.settings.merge! YAML.load_file(path)
13
+ end
14
+
15
+ def setup(path = nil)
16
+ load_from_file(path) if path
17
+ end
18
+
19
+ def method_missing(method_name)
20
+ settings[method_name.to_s]
21
+ end
22
+ end
23
+
24
+ Config = Configuration.new
25
+ end
26
+
@@ -0,0 +1,7 @@
1
+ module Spawno
2
+ class Railtie < ::Rails::Railtie
3
+ initializer 'spawno' do |app|
4
+ Spawno.setup(app.root) if ENV['SERVER_MODE'] == '1'
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,27 @@
1
+ class Spawner
2
+ def spawn(process_conf)
3
+ command, env, options, environment = spawn_arguments(process_conf)
4
+ if ENV['SPAWNO'].nil? and matching_environment?(environment)
5
+ Kernel.spawn(env, command, options)
6
+ end
7
+ end
8
+
9
+ def env_vars(env)
10
+ {'SPAWNO' => 'true'}.merge(rails? ? env.merge('RAILS_ENV' => Rails.env) : env)
11
+ end
12
+
13
+ def matching_environment?(environment)
14
+ rails? ? Rails.env == environment : true
15
+ end
16
+
17
+ def rails?
18
+ defined?(Rails)
19
+ end
20
+
21
+ def spawn_arguments(process_conf)
22
+ command, env, options, environment = process_conf.values_at('command', 'env', 'options', 'environment')
23
+ env ||= {}
24
+ options ||= {}
25
+ [command, env_vars(env), options, environment]
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Spawno
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'spawno/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "spawno"
8
+ spec.version = Spawno::VERSION
9
+ spec.authors = ["Dieter Pisarewski"]
10
+ spec.email = ["dieter.pisarewski@gmail.com"]
11
+ spec.summary = %q{Let rails spawn extra processes at startup.}
12
+ spec.description = %q{}
13
+ spec.homepage = "http://megorei.com"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spawno
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Dieter Pisarewski
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-19 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: ''
42
+ email:
43
+ - dieter.pisarewski@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".ruby-gemset"
50
+ - ".ruby-version"
51
+ - Gemfile
52
+ - LICENSE
53
+ - LICENSE.txt
54
+ - README.md
55
+ - Rakefile
56
+ - config/spawno.yml.sample
57
+ - lib/spawno.rb
58
+ - lib/spawno/config.rb
59
+ - lib/spawno/railtie.rb
60
+ - lib/spawno/spawner.rb
61
+ - lib/spawno/version.rb
62
+ - spawno.gemspec
63
+ homepage: http://megorei.com
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Let rails spawn extra processes at startup.
87
+ test_files: []