capistrano-delayed-job 1.0.1 → 1.1.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: 3988871ad96962e800e848378bbe2b11f91c46d3
4
- data.tar.gz: 4491bd852fd9e8b04003a99043b37b4449b51bfc
3
+ metadata.gz: 06dde9bb44beaf1417b123c95216e86a6c516a3d
4
+ data.tar.gz: 1e1ae251ea4a96c13001958968e315f83de2a9a0
5
5
  SHA512:
6
- metadata.gz: d6d58f344323ae2856da668a81c9f7cd9bf6e85c4780bfb69711a37b37e7c6c4b0f07e39c226a7a4886874230fc3e28cbe1cb17e172bed6ed3011d8ee3278919
7
- data.tar.gz: 656c4928a24e7c0e5564cd5088353cebe1b2523beca5e6ed88ef7d2f669fee8f3a8d11e91498a665814117502c77a14b2c98d20e5be9da056956c11b6748f8e8
6
+ metadata.gz: ef82795130be159b8bf387daf43e1e9ac1b13a2459858c629c111cde1bd45cbecf812572fddc78f5406aca1c445187c9d060d73f4f34e26ca176bf8ce2c56787
7
+ data.tar.gz: db18958fbce27f26f74aa58c6d738d8b1013f5808a0adb8863a4c75ee363bdfec76241a25e72017732563de3f8a59cc1dfc23e4f5c8b71d20e4a7fd6295cea94
data/README.md CHANGED
@@ -74,6 +74,13 @@ The roles on which the DelayedJob should run.
74
74
  * `set :delayed_job_service, -> { "delayed_job_#{fetch(:application)}_#{fetch(:stage)}" }`<br/>
75
75
  The name of the service that DelayedJob uses.
76
76
 
77
+ * `set :delayed_job_monit_enabled, false` <br/>
78
+ Use monit to monitor DelayedJob processes. This is especially useful on roles with
79
+ constrained memory. On these nodes, DelayedJob processes are regularly killed by the
80
+ OS. In order to use this setting, install monit on roles that run DelayedJob and
81
+ start monit's httpd server. See (here)[http://mmonit.com/monit/documentation/monit.html#MONIT-HTTPD]
82
+ for instructions.
83
+
77
84
  ### Template customization
78
85
 
79
86
  If you want to change default templates, you can generate them using
@@ -4,10 +4,16 @@ module Capistrano
4
4
  module DelayedJob
5
5
  module Helpers
6
6
 
7
- def bundle_delayed_job(*args)
8
- bin_dir = %w{bin script}.find{|dir_name| Dir.exists?(dir_name)}
9
- raise "No bin or script dir found in project" if bin_dir.nil?
10
- SSHKit::Command.new(:bundle, :exec, "#{bin_dir}/delayed_job", args).to_command
7
+ def delayed_job_command(*args)
8
+ "cd #{current_path} && " <<
9
+ SSHKit::Command.new("HOME=/home/#{deploy_user}",
10
+ "RAILS_ENV=#{fetch(:rails_env)}",
11
+ :nice,
12
+ '-n 15',
13
+ :bundle,
14
+ :exec,
15
+ delayed_job_script_relative_path,
16
+ args).to_command
11
17
  end
12
18
 
13
19
  def dj_template(template_name)
@@ -24,7 +30,7 @@ module Capistrano
24
30
  end
25
31
 
26
32
  def deploy_user
27
- capture :id, '-un'
33
+ @deploy_user ||= capture(:id, '-un')
28
34
  end
29
35
 
30
36
  def sudo_upload!(from, to)
@@ -35,6 +41,16 @@ module Capistrano
35
41
  sudo :mv, tmp_file, to_dir
36
42
  end
37
43
 
44
+ def delayed_job_script_relative_path
45
+ "#{relative_bin_path}/delayed_job"
46
+ end
47
+
48
+ private
49
+ def relative_bin_path
50
+ bin_path = %w{bin script}.find { |dir_name| Dir.exists?(dir_name) }
51
+ raise "No bin or script dir found in project" if bin_path.nil?
52
+ bin_path
53
+ end
38
54
  end
39
55
  end
40
56
  end
@@ -1,5 +1,5 @@
1
1
  module Capistrano
2
2
  module DelayedJob
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -6,6 +6,12 @@ module Capistrano
6
6
  "/etc/init.d/#{fetch(:delayed_job_service)}"
7
7
  end
8
8
 
9
+ # install the delayed_job monit configuration in the conf.d directory, where it will
10
+ # automaticaly be picked up by monit
11
+ def delayed_job_monitrc_file
12
+ "/etc/monit/conf.d/#{fetch(:delayed_job_service)}.monitrc"
13
+ end
14
+
9
15
  def current_path
10
16
  deploy_path.join('current')
11
17
  end
@@ -8,6 +8,7 @@ namespace :load do
8
8
  task :defaults do
9
9
  set :delayed_job_workers, 1
10
10
  set :delayed_job_service, -> { "delayed_job_#{fetch(:application)}_#{fetch(:stage)}" }
11
+ set :delayed_job_monit_enabled, false
11
12
 
12
13
  set :delayed_job_server_roles, [:app]
13
14
  end
@@ -36,7 +37,22 @@ namespace :delayed_job do
36
37
  desc "#{command} delayed_job"
37
38
  task command do
38
39
  on roles fetch(:delayed_job_server_roles) do
39
- sudo :service, "#{fetch(:delayed_job_service)} #{command}"
40
+ if fetch(:delayed_job_monit_enabled)
41
+ # monit is enabled, use it to restart the service
42
+ sudo :monit, '-g', 'delayed_job', command
43
+ else
44
+ # monit is disabled, use the standard init script
45
+ sudo :service, fetch(:delayed_job_service), command
46
+ end
47
+ end
48
+ end
49
+ end
50
+
51
+ namespace :monit do
52
+ task :setup do
53
+ on roles fetch(:delayed_job_server_roles) do
54
+ sudo_upload! dj_template('delayed_job.monitrc.erb'), delayed_job_monitrc_file
55
+ sudo :service, 'monit restart'
40
56
  end
41
57
  end
42
58
  end
@@ -49,4 +65,5 @@ end
49
65
  desc 'Server setup tasks'
50
66
  task :setup do
51
67
  invoke 'delayed_job:setup'
68
+ invoke 'delayed_job:monit:setup' if fetch(:delayed_job_monit_enabled)
52
69
  end
@@ -0,0 +1,14 @@
1
+ # DelayedJob monit script generated by capistrano-delayed-job on <%= Time.now %>.
2
+ # Based on: https://github.com/collectiveidea/delayed_job/blob/master/contrib/delayed_job_rails_4_multiple.monitrc
3
+ #
4
+ # The processes are grouped so that monit can act on them as a whole, e.g.
5
+ #
6
+ # monit -g delayed_job restart
7
+
8
+ <% (0..fetch(:delayed_job_workers) - 1).each do |worker_id| %>
9
+ check process delayed_job_<%= worker_id %>
10
+ with pidfile <%= shared_path.join('tmp/pids') %>/delayed_job.<%= worker_id %>.pid
11
+ start program = "/bin/su - <%= deploy_user %> -c '<%= delayed_job_command %> start -i <%= worker_id %>'"
12
+ stop program = "/bin/su - <%= deploy_user %> -c '<%= delayed_job_command %> stop -i <%= worker_id %>'"
13
+ group delayed_job
14
+ <% end %>
@@ -11,18 +11,15 @@
11
11
  ### END INIT INFO
12
12
 
13
13
  N=/etc/init.d/delayed_job
14
- APP_ROOT=<%= current_path %>
15
14
  AS_USER=<%= fetch(:delayed_job_user) %>
16
15
  service="delayed_job"
17
16
 
18
-
19
-
20
17
  set -e
21
18
 
22
19
  interact() {
23
20
  op="$1"
24
21
  echo "Invoking DelayedJob with command '$op'"
25
- CMD="cd $APP_ROOT && HOME=/home/$AS_USER RAILS_ENV=<%= fetch(:rails_env) %> nice -n 15 <%= bundle_delayed_job("$op -n", fetch(:delayed_job_workers))%>"
22
+ CMD="<%= delayed_job_command("$op -n", fetch(:delayed_job_workers))%>"
26
23
 
27
24
  if [ "$(id -un)" = "$AS_USER" ]; then
28
25
  eval $CMD
@@ -45,4 +42,4 @@ case "$1" in
45
42
  ;;
46
43
  esac
47
44
 
48
- exit 0
45
+ exit 0
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: capistrano-delayed-job
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ruben Stranders
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-02 00:00:00.000000000 Z
11
+ date: 2015-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capistrano
@@ -92,6 +92,7 @@ files:
92
92
  - lib/capistrano/tasks/delayed_job.rake
93
93
  - lib/generators/capistrano/delayed_job/USAGE.md
94
94
  - lib/generators/capistrano/delayed_job/config_generator.rb
95
+ - lib/generators/capistrano/delayed_job/templates/delayed_job.monitrc.erb
95
96
  - lib/generators/capistrano/delayed_job/templates/delayed_job_init.erb
96
97
  homepage: https://github.com/capistrano-plugins/capistrano-delayed-job
97
98
  licenses: []