resque-god 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ea13e3ae8c63a2127947794f8520eec956bdb9cc
4
+ data.tar.gz: 608a2e7c257730d783fcab57d74dda41f8b88f1f
5
+ SHA512:
6
+ metadata.gz: d14d87f5f98477707a47a20d2fbff022267682b4df7d0a7280c71c76660e81d285a6eba1e58af1d0709e97456fff79df48b552e3887451fd563cc0b1563e27e3
7
+ data.tar.gz: 604492046faaaf733f935c8758ef5bc52ec4a447ac2d06334aec97fdb55d149d34ab94e8066fbb979ff5a659016003e2f84a652c215e13a7950ae2577e8ae695
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in resque-god.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 bibendi
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.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Resque::God
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'resque-god'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install resque-god
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/resque-god/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,106 @@
1
+ require 'yaml'
2
+ require 'ostruct'
3
+ require 'erb'
4
+
5
+ require 'active_support/core_ext/hash/keys'
6
+ require 'active_support/core_ext/hash/deep_merge'
7
+
8
+ module Resque
9
+ module God
10
+ class Configuration
11
+ class Worker < OpenStruct
12
+ def initialize(queue, config)
13
+ data = {queue: queue}
14
+
15
+ if config.is_a?(Hash)
16
+ data.merge!(config.symbolize_keys)
17
+ else
18
+ data[:count] = config
19
+ end
20
+
21
+ super(data)
22
+ end
23
+
24
+ def count
25
+ [super || 1, 1].max
26
+ end
27
+
28
+ def env
29
+ env = super || {}
30
+
31
+ env[:QUEUE] ||= queue
32
+
33
+ Hash[env.map { |k, v| [k, v.to_s] }]
34
+ end
35
+ end
36
+
37
+ def initialize(*paths)
38
+ @configuration = {}
39
+ paths.each { |f| load f }
40
+ end
41
+
42
+ def workers
43
+ @workers ||= (self[:workers] || {}).map { |k, v| Worker.new(k, v) }
44
+ end
45
+
46
+ def log_file
47
+ self['resque.log_file'] || ::Rails.root.join('log/resque.log').to_s
48
+ end
49
+
50
+ def config_file
51
+ self['resque.config_file'] || ::Rails.root.join('config/resque.god').to_s
52
+ end
53
+
54
+ def pid_file
55
+ "#{pids}/resque-god.pid"
56
+ end
57
+
58
+ def pids
59
+ self['resque.pids'] || ::Rails.root.join('tmp/pids').to_s
60
+ end
61
+
62
+ def root
63
+ self['resque.root'] || ::Rails.root.to_s
64
+ end
65
+
66
+ def terminate_timeout
67
+ workers.map(&:stop_timeout).compact.max.to_i + 10
68
+ end
69
+
70
+ def env
71
+ env = self['env'] || {}
72
+
73
+ Hash[env.map { |k, v| [k, v.to_s] }]
74
+ end
75
+
76
+ def to_god
77
+ template = ERB.new(File.read(File.join(File.dirname(__FILE__), 'god.erb')))
78
+ template.result(binding)
79
+ end
80
+
81
+ private
82
+
83
+ def load(path)
84
+ if File.exists?(path)
85
+ config = YAML.load(File.read(path))
86
+
87
+ @configuration.merge!(config)
88
+ end
89
+ end
90
+
91
+ # get value from configuration
92
+ def [](path)
93
+ parts = path.to_s.split('.')
94
+ result = @configuration
95
+
96
+ parts.each do |k|
97
+ result = result[k]
98
+
99
+ break if result.nil?
100
+ end
101
+
102
+ result
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,55 @@
1
+ # THIS FILE IS AUTO-GENERATED. PLEASE DO NOT CHANGE IT!
2
+
3
+ bundle = '<%= `which bundle`.strip %>'
4
+ rails_root = '<%= root %>'
5
+ God.pid_file_directory = '<%= pids %>'
6
+ God.terminate_timeout = <%= terminate_timeout.to_i %>
7
+
8
+ <% workers.each do |worker| %>
9
+ <% worker.count.times do |i| %>
10
+ God.watch do |w|
11
+ w.dir = rails_root
12
+ w.name = 'resque-<%= worker.queue %>-<%= i %>'
13
+ w.group = 'resque'
14
+ w.interval = 30.seconds
15
+ w.env = <%= Resque::God.config.env.merge(worker.env).merge(:RAILS_ENV => ::Rails.env, :BUNDLE_GEMFILE => "#{root}/Gemfile").stringify_keys! %>
16
+ w.start = "#{bundle} exec rake -f #{rails_root}/Rakefile resque:work"
17
+ w.log = '<%= log_file %>'
18
+ w.stop_signal = 'QUIT'
19
+
20
+ <% if worker.stop_timeout %>
21
+ w.stop_timeout = <%= worker.stop_timeout %>
22
+ <% end %>
23
+
24
+ # determine the state on startup
25
+ w.transition(:init, { true => :up, false => :start }) do |on|
26
+ on.condition(:process_running) do |c|
27
+ c.running = true
28
+ end
29
+ end
30
+
31
+ # determine when process has finished starting
32
+ w.transition([:start, :restart], :up) do |on|
33
+ on.condition(:process_running) do |c|
34
+ c.running = true
35
+ c.interval = 5.seconds
36
+ end
37
+
38
+ # failsafe
39
+ on.condition(:tries) do |c|
40
+ c.times = 5
41
+ c.transition = :start
42
+ c.interval = 5.seconds
43
+ end
44
+ end
45
+
46
+ # start if process is not running
47
+ w.transition(:up, :start) do |on|
48
+ on.condition(:process_running) do |c|
49
+ c.running = false
50
+ end
51
+ end
52
+ # END OF WORKER CONFIGURATION
53
+ end
54
+ <% end %>
55
+ <% end %>
@@ -0,0 +1,11 @@
1
+ require 'rails/railtie'
2
+
3
+ module Resque
4
+ module God
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load 'resque/god/tasks.rake'
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,69 @@
1
+ namespace :resque do
2
+ desc 'Generate God configuration file'
3
+ task :conf => :environment do
4
+ File.write(Resque::God.config.config_file, Resque::God.config.to_god)
5
+
6
+ puts "God configuration file generated to #{Resque::God.config.config_file}"
7
+ end
8
+
9
+ desc 'Start God server and watch for Resque workers'
10
+ task :start => :conf do
11
+ if god_running?
12
+ puts `#{god} start resque`
13
+ else
14
+ puts `#{god} -c #{Resque::God.config.config_file} -P #{Resque::God.config.pid_file} -l #{Resque::God.config.log_file}`
15
+ end
16
+ end
17
+
18
+ desc 'Restart Resque workers'
19
+ task :restart => :conf do
20
+ if god_stopped?
21
+ Rake::Task['resque:start'].invoke
22
+ else
23
+ puts `#{god} load #{Resque::God.config.config_file} stop && #{god} restart resque`
24
+ end
25
+ end
26
+
27
+ desc 'Stop Resque workers'
28
+ task :stop do
29
+ puts `#{god} stop resque`
30
+ end
31
+
32
+ desc 'Stop Resque workers and quit God'
33
+ task :terminate do
34
+ puts `#{god} terminate`
35
+ end
36
+
37
+ desc 'Stop processing any new jobs'
38
+ task :pause do
39
+ puts `#{god} signal resque USR2`
40
+ end
41
+
42
+ desc 'Resume jobs processing after pause'
43
+ task :resume do
44
+ puts `#{god} signal resque CONT`
45
+ end
46
+
47
+ desc 'Shows Resque status'
48
+ task :status do
49
+ puts `#{god} status resque`
50
+ end
51
+
52
+ private
53
+
54
+ def god
55
+ `which god`.strip
56
+ end
57
+
58
+ def god_running?
59
+ File.exists?(Resque::God.config.pid_file) && Process.kill(0, File.read(Resque::God.config.pid_file).to_i)
60
+ rescue Errno::ESRCH
61
+ false
62
+ rescue Errno::EPERM
63
+ true
64
+ end
65
+
66
+ def god_stopped?
67
+ !god_running?
68
+ end
69
+ end
@@ -0,0 +1,5 @@
1
+ module Resque
2
+ module God
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
data/lib/resque/god.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'resque/god/version'
2
+ require 'resque/god/railtie'
3
+ require 'active_support/dependencies/autoload'
4
+
5
+ module Resque
6
+ module God
7
+ extend ActiveSupport::Autoload
8
+
9
+ autoload :Configuration
10
+
11
+ def self.config
12
+ @config ||= Configuration.new(Rails.root.join('config', 'resque-god.yml'))
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'resque/god/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "resque-god"
8
+ spec.version = Resque::God::VERSION
9
+ spec.authors = ["bibendi"]
10
+ spec.email = ["bibendi@bk.ru"]
11
+ spec.summary = "Launch Resque workers from config via God"
12
+ spec.description = "Launch Resque workers from config via God. Worker`s settings are stored in the config file."
13
+ spec.homepage = "https://github.com/bibendi/resque-god"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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_runtime_dependency 'resque', '~> 1.25'
22
+ spec.add_runtime_dependency 'god', '>= 0.13'
23
+ spec.add_runtime_dependency 'railties', '>= 3.0'
24
+ spec.add_runtime_dependency 'activesupport', '>= 3.0'
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.7"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency 'rspec', '~> 3.1'
29
+ end
metadata ADDED
@@ -0,0 +1,155 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-god
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - bibendi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-12-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ prerelease: false
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.25'
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: '1.25'
25
+ type: :runtime
26
+ name: resque
27
+ - !ruby/object:Gem::Dependency
28
+ prerelease: false
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0.13'
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - '>='
37
+ - !ruby/object:Gem::Version
38
+ version: '0.13'
39
+ type: :runtime
40
+ name: god
41
+ - !ruby/object:Gem::Dependency
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '3.0'
53
+ type: :runtime
54
+ name: railties
55
+ - !ruby/object:Gem::Dependency
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '3.0'
67
+ type: :runtime
68
+ name: activesupport
69
+ - !ruby/object:Gem::Dependency
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '1.7'
76
+ requirement: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ~>
79
+ - !ruby/object:Gem::Version
80
+ version: '1.7'
81
+ type: :development
82
+ name: bundler
83
+ - !ruby/object:Gem::Dependency
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - ~>
93
+ - !ruby/object:Gem::Version
94
+ version: '10.0'
95
+ type: :development
96
+ name: rake
97
+ - !ruby/object:Gem::Dependency
98
+ prerelease: false
99
+ version_requirements: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '3.1'
104
+ requirement: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ~>
107
+ - !ruby/object:Gem::Version
108
+ version: '3.1'
109
+ type: :development
110
+ name: rspec
111
+ description: Launch Resque workers from config via God. Worker`s settings are stored
112
+ in the config file.
113
+ email:
114
+ - bibendi@bk.ru
115
+ executables: []
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - .gitignore
120
+ - Gemfile
121
+ - LICENSE.txt
122
+ - README.md
123
+ - Rakefile
124
+ - lib/resque/god.rb
125
+ - lib/resque/god/configuration.rb
126
+ - lib/resque/god/god.erb
127
+ - lib/resque/god/railtie.rb
128
+ - lib/resque/god/tasks.rake
129
+ - lib/resque/god/version.rb
130
+ - resque-god.gemspec
131
+ homepage: https://github.com/bibendi/resque-god
132
+ licenses:
133
+ - MIT
134
+ metadata: {}
135
+ post_install_message:
136
+ rdoc_options: []
137
+ require_paths:
138
+ - lib
139
+ required_ruby_version: !ruby/object:Gem::Requirement
140
+ requirements:
141
+ - - '>='
142
+ - !ruby/object:Gem::Version
143
+ version: '0'
144
+ required_rubygems_version: !ruby/object:Gem::Requirement
145
+ requirements:
146
+ - - '>='
147
+ - !ruby/object:Gem::Version
148
+ version: '0'
149
+ requirements: []
150
+ rubyforge_project:
151
+ rubygems_version: 2.4.2
152
+ signing_key:
153
+ specification_version: 4
154
+ summary: Launch Resque workers from config via God
155
+ test_files: []