capistrano-delayed-job 1.0.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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c7bad2495a9ab3aa196b5baa2a60a3f1bf1cd647
4
+ data.tar.gz: 360b7828d6f2cb4e0aea819569173c286d2b975f
5
+ SHA512:
6
+ metadata.gz: e73baaf94c73eeadb5594e73da815f1f0a7ba5e0c4250f747e405639e41832e837328e25cbba201d21ecd9ecbad38572ef4abc3d8263563d7dfd608711fabc79
7
+ data.tar.gz: ec6d5df4eb93dfede6e36994f2d3c6552a881870a7c89d87b3c6e80a60fc550526553f753b8233f4180e0d839d5943f6e896508983393239b23f8e20ee68bff7
@@ -0,0 +1,19 @@
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
+ /vendor/ruby
19
+ .idea
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in *.gemspec
4
+ gemspec
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2014 Ruben Stranders
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the "Software"),
5
+ to deal in the Software without restriction, including without limitation
6
+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the
8
+ Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included
11
+ in all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
15
+ OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
17
+ DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
18
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
19
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,115 @@
1
+ # Capistrano::DelayedJob
2
+
3
+ Capistrano tasks for automatic DelayedJob configuration.
4
+
5
+ Goals of this plugin:
6
+
7
+ * automatic DelayedJob configuration for Rails apps
8
+ * **no manual ssh** to the server required
9
+
10
+ Specifics:
11
+
12
+ * generates an init script on the server for Delayed job
13
+ * capistrano tasks for management, example: `delayed_job:restart`<br/>
14
+ see below for all available tasks
15
+
16
+ `capistrano-delayed-job` works only with Capistrano 3!
17
+
18
+ Inspired by
19
+ [capistrano-nginx-unicorn](https://github.com/bruno-/capistrano-nginx-unicorn) and [capistrano-recipes](https://github.com/mattdbridges/capistrano-recipes).
20
+
21
+ ### Installation
22
+
23
+ Add this to `Gemfile`:
24
+
25
+ group :development do
26
+ gem 'capistrano', '~> 3.1'
27
+ gem 'capistrano-delayed-job', '~> 1.0'
28
+ end
29
+
30
+ And then:
31
+
32
+ $ bundle install
33
+
34
+ ### Setup and usage
35
+
36
+ Add this line to `Capfile`
37
+
38
+ require 'capistrano/delayed_job'
39
+
40
+ **Setup task**
41
+
42
+ Make sure the `deploy_to` path exists and has the right privileges on the
43
+ server (i.e. `/var/www/myapp`).<br/>
44
+ Or just install
45
+ [capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)
46
+ plugin and don't think about it.
47
+
48
+ To setup the DelayedJob on the servers with the `delayed_job_server_role` (default `:app`) run:
49
+
50
+ $ bundle exec cap production setup
51
+
52
+ This will generate the init script for delayed job.
53
+
54
+ ### Configuration
55
+
56
+ As described in the Usage section, this plugin works with minimal setup.
57
+ However, configuration is possible.
58
+
59
+ You'll find the options and their defaults below.
60
+
61
+ In order to override the default, put the option in the stage file, for example:
62
+
63
+ # in config/deploy/production.rb
64
+ set :delayed_job_workers, 10
65
+
66
+ Defaults are listed near option name in the first line.
67
+
68
+ * `set :delayed_job_workers` # defaults to 1<br/>
69
+ The number of workers to run on each server.
70
+
71
+ * `set :delayed_job_server_roles, "[:app]"`<br/>
72
+ The roles on which the DelayedJob should run.
73
+
74
+ * `set :delayed_job_service, -> { "delayed_job_#{fetch(:application)}_#{fetch(:stage)}" }`<br/>
75
+ The name of the service that DelayedJob uses.
76
+
77
+ ### Template customization
78
+
79
+ If you want to change default templates, you can generate them using
80
+ `rails generator`:
81
+
82
+ $ bundle exec rails g capistrano:delayed_job:config
83
+
84
+ This will copy default templates to `config/deploy/templates` directory, so you
85
+ can customize them as you like, and capistrano tasks will use this templates
86
+ instead of default.
87
+
88
+ You can also provide path, where to generate templates:
89
+
90
+ $ bundle exec rails g capistrano:delayed_job:config config/templates
91
+
92
+ ### More Capistrano automation?
93
+
94
+ If you'd like to streamline your Capistrano deploys, you might want to check
95
+ these zero-configuration, plug-n-play plugins:
96
+
97
+ - [capistrano-unicorn-nginx](https://github.com/bruno-/capistrano-unicorn-nginx)<br/>
98
+ no-configuration unicorn and nginx setup with sensible defaults
99
+ - [capistrano-postgresql](https://github.com/bruno-/capistrano-postgresql)<br/>
100
+ plugin that automates postgresql configuration and setup
101
+ - [capistrano-rbenv-install](https://github.com/bruno-/capistrano-rbenv-install)<br/>
102
+ would you like Capistrano to install rubies for you?
103
+ - [capistrano-safe-deploy-to](https://github.com/bruno-/capistrano-safe-deploy-to)<br/>
104
+ if you're annoyed that Capistrano does **not** create a deployment path for the
105
+ app on the server (default `/var/www/myapp`), this is what you need!
106
+
107
+ ### Bug reports and pull requests
108
+
109
+ ...are very welcome!
110
+
111
+ ### Thanks
112
+
113
+ [@bruno-](https://github.com/bruno-) - for his
114
+ [capistrano-unicorn-nginx](https://github.com/bruno-/capistrano-unicorn-nginx) plugin on which this
115
+ one is based.
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,35 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'capistrano/delayed_job/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "capistrano-delayed-job"
8
+ gem.version = Capistrano::DelayedJob::VERSION
9
+ gem.authors = ["Ruben Stranders"]
10
+ gem.email = ["r.stranders@gmail.com"]
11
+ gem.description = <<-EOF.gsub(/^\s+/, '')
12
+ Capistrano tasks for automatic and sensible DelayedJob configuration.
13
+
14
+ Enables zero downtime deployments of Rails applications. Configs can be
15
+ copied to the application using generators and easily customized.
16
+
17
+ Works *only* with Capistrano 3+.
18
+
19
+ Inspired by https://github.com/bruno-/capistrano-unicorn-nginx and http://bl.ocks.org/dv/10370719
20
+ EOF
21
+ gem.summary = "Capistrano tasks for automatic and sensible DelayedJob configuration."
22
+ gem.homepage = "https://github.com/capistrano-plugins/capistrano-delayed-job"
23
+
24
+ gem.files = `git ls-files`.split($/)
25
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
26
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
27
+ gem.require_paths = ["lib"]
28
+
29
+ gem.add_dependency "capistrano", ">= 3.1"
30
+ gem.add_dependency "sshkit", ">= 1.2.0"
31
+
32
+ gem.add_dependency "daemons", ">= 1.1"
33
+
34
+ gem.add_development_dependency "rake"
35
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ require 'capistrano/dsl/delayed_job_paths'
2
+ load File.expand_path("../tasks/delayed_job.rake", __FILE__)
@@ -0,0 +1,38 @@
1
+ require 'erb'
2
+
3
+ module Capistrano
4
+ module DelayedJob
5
+ module Helpers
6
+
7
+ def bundle_delayed_job(*args)
8
+ SSHKit::Command.new(:bundle, :exec, "script/delayed_job", args).to_command
9
+ end
10
+
11
+ def dj_template(template_name)
12
+ config_file = "#{fetch(:templates_path)}/#{template_name}"
13
+ # if no customized file, proceed with default
14
+ unless File.exists?(config_file)
15
+ config_file = File.join(File.dirname(__FILE__), "../../generators/capistrano/delayed_job/templates/#{template_name}")
16
+ end
17
+ StringIO.new(ERB.new(File.read(config_file)).result(binding))
18
+ end
19
+
20
+ def file_exists?(path)
21
+ test "[ -e #{path} ]"
22
+ end
23
+
24
+ def deploy_user
25
+ capture :id, '-un'
26
+ end
27
+
28
+ def sudo_upload!(from, to)
29
+ filename = File.basename(to)
30
+ to_dir = File.dirname(to)
31
+ tmp_file = "#{fetch(:tmp_dir)}/#{filename}"
32
+ upload! from, tmp_file
33
+ sudo :mv, tmp_file, to_dir
34
+ end
35
+
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ module Capistrano
2
+ module DelayedJob
3
+ VERSION = "1.0.0"
4
+ end
5
+ end
@@ -0,0 +1,15 @@
1
+ module Capistrano
2
+ module DSL
3
+ module DelayedJobPaths
4
+
5
+ def delayed_job_initd_file
6
+ "/etc/init.d/#{fetch(:delayed_job_service)}"
7
+ end
8
+
9
+ def current_path
10
+ deploy_path.join('current')
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,52 @@
1
+ require 'capistrano/dsl/delayed_job_paths'
2
+ require 'capistrano/delayed_job/helpers'
3
+
4
+ include Capistrano::DelayedJob::Helpers
5
+ include Capistrano::DSL::DelayedJobPaths
6
+
7
+ namespace :load do
8
+ task :defaults do
9
+ set :delayed_job_workers, 1
10
+ set :delayed_job_service, -> { "delayed_job_#{fetch(:application)}_#{fetch(:stage)}" }
11
+
12
+ set :delayed_job_server_roles, [:app]
13
+ end
14
+ end
15
+
16
+ namespace :delayed_job do
17
+
18
+ task :defaults do
19
+ on roles fetch(:delayed_job_server_roles) do
20
+ set :delayed_job_user, fetch(:delayed_job_user, deploy_user)
21
+ end
22
+ end
23
+
24
+ desc 'Setup DelayedJob initializer'
25
+ task :setup do
26
+ on roles fetch(:delayed_job_server_roles) do
27
+ sudo_upload! dj_template('delayed_job_init.erb'), delayed_job_initd_file
28
+ execute :chmod, '+x', delayed_job_initd_file
29
+ sudo 'update-rc.d', '-f', fetch(:delayed_job_service), 'defaults'
30
+ end
31
+ end
32
+
33
+ before :setup, :defaults
34
+
35
+ %w[start stop restart].each do |command|
36
+ desc "#{command} delayed_job"
37
+ task command do
38
+ on roles fetch(:delayed_job_server_roles) do
39
+ sudo :service, "#{fetch(:delayed_job_service)} #{command}"
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ namespace :deploy do
46
+ after :publishing, 'delayed_job:restart'
47
+ end
48
+
49
+ desc 'Server setup tasks'
50
+ task :setup do
51
+ invoke 'delayed_job:setup'
52
+ end
@@ -0,0 +1,9 @@
1
+ To create local delayed_job configuration files call
2
+
3
+ bundle exec rails generate capistrano:delayed_job:config [path]
4
+
5
+ The default path is "config/deploy/templates". You can override it like so:
6
+
7
+ bundle rails generate capistrano:delayed_job:config "config/templates"
8
+
9
+ If you override templates path, don't forget to set "templates_path" variable in your deploy.rb
@@ -0,0 +1,17 @@
1
+ module Capistrano
2
+ module DelayedJob
3
+ module Generators
4
+ class ConfigGenerator < Rails::Generators::Base
5
+ desc "Create local DelayedJob configuration files for customization"
6
+ source_root File.expand_path('../templates', __FILE__)
7
+ argument :templates_path, type: :string,
8
+ default: "config/deploy/templates",
9
+ banner: "path to templates"
10
+
11
+ def copy_template
12
+ copy_file "delayed_job_init.erb", "#{templates_path}/delayed_job_init.erb"
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,48 @@
1
+ #! /bin/sh
2
+
3
+ ### BEGIN INIT INFO
4
+ # Provides: delayed_job
5
+ # Required-Start: $remote_fs $syslog
6
+ # Required-Stop: $remote_fs $syslog
7
+ # Default-Start: 2 3 4 5
8
+ # Default-Stop: 0 1 6
9
+ # Short-Description: Manage delayed jobs for application <%= fetch(:application) %> , environment <%= fetch(:rails_env) %>
10
+ # Description: Start, stop, restart delayed jobs for application <%= fetch(:application) %>, environment <%= fetch(:rails_env) %>
11
+ ### END INIT INFO
12
+
13
+ N=/etc/init.d/delayed_job
14
+ APP_ROOT=<%= current_path %>
15
+ AS_USER=<%= fetch(:delayed_job_user) %>
16
+ service="delayed_job"
17
+
18
+
19
+
20
+ set -e
21
+
22
+ interact() {
23
+ op="$1"
24
+ 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))%>"
26
+
27
+ if [ "$(id -un)" = "$AS_USER" ]; then
28
+ eval $CMD
29
+ else
30
+ su -c "$CMD" - $AS_USER
31
+ fi
32
+ }
33
+
34
+ case "$1" in
35
+ start|stop)
36
+ interact "$1"
37
+ ;;
38
+ reload|restart|force-reload)
39
+ interact "stop"
40
+ sleep 1s
41
+ interact "start"
42
+ ;;
43
+ *)
44
+ usage
45
+ ;;
46
+ esac
47
+
48
+ exit 0
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: capistrano-delayed-job
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Ruben Stranders
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-10-01 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.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: sshkit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 1.2.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: 1.2.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: daemons
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '1.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: |
70
+ Capistrano tasks for automatic and sensible DelayedJob configuration.
71
+ Enables zero downtime deployments of Rails applications. Configs can be
72
+ copied to the application using generators and easily customized.
73
+ Works *only* with Capistrano 3+.
74
+ Inspired by https://github.com/bruno-/capistrano-unicorn-nginx and http://bl.ocks.org/dv/10370719
75
+ email:
76
+ - r.stranders@gmail.com
77
+ executables: []
78
+ extensions: []
79
+ extra_rdoc_files: []
80
+ files:
81
+ - ".gitignore"
82
+ - Gemfile
83
+ - LICENSE.md
84
+ - README.md
85
+ - Rakefile
86
+ - capistrano-delayed-job.gemspec
87
+ - lib/capistrano-delayed-job.rb
88
+ - lib/capistrano/delayed_job.rb
89
+ - lib/capistrano/delayed_job/helpers.rb
90
+ - lib/capistrano/delayed_job/version.rb
91
+ - lib/capistrano/dsl/delayed_job_paths.rb
92
+ - lib/capistrano/tasks/delayed_job.rake
93
+ - lib/generators/capistrano/delayed_job/USAGE.md
94
+ - lib/generators/capistrano/delayed_job/config_generator.rb
95
+ - lib/generators/capistrano/delayed_job/templates/delayed_job_init.erb
96
+ homepage: https://github.com/capistrano-plugins/capistrano-delayed-job
97
+ licenses: []
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubyforge_project:
115
+ rubygems_version: 2.2.2
116
+ signing_key:
117
+ specification_version: 4
118
+ summary: Capistrano tasks for automatic and sensible DelayedJob configuration.
119
+ test_files: []