eycloud-recipe-resque 1.0.3 → 1.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.
data/.gitignore CHANGED
@@ -1,2 +1,3 @@
1
1
  pkg
2
- tmp
2
+ tmp
3
+ Gemfile.lock
data/ChangeLog.md ADDED
@@ -0,0 +1,11 @@
1
+ # ChangeLog
2
+
3
+ ## v1.1.0
4
+
5
+ Fixes based on testing with [todo_with_resque](https://github.com/engineyard/todo_with_resque) Rails 3 app.
6
+
7
+ Most important change: Instructions on how to restart resque after deploy!
8
+
9
+ ## v1.0.0
10
+
11
+ First release based on various Resque projects found.
data/README.md CHANGED
@@ -1,16 +1,26 @@
1
+
1
2
  # Resque recipe for EY Cloud
2
3
 
3
- Resque is a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later.
4
+ [Resque](https://github.com/defunkt/resque) is a Redis-backed Ruby library for creating background jobs, placing those jobs on multiple queues, and processing them later.
4
5
 
5
- This recipe will setup `resque` on a Solo instance environment or on named Utility instances in a cluster environment.
6
+ This recipe will setup Resque on a Solo instance environment or on named Utility instances in a cluster environment.
6
7
 
7
- Name your Utility instances with prefixes: `resque`. For example, `resque`, or `resque123`. Naming them all `resque` works just fine.
8
+ ## Installation
8
9
 
9
- This recipe assumes that redis is running within the environment. Fortunately, it is. By default EY Cloud runs redis on your `solo` or `db_master` instance. Optionally, this recipe will use a custom `redis` utility instance that you might have in your environment. It's clever like that.
10
+ 1. Install the recipe
11
+ 2. Add a deploy hook to restart resque workers after the application restarts
12
+ 3. Name all utility instances `resque`.
10
13
 
11
- ## Installation
14
+ ```ruby
15
+ # deploy/after_restart.rb
16
+ on_utilities(:resque) do
17
+ node[:applications].each do |app_name, data|
18
+ sudo 'echo "sleep 20 && monit -g resque_#{app_name} restart all" | at now'
19
+ end
20
+ end
21
+ ```
12
22
 
13
- ## Simple Installation
23
+ ### Simple Installation
14
24
 
15
25
  To add this recipe to your collection of recipes, or as your first recipe, you can use the helpful `ey-recipes` command line tool:
16
26
 
@@ -27,7 +37,7 @@ If you want to have your recipes run during deploy (rather than the separate `ey
27
37
  git add .; git commit -m "added delayed job recipe"; git push origin master
28
38
  ey deploy
29
39
 
30
- ## Manual Installation
40
+ ### Manual Installation
31
41
 
32
42
  Clone/copy this repository into a `cookbooks/resque` folder (such that you have a `cookbooks/resque/recipes/default.rb` file). This recipe must be installed as `resque` and not `eycloud-recipe-resque` or anything fancy.
33
43
 
@@ -41,3 +51,68 @@ repository.
41
51
  Then to upload and apply to EY Cloud for a given environment:
42
52
 
43
53
  ey recipes upload --apply -e target-environment
54
+
55
+ ### Rails 3
56
+
57
+ To ensure that Resque can discover where Redis installed, create a `config/initializers/resque.rb` file:
58
+
59
+ ```ruby
60
+ resque_yml = File.expand_path('../../resque.yml', __FILE__)
61
+ if File.exist?(resque_yml)
62
+ Resque.redis = YAML.load_file(resque_yml)["redis_uri"]
63
+ end
64
+ ```
65
+
66
+ ## How do I get some Resque workers?
67
+
68
+ Resque workers can process 1 task/job at a time.
69
+
70
+ If you have a solo instance, then one Resque worker is provisioned.
71
+
72
+ If you have one or more app instances, then no Resque workers are provisioned. Instead, add dedicated utility instances to provision Resque workers.
73
+
74
+ Name your Utility instances `resque`.
75
+
76
+ ## How many Resque workers will I get?
77
+
78
+ All the available memory of an instance is used for Resque workers, with 300Mb set aside for operating system tasks. Resque workers are allocated 300Mb each.
79
+
80
+ As above, solo instances of any time have 1 worker.
81
+
82
+ For utility instances you get approximately the following number of workers:
83
+
84
+ * Small -> 4 workers within 1.7 GB
85
+ * Large -> 24 workers within 7.5 GB
86
+ * Extra Large -> 49 workers within 15 GB
87
+
88
+ * High Memory Extra Large -> 55 workers within 17.1 GB
89
+ * High-Memory Double Extra Large -> 113 workers within 34.2 GB
90
+ * High-Memory Quadruple Extra Large -> 213 workers within 64.4 GB
91
+
92
+ * High-CPU Medium -> 4 workers within 1.7 GB
93
+ * High-CPU Extra Large -> 22 workers within 7 GB
94
+
95
+ ## How do I setup Redis?
96
+
97
+ This recipe assumes that Redis is running within the environment. Fortunately, it is. Redis is automatically running on all Engine Yard Cloud environments.
98
+
99
+ If you have a dedicate Redis instance called `redis` then this recipe will discover and use that version of Redis.
100
+
101
+ ## How do I use resque-web?
102
+
103
+ In a Rails 3 app, you can access "resque-web" via your normal Rails app using mounted apps.
104
+
105
+ As a very simple, moderately secure method, add the following into your `routes.rb` routes:
106
+
107
+ ```ruby
108
+ require "resque/server"
109
+ mount Resque::Server.new, :at => "/resque/34257893542"
110
+ ```
111
+
112
+ For more security, consider the ideas in this [gist](https://gist.github.com/1575082).
113
+
114
+ ## Helpers
115
+
116
+ * `resque_instances` - returns list of instances that have resque running on them
117
+ * `resque_instance?` - does this instance have resque running on it?
118
+
@@ -1,7 +1,7 @@
1
1
  # -*- encoding: utf-8 -*-
2
2
  $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
- version = "1.0.3" # get from metadata.json or .rb
4
+ version = "1.1.0" # get from metadata.json or .rb
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "eycloud-recipe-resque"
@@ -0,0 +1,21 @@
1
+ class Chef
2
+ class Recipe
3
+ # Return which instance is to have redis installed on it
4
+ # This is determind as follows:
5
+ # 1. A utility prefixed with 'resque'
6
+ # 2. A solo
7
+ # Returns array of hash of instance data, including { "id" => "i-123456", }
8
+ def resque_instances
9
+ @resque_instances ||= node[:engineyard][:environment][:instances].find do |x|
10
+ x[:role] == "solo" || node[:instance_role] == "eylocal" ||
11
+ (node[:role] == "util" && node[:name] =~ /^(resque)/)
12
+ end
13
+ end
14
+
15
+ # Does this instance run resque?
16
+ def resque_instance?
17
+ node[:instance_role] == "solo" || node[:instance_role] == "eylocal" ||
18
+ (node[:instance_role] == "util" && node[:name] =~ /^(resque)/)
19
+ end
20
+ end
21
+ end
@@ -1,6 +1,8 @@
1
1
  class Chef
2
2
  class Recipe
3
- def get_resque_worker_count
3
+ def get_resque_worker_count
4
+ return 1 if node[:instance_role] == 'solo' || node[:instance_role] == 'eylocal'
5
+
4
6
  # $ sudo cat /proc/meminfo
5
7
  # MemTotal: 1759228 kB
6
8
  # ...
@@ -11,7 +13,6 @@ class Chef
11
13
  # in other words, if all workers on the instance are running jobs, there should
12
14
  # be memory left over
13
15
  result = (mem_total_mb - node[:worker_memory].to_i) / node[:worker_memory].to_i
14
- result /= 2 if node[:instance_role] == 'solo' || node[:instance_role] == 'eylocal'
15
16
  result
16
17
  end
17
18
  end
data/metadata.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "license": "MIT",
3
3
  "maintainer": "Engine Yard LLC",
4
4
  "maintainer_email": "drnic@engineyard.com",
5
- "version": "1.0.3",
5
+ "version": "1.1.0",
6
6
  "description": "Resque for EY Cloud",
7
7
  "name": "resque",
8
8
  "attributes": {
data/metadata.rb CHANGED
@@ -3,5 +3,5 @@ description "Resque for EY Cloud"
3
3
  long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
4
4
  maintainer "Engine Yard LLC"
5
5
  maintainer_email "drnic@engineyard.com"
6
- version "1.0.3"
6
+ version "1.1.0"
7
7
  depends "cronjobs"
data/recipes/configure.rb CHANGED
@@ -3,8 +3,7 @@
3
3
  # Recipe:: configure
4
4
  #
5
5
 
6
- if node[:instance_role] == "solo" || node[:instance_role] == "eylocal" ||
7
- (node[:instance_role] == "util" && node[:name] =~ /^(resque)/)
6
+ if resque_instance?
8
7
  resque_workers_count = get_resque_worker_count()
9
8
 
10
9
  directory "/tmp/resque_ttls" do
data/recipes/install.rb CHANGED
@@ -3,8 +3,7 @@
3
3
  # Recipe:: install
4
4
  #
5
5
 
6
- if node[:instance_role] == "solo" || node[:instance_role] == "eylocal" ||
7
- (node[:instance_role] == "util" && node[:name] =~ /^(resque)/)
6
+ if resque_instance?
8
7
 
9
8
  file "/usr/local/bin/resque_kill_stale" do
10
9
  owner 'root'
data/recipes/restart.rb CHANGED
@@ -3,15 +3,14 @@
3
3
  # Recipe:: default
4
4
  #
5
5
 
6
- if node[:instance_role] == "solo" || node[:instance_role] == "eylocal" ||
7
- (node[:instance_role] == "util" && node[:name] =~ /^(resque)/)
6
+ if resque_instance?
8
7
  node[:applications].each do |app_name, data|
9
8
  execute "ensure-resque-is-setup-with-monit" do
10
9
  command %Q{monit reload}
11
10
  end
12
11
 
13
12
  execute "restart-resque" do
14
- command %Q{echo "sleep 20 && monit -g #{app_name}_resque restart all" | at now }
13
+ command %Q{echo "sleep 20 && monit -g resque_#{app_name} restart all" | at now }
15
14
  end
16
15
  end
17
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eycloud-recipe-resque
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-17 00:00:00.000000000 Z
12
+ date: 2012-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eycloud-helper-cronjobs
16
- requirement: &70200712055240 !ruby/object:Gem::Requirement
16
+ requirement: &70279512580460 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70200712055240
24
+ version_requirements: *70279512580460
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70200712098120 !ruby/object:Gem::Requirement
27
+ requirement: &70279512579700 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70200712098120
35
+ version_requirements: *70279512579700
36
36
  description: Resque for EY Cloud
37
37
  email:
38
38
  - drnicwilliams@gmail.com
@@ -42,8 +42,8 @@ extra_rdoc_files: []
42
42
  files:
43
43
  - .DS_Store
44
44
  - .gitignore
45
+ - ChangeLog.md
45
46
  - Gemfile
46
- - Gemfile.lock
47
47
  - README.md
48
48
  - Rakefile
49
49
  - attributes/default.rb
@@ -51,6 +51,7 @@ files:
51
51
  - files/default/resque
52
52
  - files/default/resque-web
53
53
  - files/default/resque_kill_stale
54
+ - libraries/find_resque_instances.rb
54
55
  - libraries/get_resque_worker_count.rb
55
56
  - metadata.json
56
57
  - metadata.rb
@@ -76,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
76
77
  version: '0'
77
78
  segments:
78
79
  - 0
79
- hash: -116094860101360678
80
+ hash: -3022652905535487665
80
81
  required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  none: false
82
83
  requirements:
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  version: '0'
86
87
  segments:
87
88
  - 0
88
- hash: -116094860101360678
89
+ hash: -3022652905535487665
89
90
  requirements: []
90
91
  rubyforge_project:
91
92
  rubygems_version: 1.8.17
data/Gemfile.lock DELETED
@@ -1,18 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- eycloud-recipe-resque (1.0.3)
5
- eycloud-helper-cronjobs
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- eycloud-helper-cronjobs (1.0.1)
11
- rake (0.9.2.2)
12
-
13
- PLATFORMS
14
- ruby
15
-
16
- DEPENDENCIES
17
- eycloud-recipe-resque!
18
- rake