work_smarter 1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.DS_Store +0 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +26 -0
- data/LICENSE +19 -0
- data/README.markdown +52 -0
- data/Rakefile +2 -0
- data/lib/work_smarter.rb +34 -0
- data/work_smarter.gemspec +21 -0
- metadata +87 -0
data/.DS_Store
ADDED
Binary file
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
work_smarter (1.0)
|
5
|
+
delayed_job (~> 3.0.3)
|
6
|
+
heroku-api (~> 0.3.4)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: http://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (3.2.8)
|
12
|
+
i18n (~> 0.6)
|
13
|
+
multi_json (~> 1.0)
|
14
|
+
delayed_job (3.0.3)
|
15
|
+
activesupport (~> 3.0)
|
16
|
+
excon (0.16.2)
|
17
|
+
heroku-api (0.3.4)
|
18
|
+
excon (~> 0.16.1)
|
19
|
+
i18n (0.6.0)
|
20
|
+
multi_json (1.3.6)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
work_smarter!
|
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2012, Deniz Okcu
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
# Work_smarter
|
2
|
+
|
3
|
+
Work_smarter 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 Work_smarter, 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 Work_smarter to your Gemfile:
|
12
|
+
|
13
|
+
gem "work_smarter"
|
14
|
+
|
15
|
+
Add a `/config/work_smarter.yml` file to your Rails 3 project directory and add the following:
|
16
|
+
|
17
|
+
defaults: &defaults
|
18
|
+
max_workers: 1
|
19
|
+
min_workers: 0
|
20
|
+
application_name: my_heroku_application
|
21
|
+
api_key: your_api_key
|
22
|
+
backgroundjob_name: worker #default should be 'worker'
|
23
|
+
|
24
|
+
development:
|
25
|
+
<<: *defaults
|
26
|
+
|
27
|
+
test:
|
28
|
+
<<: *defaults
|
29
|
+
|
30
|
+
production:
|
31
|
+
<<: *defaults
|
32
|
+
|
33
|
+
# Usage
|
34
|
+
|
35
|
+
Work_smarter is set up to (try and) be as abstract as possible. Queuing a function works similar to delayed_job, just call:
|
36
|
+
|
37
|
+
Work_smarter.queue object, :function, [arg1, arg2]
|
38
|
+
|
39
|
+
For example:
|
40
|
+
|
41
|
+
Work_smarter.queue @image, :resize, {:width => 900, :height => 450}
|
42
|
+
# -- or --
|
43
|
+
Work_smarter.queue UserMailer.send_registration_notification(@user), :deliver
|
44
|
+
|
45
|
+
Work_smarter will automatically add and remove workers as the queue fills up and empties, respectively.
|
46
|
+
|
47
|
+
# Notes
|
48
|
+
|
49
|
+
This is a modified version of the Komodo gem. I changed some behaviour because the Komodo gem used deprecated Heroku commands.
|
50
|
+
I renamed and created this gem because i had namespace issues with a fork of the Komodo gem.
|
51
|
+
|
52
|
+
As stated above, this is really a pre-alpha of Work_smarter, as such the scaling is very basic; Work_smarter just ramps straight up to the user-configured maximum.
|
data/Rakefile
ADDED
data/lib/work_smarter.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
class Work_smarter < 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
|
+
Work_smarter.configure unless defined?(@@config)
|
5
|
+
Delayed::Job.enqueue Work_smarter.new(obj, func, args)
|
6
|
+
end
|
7
|
+
|
8
|
+
# nothing of note here
|
9
|
+
def perform
|
10
|
+
obj.send(func, args)
|
11
|
+
end
|
12
|
+
|
13
|
+
protected
|
14
|
+
# adds a heroku worker, if required
|
15
|
+
def enqueue(job)
|
16
|
+
if Rails.env == "production" && Delayed::Job.count == 0
|
17
|
+
heroku = Heroku::API.new(:api_key => @@config['api_key'])
|
18
|
+
heroku.post_ps_scale(@@config['application_name'], @@config['backgroundjob_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::API.new(:api_key => @@config['api_key'])
|
26
|
+
heroku.post_ps_scale(@@config['application_name'], @@config['backgroundjob_name'], @@config['min_workers'])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
def self.configure
|
32
|
+
@@config = YAML.load_file("#{Rails.root.to_s}/config/work_smarter.yml")[Rails.env]
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "work_smarter"
|
6
|
+
s.version = "1.0"
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Deniz Okcu"]
|
9
|
+
s.email = ["deniz@combinio.com"]
|
10
|
+
s.homepage = "http://github.com/thetron/komodo"
|
11
|
+
s.summary = %q{work_smarter autoscales delayed_job workers on Heroku}
|
12
|
+
s.description = %q{work_smarter is a updated/modified version of the Komodo gem. It allows you to scale on-demand the number of delayed_job workers on Heroku, based on the length of your queue.}
|
13
|
+
|
14
|
+
s.add_dependency 'heroku-api', '~> 0.3.4'
|
15
|
+
s.add_dependency 'delayed_job', '~> 3.0.3'
|
16
|
+
|
17
|
+
s.files = `git ls-files`.split("\n")
|
18
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
19
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
20
|
+
s.require_paths = ["lib"]
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: work_smarter
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '1.0'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Deniz Okcu
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-08-29 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: heroku-api
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 0.3.4
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.3.4
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: delayed_job
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 3.0.3
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 3.0.3
|
46
|
+
description: work_smarter is a updated/modified version of the Komodo gem. It allows
|
47
|
+
you to scale on-demand the number of delayed_job workers on Heroku, based on the
|
48
|
+
length of your queue.
|
49
|
+
email:
|
50
|
+
- deniz@combinio.com
|
51
|
+
executables: []
|
52
|
+
extensions: []
|
53
|
+
extra_rdoc_files: []
|
54
|
+
files:
|
55
|
+
- .DS_Store
|
56
|
+
- Gemfile
|
57
|
+
- Gemfile.lock
|
58
|
+
- LICENSE
|
59
|
+
- README.markdown
|
60
|
+
- Rakefile
|
61
|
+
- lib/work_smarter.rb
|
62
|
+
- work_smarter.gemspec
|
63
|
+
homepage: http://github.com/thetron/komodo
|
64
|
+
licenses: []
|
65
|
+
post_install_message:
|
66
|
+
rdoc_options: []
|
67
|
+
require_paths:
|
68
|
+
- lib
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
+
none: false
|
71
|
+
requirements:
|
72
|
+
- - ! '>='
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
none: false
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 1.8.24
|
84
|
+
signing_key:
|
85
|
+
specification_version: 3
|
86
|
+
summary: work_smarter autoscales delayed_job workers on Heroku
|
87
|
+
test_files: []
|