heroku_dj_auto_scale 0.0.1
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 +3 -0
- data/Gemfile +7 -0
- data/Rakefile +2 -0
- data/heroku_dj_auto_scale.gemspec +22 -0
- data/lib/heroku_dj_auto_scale/version.rb +3 -0
- data/lib/heroku_dj_auto_scale.rb +59 -0
- metadata +92 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/heroku_dj_auto_scale/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "heroku_dj_auto_scale"
|
6
|
+
s.version = HerokuDjAutoScale::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Joel Basson"]
|
9
|
+
s.email = []
|
10
|
+
s.homepage = "http://rubygems.org/gems/heroku_dj_auto_scale"
|
11
|
+
s.summary = %q{Allows auto-scaling of delayed job workers in Heroku}
|
12
|
+
s.description = %q{Allows auto-scaling of delayed job workers in Heroku}
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "heroku_dj_auto_scale"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
21
|
+
s.require_path = 'lib'
|
22
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'heroku'
|
2
|
+
|
3
|
+
module HerokuDjAutoScale
|
4
|
+
module Scaler
|
5
|
+
class << self
|
6
|
+
@@heroku = Heroku::Client.new(ENV['HEROKU_USER'], ENV['HEROKU_PASS']) if ENV['USE_HEROKU_SCALING'] == 'true'
|
7
|
+
|
8
|
+
def workers
|
9
|
+
ENV['USE_HEROKU_SCALING'] == 'true' ? @@heroku.info(ENV['HEROKU_APP'])[:workers].to_i : 1
|
10
|
+
end
|
11
|
+
|
12
|
+
def workers=(qty)
|
13
|
+
@@heroku.set_workers(ENV['HEROKU_APP'], qty) if ENV['USE_HEROKU_SCALING'] == 'true'
|
14
|
+
end
|
15
|
+
|
16
|
+
def job_count
|
17
|
+
Delayed::Job.all.count.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def job_count_unlocked
|
21
|
+
Delayed::Job.where(:locked_by => nil).count.to_i
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def completed(*args)
|
27
|
+
# Nothing fancy, just shut everything down if we have no jobs
|
28
|
+
Scaler.workers = 0 if Scaler.job_count.zero?
|
29
|
+
end
|
30
|
+
|
31
|
+
def enqueue(*args)
|
32
|
+
[
|
33
|
+
{
|
34
|
+
:workers => 1, # This many workers
|
35
|
+
:job_count => 1 # For this many jobs or more, until the next level
|
36
|
+
},
|
37
|
+
{
|
38
|
+
:workers => 1,
|
39
|
+
:job_count => 400
|
40
|
+
},
|
41
|
+
{
|
42
|
+
:workers => 1,
|
43
|
+
:job_count => 2500
|
44
|
+
}
|
45
|
+
].reverse_each do |scale_info|
|
46
|
+
# Run backwards so it gets set to the highest value first
|
47
|
+
# Otherwise if there were 70 jobs, it would get set to 1, then 2, then 3, etc
|
48
|
+
|
49
|
+
# If we have a job count greater than or equal to the job limit for this scale info
|
50
|
+
if Scaler.job_count >= scale_info[:job_count]
|
51
|
+
# Set the number of workers unless they are already set to a level we want. Don't scale down here!
|
52
|
+
if Scaler.workers <= scale_info[:workers]
|
53
|
+
Scaler.workers = scale_info[:workers]
|
54
|
+
end
|
55
|
+
break # We've set or ensured that the worker count is high enough
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: heroku_dj_auto_scale
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Joel Basson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-14 00:00:00 +02:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: bundler
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 15424057
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 0
|
33
|
+
- 0
|
34
|
+
- rc
|
35
|
+
- 6
|
36
|
+
version: 1.0.0.rc.6
|
37
|
+
type: :development
|
38
|
+
version_requirements: *id001
|
39
|
+
description: Allows auto-scaling of delayed job workers in Heroku
|
40
|
+
email: []
|
41
|
+
|
42
|
+
executables: []
|
43
|
+
|
44
|
+
extensions: []
|
45
|
+
|
46
|
+
extra_rdoc_files: []
|
47
|
+
|
48
|
+
files:
|
49
|
+
- .gitignore
|
50
|
+
- Gemfile
|
51
|
+
- Rakefile
|
52
|
+
- heroku_dj_auto_scale.gemspec
|
53
|
+
- lib/heroku_dj_auto_scale.rb
|
54
|
+
- lib/heroku_dj_auto_scale/version.rb
|
55
|
+
has_rdoc: true
|
56
|
+
homepage: http://rubygems.org/gems/heroku_dj_auto_scale
|
57
|
+
licenses: []
|
58
|
+
|
59
|
+
post_install_message:
|
60
|
+
rdoc_options: []
|
61
|
+
|
62
|
+
require_paths:
|
63
|
+
- lib
|
64
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 23
|
79
|
+
segments:
|
80
|
+
- 1
|
81
|
+
- 3
|
82
|
+
- 6
|
83
|
+
version: 1.3.6
|
84
|
+
requirements: []
|
85
|
+
|
86
|
+
rubyforge_project: heroku_dj_auto_scale
|
87
|
+
rubygems_version: 1.3.7
|
88
|
+
signing_key:
|
89
|
+
specification_version: 3
|
90
|
+
summary: Allows auto-scaling of delayed job workers in Heroku
|
91
|
+
test_files: []
|
92
|
+
|