komodo 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/README.markdown +48 -0
- data/Rakefile +2 -0
- data/komodo.gemspec +24 -0
- data/lib/komodo.rb +34 -0
- data/lib/komodo/version.rb +3 -0
- metadata +105 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Komodo
|
2
|
+
|
3
|
+
Komodo is a simple wrapper for Delayed::Job that helps you autoscale workers when deployed on [Heroku](http://www.heroku.com). It came about for an upcoming project of [ours](http://www.involved.com.au), which only required the occasional background worker.
|
4
|
+
|
5
|
+
__Please note:__ This is still very early days for Komodo, there's very little (read: zero) test coverage - and we've yet to even put it into production.
|
6
|
+
|
7
|
+
# Configuration
|
8
|
+
|
9
|
+
Setup delayed_job as per [the instructions](http://docs.heroku.com/delayed-job) on Heroku.
|
10
|
+
|
11
|
+
Add Komodo to your Gemfile:
|
12
|
+
|
13
|
+
gem "komodo"
|
14
|
+
|
15
|
+
Add a `/config/komodo.yml` file to your Rails 3 project directory and add the following:
|
16
|
+
|
17
|
+
defaults: &defaults
|
18
|
+
max_workers: 1
|
19
|
+
application_name: my_heroku_application
|
20
|
+
username: email@myherokuapplication.com
|
21
|
+
password: sekrit
|
22
|
+
|
23
|
+
development:
|
24
|
+
<<: *defaults
|
25
|
+
|
26
|
+
test:
|
27
|
+
<<: *defaults
|
28
|
+
|
29
|
+
production:
|
30
|
+
<<: *defaults
|
31
|
+
|
32
|
+
# Usage
|
33
|
+
|
34
|
+
Komodo is set up to (try and) be as abstract as possible. Queuing a function works similar to delayed_job, just call:
|
35
|
+
|
36
|
+
Komodo.queue object, :function, [arg1, arg2]
|
37
|
+
|
38
|
+
For example:
|
39
|
+
|
40
|
+
Komodo.queue @image, :resize, {:width => 900, :height => 450}
|
41
|
+
# -- or --
|
42
|
+
Komodo.queue UserMailer.send_registration_notification(@user), :deliver
|
43
|
+
|
44
|
+
Komodo will automatically add and remove workers as the queue fills up and empties, respectively.
|
45
|
+
|
46
|
+
# Notes
|
47
|
+
|
48
|
+
As stated above, this is really a pre-alpha of Komodo, as such the scaling is very basic; Komodo just ramps straight up to the user-configured maximum.
|
data/Rakefile
ADDED
data/komodo.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "komodo/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "komodo"
|
7
|
+
s.version = Komodo::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Nicholas Bruning"]
|
10
|
+
s.email = ["nicholas@bruning.com.au"]
|
11
|
+
s.homepage = "http://github.com/thetron/komodo"
|
12
|
+
s.summary = %q{Komodo helps you autoscale delayed_job workers on Heroku}
|
13
|
+
s.description = %q{Komodo is a simple wrapper that allows you to scale on-demand the number of delayed_job workers on Heroku, based on the length of your queue.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "komodo"
|
16
|
+
|
17
|
+
s.add_dependency 'heroku', '~> 1.14.6'
|
18
|
+
s.add_dependency 'delayed_job', '~> 2.1.2'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
s.require_paths = ["lib"]
|
24
|
+
end
|
data/lib/komodo.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class Komodo < Struct.new(:obj, :func, :args)
|
2
|
+
# delayed_job wrapper, creates a new monitored job and queues it
|
3
|
+
def self.queue(obj, func, args = [])
|
4
|
+
Komodo.configure unless defined?(@@config)
|
5
|
+
Delayed::Job.enqueue MonitoredJob.new(obj, func, args)
|
6
|
+
end
|
7
|
+
|
8
|
+
protected
|
9
|
+
# nothing of note here
|
10
|
+
def perform
|
11
|
+
obj.send(func, args)
|
12
|
+
end
|
13
|
+
|
14
|
+
# adds a heroku worker, if required
|
15
|
+
def enqueue(job)
|
16
|
+
if Rails.env == "production" && Delayed::Job.count == 0
|
17
|
+
heroku = Heroku::Client.new(@@config['username'], @@config['password'])
|
18
|
+
heroku.set_workers(@@config['application_name'], @@config['max_workers'])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
# removes heroku workers if queue is empty, or falling below max_workers
|
23
|
+
def after(job)
|
24
|
+
if Rails.env == "production" && Delayed::Job.count == 0
|
25
|
+
heroku = Heroku::Client.new(@@config['username'], @@config['password'])
|
26
|
+
heroku.set_workers(@@config['application_name'], 0)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def self.configure
|
32
|
+
@@config = YAML.load_file("#{Rails.root.to_s}/config/komodo.yml")[Rails.env]
|
33
|
+
end
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,105 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: komodo
|
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
|
+
- Nicholas Bruning
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-12-07 00:00:00 +11:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: heroku
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 35
|
30
|
+
segments:
|
31
|
+
- 1
|
32
|
+
- 14
|
33
|
+
- 6
|
34
|
+
version: 1.14.6
|
35
|
+
type: :runtime
|
36
|
+
version_requirements: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: delayed_job
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
hash: 15
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 1
|
49
|
+
- 2
|
50
|
+
version: 2.1.2
|
51
|
+
type: :runtime
|
52
|
+
version_requirements: *id002
|
53
|
+
description: Komodo is a simple wrapper that allows you to scale on-demand the number of delayed_job workers on Heroku, based on the length of your queue.
|
54
|
+
email:
|
55
|
+
- nicholas@bruning.com.au
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files: []
|
61
|
+
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- README.markdown
|
66
|
+
- Rakefile
|
67
|
+
- komodo.gemspec
|
68
|
+
- lib/komodo.rb
|
69
|
+
- lib/komodo/version.rb
|
70
|
+
has_rdoc: true
|
71
|
+
homepage: http://github.com/thetron/komodo
|
72
|
+
licenses: []
|
73
|
+
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
|
77
|
+
require_paths:
|
78
|
+
- lib
|
79
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
hash: 3
|
85
|
+
segments:
|
86
|
+
- 0
|
87
|
+
version: "0"
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
hash: 3
|
94
|
+
segments:
|
95
|
+
- 0
|
96
|
+
version: "0"
|
97
|
+
requirements: []
|
98
|
+
|
99
|
+
rubyforge_project: komodo
|
100
|
+
rubygems_version: 1.3.7
|
101
|
+
signing_key:
|
102
|
+
specification_version: 3
|
103
|
+
summary: Komodo helps you autoscale delayed_job workers on Heroku
|
104
|
+
test_files: []
|
105
|
+
|