mina-sidekiq 0.1.1 → 0.2.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: 340eecbce7bf98675a29f44bb6f973101dd8a205
4
- data.tar.gz: 427b634f9fb14312e0d1fb28912fe9bf9bf3741d
3
+ metadata.gz: b00138ad54880e131c60c2d955511bbfbdd9d262
4
+ data.tar.gz: f66cdab70f47c85ac99a0a7ffaaa5d04e79e3cfb
5
5
  SHA512:
6
- metadata.gz: e90a545139b3b2229fbda1817df1367f0ed48d99d438640138e7bf0c86738d00183c005f504c0ebdf8382c1fe98c85501c7b90cd5fdbb2845c57835884065338
7
- data.tar.gz: 80988e5e13a94bdabcc296564d325318d2a1a23a9a11180a9c7b17bfd16e5eeebcf222c92a404fd29c93297541a035c0980dee79ba93b472aaa521ac5ca96827
6
+ metadata.gz: 7ce054e9deb259727dcd88232968ce6dc07d8a9cf921e3680277f3e250fa91be3fcbdb0e6146c5c957ebd8c03910e84d47eb2f18c7d48496474c3c3b5dd559e2
7
+ data.tar.gz: 66ef72fcfc9521ef8e4938e285b4c1384088edf353d61c8da5b14e7538eb6f53521b0cea8e0021a267a56686b9a7e74c7297e65157e7c927bd40217b0e992d64
data/.gitignore CHANGED
@@ -16,3 +16,4 @@ tmp
16
16
  .yardoc
17
17
  _yardoc
18
18
  doc/
19
+ test_env/deploy/
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - "1.9.3"
4
+ - "2.0.0"
5
+ services: redis
6
+ env: FORCE_ADD_SSH_KEY=1
data/Changelog.md ADDED
@@ -0,0 +1,14 @@
1
+ Changelog
2
+ =========
3
+
4
+ 0.2.0 2013-08-18
5
+ ----------------
6
+
7
+ Breaking Changes:
8
+
9
+ * to load the tasks requiring 'mina_sidekiq/tasks' is needed now
10
+
11
+ Enhancements:
12
+
13
+ * add sidekiq_processes to allow launching multiple sidekiq instances
14
+ * improved checking, if old instances of sidekiq are still running
data/Gemfile.lock ADDED
@@ -0,0 +1,20 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ mina-sidekiq (0.2.0)
5
+ mina
6
+
7
+ GEM
8
+ remote: http://www.rubygems.org/
9
+ specs:
10
+ mina (0.3.0)
11
+ open4
12
+ rake
13
+ open4 (1.3.0)
14
+ rake (10.1.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ mina-sidekiq!
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
1
  mina-sidekiq
2
2
  ============
3
3
 
4
+ [![Build Status](https://travis-ci.org/Mic92/mina-sidekiq.png?branch=master)](https://travis-ci.org/Mic92/mina-sidekiq)
5
+
4
6
  mina-sidekiq is a gem that adds tasks to aid in the deployment of [Sidekiq] (http://mperham.github.com/sidekiq/)
5
7
  using [Mina] (http://nadarei.co/mina).
6
8
 
@@ -12,14 +14,25 @@ using [Mina] (http://nadarei.co/mina).
12
14
 
13
15
  ## Example
14
16
 
15
- require 'mina-sidekiq'
17
+ ## Usage example
18
+
19
+ require 'mina_sidekiq/tasks'
16
20
  ...
21
+ # to make logs persistent between deploys
22
+ set :shared_paths, ['log']
23
+
24
+ task :setup do
25
+ # sidekiq needs a place to store its pid file and log file
26
+ queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
27
+ queue! %[mkdir -p "#{deploy_to}/shared/log/"]
28
+ end
17
29
 
18
- task :deploy => :enviroment do
30
+ task :deploy do
19
31
  deploy do
20
32
  # stop accepting new workers
21
33
  invoke :'sidekiq:quiet'
22
34
  invoke :'git:clone'
35
+ invoke :'deploy:link_shared_paths'
23
36
  ...
24
37
 
25
38
  to :launch do
@@ -43,6 +56,7 @@ using [Mina] (http://nadarei.co/mina).
43
56
  * sidekiq\_timeout: Sets a upper limit of time a worker is allowed to finish, before it is killed.
44
57
  * sidekiq\_log: Sets the path to the log file of sidekiq
45
58
  * sidekiq\_pid: Sets the path to the pid file of a sidekiq worker
59
+ * sidekiq_processes: Sets the number of sidekiq processes launched
46
60
 
47
61
  ## Copyright
48
62
 
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ require 'rake'
2
+
3
+ desc 'Run integration tests'
4
+ task :test do
5
+ Dir.chdir("#{Rake.original_dir}/test_env") do
6
+ if ENV['FORCE_ADD_SSH_KEY']
7
+ force_add_ssh_key
8
+ end
9
+
10
+ FileUtils.rm_rf('deploy')
11
+ sh 'mina setup --verbose'
12
+ begin
13
+ # fresh deploy
14
+ sh 'mina deploy --verbose'
15
+ # second deploy
16
+ sh 'mina deploy --verbose'
17
+ rescue Exception => e
18
+ puts e.message
19
+ puts e.backtrace.inspect
20
+ log = "./deploy/shared/sidekiq.log"
21
+ if File.exists?(log)
22
+ puts "cat #{log}"
23
+ puts File.open(log).read
24
+ end
25
+ end
26
+ end
27
+ end
28
+
29
+ def force_add_ssh_key(&block)
30
+ ssh_key = File.expand_path("~/.ssh/id_rsa.pub")
31
+ unless File.exists?(ssh_key)
32
+ sh "ssh-keygen -t rsa -N '' -f ~/.ssh/id_rsa"
33
+ end
34
+ file = File.open(ssh_key)
35
+ pub_key = file.readline
36
+ file.close
37
+
38
+ authorized_keys = File.expand_path("~/.ssh/authorized_keys")
39
+ begin
40
+ File.open(authorized_keys, 'a+') do |f|
41
+ File.chmod(0600, authorized_keys)
42
+ f.puts(pub_key)
43
+ end
44
+ rescue Exception => e
45
+ puts e.message
46
+ puts e.backtrace.inspect
47
+ ensure
48
+ File.chmod(0400, authorized_keys)
49
+ end
50
+ end
51
+
52
+ task :default => :test
@@ -0,0 +1,121 @@
1
+ # # Modules: Sidekiq
2
+ # Adds settings and tasks for managing Sidekiq workers.
3
+ #
4
+ # ## Usage example
5
+ # require 'mina_sidekiq/tasks'
6
+ # ...
7
+ # task :setup do
8
+ # # sidekiq needs a place to store its pid file
9
+ # queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
10
+ # end
11
+ #
12
+ # task :deploy do
13
+ # deploy do
14
+ # invoke :'sidekiq:quiet'
15
+ # invoke :'git:clone'
16
+ # ...
17
+ #
18
+ # to :launch do
19
+ # ...
20
+ # invoke :'sidekiq:restart'
21
+ # end
22
+ # end
23
+ # end
24
+
25
+ require 'mina/bundler'
26
+ require 'mina/rails'
27
+
28
+ # ## Settings
29
+ # Any and all of these settings can be overriden in your `deploy.rb`.
30
+
31
+ # ### sidekiq
32
+ # Sets the path to sidekiq.
33
+ set_default :sidekiq, lambda { "#{bundle_bin} exec sidekiq" }
34
+
35
+ # ### sidekiqctl
36
+ # Sets the path to sidekiqctl.
37
+ set_default :sidekiqctl, lambda { "#{bundle_prefix} sidekiqctl" }
38
+
39
+ # ### sidekiq_timeout
40
+ # Sets a upper limit of time a worker is allowed to finish, before it is killed.
41
+ set_default :sidekiq_timeout, 10
42
+
43
+ # ### sidekiq_config
44
+ # Sets the path to the configuration file of sidekiq
45
+ set_default :sidekiq_config, "./config/sidekiq.yml"
46
+
47
+ # ### sidekiq_log
48
+ # Sets the path to the log file of sidekiq
49
+ #
50
+ # To disable logging set it to "/dev/null"
51
+ set_default :sidekiq_log, lambda { "#{deploy_to}/#{current_path}/log/sidekiq.log" }
52
+
53
+ # ### sidekiq_pid
54
+ # Sets the path to the pid file of a sidekiq worker
55
+ set_default :sidekiq_pid, lambda { "#{deploy_to}/#{shared_path}/pids/sidekiq.pid" }
56
+
57
+ # ### sidekiq_processes
58
+ # Sets the number of sidekiq processes launched
59
+ set_default :sidekiq_processes, 1
60
+
61
+ # ## Control Tasks
62
+ namespace :sidekiq do
63
+ def for_each_process(&block)
64
+ sidekiq_processes.times do |idx|
65
+ pid_file = if idx == 0
66
+ sidekiq_pid
67
+ else
68
+ "#{sidekiq_pid}-#{idx}"
69
+ end
70
+ yield(pid_file, idx)
71
+ end
72
+ end
73
+
74
+ # ### sidekiq:quiet
75
+ desc "Quiet sidekiq (stop accepting new work)"
76
+ task :quiet do
77
+ queue %[echo "-----> Quiet sidekiq (stop accepting new work)"]
78
+ for_each_process do |pid_file, idx|
79
+ queue %{
80
+ if [ -d #{deploy_to}/#{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then
81
+ #{echo_cmd %{cd #{deploy_to}/#{current_path} && #{sidekiqctl} quiet #{pid_file}} }
82
+ else
83
+ echo 'Sidekiq is not running'
84
+ fi
85
+ }
86
+ end
87
+ end
88
+
89
+ # ### sidekiq:stop
90
+ desc "Stop sidekiq"
91
+ task :stop do
92
+ queue %[echo "-----> Stop sidekiq"]
93
+ for_each_process do |pid_file, idx|
94
+ queue %[
95
+ if [ -d #{deploy_to}/#{current_path} ] && [ -f #{pid_file} ] && kill -0 `cat #{pid_file}`> /dev/null 2>&1; then
96
+ #{echo_cmd %[cd #{deploy_to}/#{current_path} && #{sidekiqctl} stop #{pid_file} #{sidekiq_timeout}]}
97
+ else
98
+ echo 'Sidekiq is not running'
99
+ fi
100
+ ]
101
+ end
102
+ end
103
+
104
+ # ### sidekiq:start
105
+ desc "Start sidekiq"
106
+ task :start do
107
+ queue %[echo "-----> Start sidekiq"]
108
+ for_each_process do |pid_file, idx|
109
+ queue %{
110
+ #{echo_cmd %[cd #{deploy_to}/#{current_path}; nohup #{sidekiq} -e #{rails_env} -C #{sidekiq_config} -P #{pid_file} >> #{sidekiq_log} 2>&1 &] }
111
+ }
112
+ end
113
+ end
114
+
115
+ # ### sidekiq:restart
116
+ desc "Restart sidekiq"
117
+ task :restart do
118
+ invoke :'sidekiq:stop'
119
+ invoke :'sidekiq:start'
120
+ end
121
+ end
@@ -0,0 +1,5 @@
1
+ module MinaSidekiq
2
+ def self.version
3
+ "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ require 'mina_sidekiq/version'
2
+
3
+ module MinaSidekiq
4
+ end
data/mina-sidekiq.gemspec CHANGED
@@ -1,8 +1,10 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
 
3
+ require "./lib/mina_sidekiq/version.rb"
4
+
3
5
  Gem::Specification.new do |s|
4
6
  s.name = "mina-sidekiq"
5
- s.version = File.read('VERSION')
7
+ s.version = MinaSidekiq.version
6
8
  s.authors = ["Joerg Thalheim"]
7
9
  s.email = ["joerg@higgsboson.tk"]
8
10
  s.homepage = "http://github.com/Mic92/mina-sidekiq"
@@ -14,6 +16,13 @@ Gem::Specification.new do |s|
14
16
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
17
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
16
18
  s.require_paths = ["lib"]
19
+ s.post_install_message = <<-MESSAGE
20
+ Starting with 0.2.0, you have to add:
21
+
22
+ require 'mina_sidekiq/tasks'
23
+
24
+ in your deploy.rb to load the library
25
+ MESSAGE
17
26
 
18
27
  s.add_runtime_dependency "mina"
19
28
  end
@@ -0,0 +1,46 @@
1
+ require 'mina'
2
+ require 'mina/git'
3
+ require 'mina_sidekiq/tasks'
4
+ require 'mina/git'
5
+ require 'mina/bundler'
6
+ require 'mina/rvm'
7
+ require 'fileutils'
8
+
9
+ FileUtils.mkdir_p "#{Dir.pwd}/deploy"
10
+
11
+ set :ssh_options, '-o StrictHostKeyChecking=no'
12
+
13
+ set :domain, 'localhost'
14
+ set :deploy_to, "#{Dir.pwd}/deploy"
15
+ set :repository, 'https://github.com/Mic92/mina-sidekiq-test-rails.git'
16
+ set :keep_releases, 2
17
+ set :sidekiq_processes, 2
18
+
19
+ set :shared_paths, ['log']
20
+
21
+ task :environment do
22
+ invoke :'rvm:use[ruby-2.0.0]'
23
+ end
24
+
25
+ task :setup => :environment do
26
+ queue! %[mkdir -p "#{deploy_to}/shared/pids/"]
27
+ queue! %[mkdir -p "#{deploy_to}/shared/log/"]
28
+ end
29
+
30
+ task :deploy => :environment do
31
+ deploy do
32
+ invoke :'git:clone'
33
+ invoke :'deploy:link_shared_paths'
34
+ invoke :'bundle:install'
35
+
36
+ to :launch do
37
+ invoke :'sidekiq:start'
38
+ queue! %[sleep 3; kill -0 `cat #{sidekiq_pid}`]
39
+
40
+ invoke :'sidekiq:quiet'
41
+
42
+ invoke :'sidekiq:stop'
43
+ queue! %[(kill -0 `cat #{sidekiq_pid}`) 2> /dev/null && exit 1 || exit 0]
44
+ end
45
+ end
46
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mina-sidekiq
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joerg Thalheim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-04 00:00:00.000000000 Z
11
+ date: 2013-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mina
@@ -32,18 +32,28 @@ extensions: []
32
32
  extra_rdoc_files: []
33
33
  files:
34
34
  - .gitignore
35
+ - .travis.yml
36
+ - Changelog.md
35
37
  - Gemfile
38
+ - Gemfile.lock
36
39
  - LICENSE
37
40
  - README.md
38
- - VERSION
39
- - lib/mina-sidekiq.rb
40
- - lib/mina-sidekiq/sidekiq.rb
41
+ - Rakefile
42
+ - lib/mina_sidekiq.rb
43
+ - lib/mina_sidekiq/tasks.rb
44
+ - lib/mina_sidekiq/version.rb
41
45
  - mina-sidekiq.gemspec
46
+ - test_env/config/deploy.rb
42
47
  homepage: http://github.com/Mic92/mina-sidekiq
43
48
  licenses:
44
49
  - MIT
45
50
  metadata: {}
46
- post_install_message:
51
+ post_install_message: |
52
+ Starting with 0.2.0, you have to add:
53
+
54
+ require 'mina_sidekiq/tasks'
55
+
56
+ in your deploy.rb to load the library
47
57
  rdoc_options: []
48
58
  require_paths:
49
59
  - lib
@@ -59,7 +69,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
59
69
  version: '0'
60
70
  requirements: []
61
71
  rubyforge_project:
62
- rubygems_version: 2.0.3
72
+ rubygems_version: 2.0.6
63
73
  signing_key:
64
74
  specification_version: 4
65
75
  summary: Tasks to deploy Sidekiq with mina.
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.1
@@ -1,88 +0,0 @@
1
- # # Modules: Sidekiq
2
- # Adds settings and tasks for managing Sidekiq workers.
3
- #
4
- # ## Usage example
5
- # require 'mina-sidekiq/sidekiq'
6
- # ...
7
- #
8
- # task :deploy => :enviroment do
9
- # deploy do
10
- # invoke :'sidekiq:quiet'
11
- # invoke :'git:clone'
12
- # ...
13
- #
14
- # to :launch do
15
- # ...
16
- # invoke :'sidekiq:restart'
17
- # end
18
- # end
19
- # end
20
-
21
- require 'mina/bundler'
22
- require 'mina/rails'
23
-
24
- # ## Settings
25
- # Any and all of these settings can be overriden in your `deploy.rb`.
26
-
27
- # ### sidekiq
28
- # Sets the path to sidekiq.
29
- set_default :sidekiq, lambda { "#{bundle_bin} exec sidekiq" }
30
-
31
- # ### sidekiqctl
32
- # Sets the path to sidekiqctl.
33
- set_default :sidekiqctl, lambda { "#{bundle_prefix} sidekiqctl" }
34
-
35
- # ### sidekiq_timeout
36
- # Sets a upper limit of time a worker is allowed to finish, before it is killed.
37
- set_default :sidekiq_timeout, 10
38
-
39
- # ### sidekiq_config
40
- # Sets the path to the configuration file of sidekiq
41
- set_default :sidekiq_config, "./config/sidekiq.yml"
42
-
43
- # ### sidekiq_log
44
- # Sets the path to the log file of sidekiq
45
- #
46
- # To disable logging set it to "/dev/null"
47
- set_default :sidekiq_log, "./log/sidekiq.log"
48
-
49
- # ### sidekiq_pid
50
- # Sets the path to the pid file of a sidekiq worker
51
- set_default :sidekiq_pid, lambda { "#{deploy_to}/#{shared_path}/pids/sidekiq.pid" }
52
-
53
- # ## Control Tasks
54
- namespace :sidekiq do
55
- # ### sidekiq:quiet
56
- desc "Quiet sidekiq (stop accepting new work)"
57
- task :quiet do
58
- queue %{ if [ -f #{sidekiq_pid} ]; then
59
- echo "-----> Quiet sidekiq (stop accepting new work)"
60
- #{echo_cmd %{(cd #{deploy_to}/#{current_path} && #{sidekiqctl} quiet #{sidekiq_pid})} }
61
- fi }
62
- end
63
-
64
- # ### sidekiq:stop
65
- desc "Stop sidekiq"
66
- task :stop do
67
- queue %[ if [ -f #{sidekiq_pid} ]; then
68
- echo "-----> Stop sidekiq"
69
- #{echo_cmd %[(cd #{deploy_to}/#{current_path} && #{sidekiqctl} stop #{sidekiq_pid} #{sidekiq_timeout})]}
70
- fi ]
71
- end
72
-
73
- # ### sidekiq:start
74
- desc "Start sidekiq"
75
- task :start do
76
- queue %{
77
- echo "-----> Start sidekiq"
78
- #{echo_cmd %[(cd #{deploy_to}/#{current_path}; nohup #{sidekiq} -e #{rails_env} -C #{sidekiq_config} -P #{sidekiq_pid} >> #{sidekiq_log} 2>&1 </dev/null &) ] }
79
- }
80
- end
81
-
82
- # ### sidekiq:restart
83
- desc "Restart sidekiq"
84
- task :restart do
85
- invoke :'sidekiq:stop'
86
- invoke :'sidekiq:start'
87
- end
88
- end
data/lib/mina-sidekiq.rb DELETED
@@ -1,3 +0,0 @@
1
- module MinaSidekiq
2
- require "mina-sidekiq/sidekiq"
3
- end