makandra_sidekiq 0.1.0
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 +7 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.ruby-version +1 -0
- data/.travis.yml +12 -0
- data/CHANGELOG.md +8 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +72 -0
- data/Rakefile +6 -0
- data/bin/setup +8 -0
- data/lib/makandra_sidekiq/capistrano/tasks/sidekiq.rake +37 -0
- data/lib/makandra_sidekiq/capistrano.rb +1 -0
- data/lib/makandra_sidekiq/railtie.rb +11 -0
- data/lib/makandra_sidekiq/sidekiq_control.rb +121 -0
- data/lib/makandra_sidekiq/tasks/sidekiq.rake +31 -0
- data/lib/makandra_sidekiq/version.rb +3 -0
- data/lib/makandra_sidekiq.rb +2 -0
- data/makandra_sidekiq.gemspec +25 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 21ef8f6ae9bafcc529abfd8fb14321d25bfbaff6
|
4
|
+
data.tar.gz: 4c57b120923a63024bab5ea9bb018651f5465dd4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2018238e3d7d38cd812b63d68c42de8334c0bf91bc0f01d9e99089c95fda2de15028d17dc7d7a7c107440cd8ffb1c37244bcd59355a0aad3a68375648f70db54
|
7
|
+
data.tar.gz: 73a30c082ad3c0c65fda2f054ce36cd3631538e61aea5bf8fa3098722befa581c0b3b8a3db875b16ddb439cd4aeb9ab72e07fab704eae0ca751a2120958e2cb3
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.3.1
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2016 Tobias Kraze
|
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,72 @@
|
|
1
|
+
# makandra_sidekiq [](https://travis-ci.org/makandra/makandra_sidekiq)
|
2
|
+
|
3
|
+
Support code for our default sidekiq setup.
|
4
|
+
|
5
|
+
Includes rake tasks to start and stop sidekiq, capistrano recipes for deployment, and a way to restart sidekiq on reboot.
|
6
|
+
|
7
|
+
|
8
|
+
## Installation
|
9
|
+
|
10
|
+
Add this line to your application's Gemfile:
|
11
|
+
|
12
|
+
```ruby
|
13
|
+
gem 'makandra_sidekiq'
|
14
|
+
```
|
15
|
+
|
16
|
+
|
17
|
+
## Usage
|
18
|
+
|
19
|
+
### Prerequisites
|
20
|
+
|
21
|
+
Your sidekiq configuration has to live in `config/sidekiq.yml`.
|
22
|
+
|
23
|
+
Make sure you include at least `:pidfile` and `:logfile`. Sane values are
|
24
|
+
|
25
|
+
```
|
26
|
+
:pidfile: ./tmp/pids/sidekiq.pid
|
27
|
+
:logfile: ./log/sidekiq.log
|
28
|
+
```
|
29
|
+
|
30
|
+
### Capistrano
|
31
|
+
|
32
|
+
makandra_sidekiq requires [capistrano](https://github.com/capistrano/capistrano) >= 3.
|
33
|
+
|
34
|
+
- Add the following line to your Capfile:
|
35
|
+
|
36
|
+
```
|
37
|
+
require 'makandra_sidekiq/capistrano'
|
38
|
+
```
|
39
|
+
|
40
|
+
- Give one or more servers the `sidekiq` role.
|
41
|
+
|
42
|
+
- Make sure that your pidfile is symlinked to a shared directory. For the example above, make sure that `set :linked_dirs` includes `tmp/pids`.
|
43
|
+
|
44
|
+
|
45
|
+
### Restart sidekiq on reboot
|
46
|
+
|
47
|
+
Simply add `rake sidekiq:start` as a @reboot task to your crontab.
|
48
|
+
|
49
|
+
When using [whenever](https://github.com/javan/whenever), add this to your schedule.rb:
|
50
|
+
|
51
|
+
```
|
52
|
+
every :reboot do
|
53
|
+
rake 'sidekiq:start'
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
57
|
+
In case you don't use whenever, this crontab entry will work:
|
58
|
+
```
|
59
|
+
@reboot /bin/bash -l -c 'cd /path/to/rails/root && RAILS_ENV=environment bundle exec rake sidekiq:start --silent'
|
60
|
+
```
|
61
|
+
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/makandra/makandra_sidekiq.
|
66
|
+
|
67
|
+
|
68
|
+
## Credits
|
69
|
+
|
70
|
+
Tobias Kraze, makandra GmbH
|
71
|
+
|
72
|
+
Arne Hartherz, makandra GmbH
|
data/Rakefile
ADDED
data/bin/setup
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
namespace :sidekiq do
|
2
|
+
|
3
|
+
def run_task(name)
|
4
|
+
on roles :sidekiq do
|
5
|
+
within release_path do
|
6
|
+
with rails_env: fetch(:rails_env) do
|
7
|
+
execute :rake, "sidekiq:#{name}"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
desc 'Quiet sidekiq (stop processing new tasks)'
|
14
|
+
task :quiet do
|
15
|
+
run_task('quiet')
|
16
|
+
end
|
17
|
+
|
18
|
+
desc 'Stop sidekiq'
|
19
|
+
task :stop do
|
20
|
+
run_task('stop')
|
21
|
+
end
|
22
|
+
|
23
|
+
desc 'Start sidekiq'
|
24
|
+
task :start do
|
25
|
+
run_task('start')
|
26
|
+
end
|
27
|
+
|
28
|
+
desc 'Restart sidekiq'
|
29
|
+
task :restart do
|
30
|
+
run_task('restart')
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
after 'deploy:starting', 'sidekiq:quiet'
|
35
|
+
after 'deploy:updated', 'sidekiq:stop'
|
36
|
+
after 'deploy:reverted', 'sidekiq:stop'
|
37
|
+
after 'deploy:published', 'sidekiq:start'
|
@@ -0,0 +1 @@
|
|
1
|
+
load File.expand_path('capistrano/tasks/sidekiq.rake', __dir__)
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'yaml'
|
3
|
+
require 'open3'
|
4
|
+
require 'erb'
|
5
|
+
|
6
|
+
module MakandraSidekiq
|
7
|
+
class SidekiqControl
|
8
|
+
|
9
|
+
CONFIG_PATH = ['config', 'sidekiq.yml']
|
10
|
+
|
11
|
+
def initialize(root)
|
12
|
+
@root = Pathname.new(root)
|
13
|
+
@config = load_config
|
14
|
+
end
|
15
|
+
|
16
|
+
def quiet
|
17
|
+
if running?
|
18
|
+
puts 'Preventing Sidekiq from accepting new jobs...'
|
19
|
+
run_sidekiqctl('quiet')
|
20
|
+
else
|
21
|
+
puts 'Sidekiq is not running.'
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def stop
|
26
|
+
if running?
|
27
|
+
puts 'Stopping Sidekiq...'
|
28
|
+
run_sidekiqctl('stop')
|
29
|
+
else
|
30
|
+
puts 'Sidekiq is not running.'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def start
|
35
|
+
if running?
|
36
|
+
puts 'Sidekiq is already running.'
|
37
|
+
else
|
38
|
+
puts 'Starting Sidekiq...'
|
39
|
+
run_sidekiq
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
def rails_env
|
46
|
+
@rails_env ||= ENV['RAILS_ENV'] || ENV['RACK_ENV'] || 'development'
|
47
|
+
end
|
48
|
+
|
49
|
+
def config_path
|
50
|
+
@config_path ||= @root.join(*CONFIG_PATH)
|
51
|
+
end
|
52
|
+
|
53
|
+
def pid_file
|
54
|
+
@pid_file ||= @root.join(@config[:pidfile])
|
55
|
+
end
|
56
|
+
|
57
|
+
def pid
|
58
|
+
@pid ||= if pid_file.file?
|
59
|
+
pid_file.read.to_i
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
def running?
|
64
|
+
Process.kill(0, pid) if pid
|
65
|
+
rescue Errno::ESRCH
|
66
|
+
# not running
|
67
|
+
false
|
68
|
+
end
|
69
|
+
|
70
|
+
def load_config
|
71
|
+
messages = []
|
72
|
+
begin
|
73
|
+
config_erb = ERB.new(config_path.read)
|
74
|
+
config = YAML.load(config_erb.result)
|
75
|
+
rescue
|
76
|
+
messages << "Error: Could not load #{config_path}."
|
77
|
+
end
|
78
|
+
if config
|
79
|
+
env_config = config[rails_env]
|
80
|
+
config.merge!(env_config) if env_config
|
81
|
+
unless config[:pidfile]
|
82
|
+
messages << "Error: #{config_path} does not set a :pidfile"
|
83
|
+
end
|
84
|
+
unless config[:logfile]
|
85
|
+
messages << "Error: #{config_path} does not set a :logfile."
|
86
|
+
end
|
87
|
+
end
|
88
|
+
if messages.any?
|
89
|
+
fail messages.join("\n")
|
90
|
+
end
|
91
|
+
config
|
92
|
+
end
|
93
|
+
|
94
|
+
def run_sidekiqctl(command)
|
95
|
+
bundle_exec('sidekiqctl', command, pid_file.to_s)
|
96
|
+
end
|
97
|
+
|
98
|
+
def run_sidekiq
|
99
|
+
arguments = [
|
100
|
+
'--index', sidekiq_index.to_s,
|
101
|
+
'--environment', rails_env,
|
102
|
+
'--config', config_path.to_s,
|
103
|
+
'--daemon'
|
104
|
+
]
|
105
|
+
bundle_exec('sidekiq', *arguments)
|
106
|
+
end
|
107
|
+
|
108
|
+
def sidekiq_index
|
109
|
+
ENV['SIDEKIQ_INDEX'] || 0
|
110
|
+
end
|
111
|
+
|
112
|
+
def bundle_exec(*command)
|
113
|
+
stdout_str, stderr_str, status = Open3.capture3('bundle', 'exec', *command, chdir: @root.to_s)
|
114
|
+
puts stdout_str
|
115
|
+
unless status.success?
|
116
|
+
fail "Sidekiqctl failed with message: #{stderr_str}"
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'makandra_sidekiq/sidekiq_control'
|
2
|
+
|
3
|
+
namespace :sidekiq do
|
4
|
+
|
5
|
+
def sidekiq_control
|
6
|
+
root = Rake.application.original_dir
|
7
|
+
@sidekiq_control ||= MakandraSidekiq::SidekiqControl.new(root)
|
8
|
+
end
|
9
|
+
|
10
|
+
desc 'Quiet sidekiq (stop processing new tasks)'
|
11
|
+
task :quiet do
|
12
|
+
sidekiq_control.quiet
|
13
|
+
end
|
14
|
+
|
15
|
+
desc 'Stop sidekiq'
|
16
|
+
task :stop do
|
17
|
+
sidekiq_control.stop
|
18
|
+
end
|
19
|
+
|
20
|
+
desc 'Start sidekiq'
|
21
|
+
task :start do
|
22
|
+
sidekiq_control.start
|
23
|
+
end
|
24
|
+
|
25
|
+
desc 'Restart sidekiq'
|
26
|
+
task :restart do
|
27
|
+
sidekiq_control.stop
|
28
|
+
sidekiq_control.start
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'makandra_sidekiq/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "makandra_sidekiq"
|
8
|
+
spec.version = MakandraSidekiq::VERSION
|
9
|
+
spec.authors = ["Tobias Kraze"]
|
10
|
+
spec.email = ["tobias.kraze@makandra.de"]
|
11
|
+
|
12
|
+
spec.summary = %q{Support code for sidekiq, including rake tasks and capistrano recipes.}
|
13
|
+
spec.homepage = "https://github.com/makandra/makandra_sidekiq"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.bindir = "exe"
|
17
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_dependency 'capistrano', '>= 3'
|
21
|
+
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
23
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
24
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: makandra_sidekiq
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Tobias Kraze
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: capistrano
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.12'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.12'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- tobias.kraze@makandra.de
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".ruby-version"
|
79
|
+
- ".travis.yml"
|
80
|
+
- CHANGELOG.md
|
81
|
+
- Gemfile
|
82
|
+
- LICENSE
|
83
|
+
- README.md
|
84
|
+
- Rakefile
|
85
|
+
- bin/setup
|
86
|
+
- lib/makandra_sidekiq.rb
|
87
|
+
- lib/makandra_sidekiq/capistrano.rb
|
88
|
+
- lib/makandra_sidekiq/capistrano/tasks/sidekiq.rake
|
89
|
+
- lib/makandra_sidekiq/railtie.rb
|
90
|
+
- lib/makandra_sidekiq/sidekiq_control.rb
|
91
|
+
- lib/makandra_sidekiq/tasks/sidekiq.rake
|
92
|
+
- lib/makandra_sidekiq/version.rb
|
93
|
+
- makandra_sidekiq.gemspec
|
94
|
+
homepage: https://github.com/makandra/makandra_sidekiq
|
95
|
+
licenses: []
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.6.6
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Support code for sidekiq, including rake tasks and capistrano recipes.
|
117
|
+
test_files: []
|
118
|
+
has_rdoc:
|