sklaventreiber 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/.DS_Store +0 -0
- data/.gitignore +21 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +30 -0
- data/LICENSE +22 -0
- data/Procfile +2 -0
- data/README.md +88 -0
- data/Rakefile +20 -0
- data/lib/.DS_Store +0 -0
- data/lib/sklaventreiber.rb +15 -0
- data/lib/sklaventreiber/.DS_Store +0 -0
- data/lib/sklaventreiber/config.rb +11 -0
- data/lib/sklaventreiber/herokuconnection.rb +62 -0
- data/lib/sklaventreiber/mock.rb +17 -0
- data/lib/sklaventreiber/tasks.rb +11 -0
- data/lib/sklaventreiber/version.rb +3 -0
- data/lib/sklaventreiber/worker.rb +78 -0
- data/lib/sklaventreiber/workerplugin.rb +58 -0
- data/navvy.proc +1 -0
- data/sklaventreiber.gemspec +26 -0
- data/test.proc +1 -0
- data/test/.DS_Store +0 -0
- data/test/job.rb +21 -0
- data/test/test_sklaventreiber_plugin.rb +132 -0
- metadata +145 -0
data/.DS_Store
ADDED
|
Binary file
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
sklaventreiber (0.0.1)
|
|
5
|
+
heroku-api
|
|
6
|
+
sequel
|
|
7
|
+
|
|
8
|
+
GEM
|
|
9
|
+
remote: https://rubygems.org/
|
|
10
|
+
specs:
|
|
11
|
+
excon (0.16.10)
|
|
12
|
+
foreman (0.60.2)
|
|
13
|
+
thor (>= 0.13.6)
|
|
14
|
+
heroku-api (0.3.7)
|
|
15
|
+
excon (~> 0.16.10)
|
|
16
|
+
navvy (0.3.2)
|
|
17
|
+
pg (0.14.1)
|
|
18
|
+
rake (0.9.2.2)
|
|
19
|
+
sequel (3.42.0)
|
|
20
|
+
thor (0.16.0)
|
|
21
|
+
|
|
22
|
+
PLATFORMS
|
|
23
|
+
ruby
|
|
24
|
+
|
|
25
|
+
DEPENDENCIES
|
|
26
|
+
foreman
|
|
27
|
+
navvy
|
|
28
|
+
pg
|
|
29
|
+
rake
|
|
30
|
+
sklaventreiber!
|
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Nikolaus Piccolotto
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
6
|
+
a copy of this software and associated documentation files (the
|
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
11
|
+
the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be
|
|
14
|
+
included in all copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Procfile
ADDED
data/README.md
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Sklaventreiber
|
|
2
|
+
|
|
3
|
+
Sklaventreiber is a Ruby gem that manages your worker when you're using [Navvy](https://github.com/jeffkreeftmeijer/navvy) and [Sequel](http://sequel.rubyforge.org/) with [Heroku](http://heroku.com). It hires one if there are jobs to be done and fires him if not.
|
|
4
|
+
|
|
5
|
+
Slaventreiber can either be used as a [Sequel plugin](http://sequel.rubyforge.org/rdoc/files/doc/model_hooks_rdoc.html) or as a worker process.
|
|
6
|
+
|
|
7
|
+
*Sklaventreiber*, der (eng.: slave driver): German expression for a overly demanding boss that ignores his employees' health and happiness.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
Sklaventreiber is **NOT** usable as of now, because it still requires a custom version of Navvy. This is going to change.
|
|
12
|
+
|
|
13
|
+
### Plugin
|
|
14
|
+
|
|
15
|
+
Add this line to your application's Gemfile:
|
|
16
|
+
|
|
17
|
+
gem 'sklaventreiber'
|
|
18
|
+
|
|
19
|
+
And then execute:
|
|
20
|
+
|
|
21
|
+
$ bundle
|
|
22
|
+
|
|
23
|
+
Or install it yourself as:
|
|
24
|
+
|
|
25
|
+
$ gem install sklaventreiber
|
|
26
|
+
|
|
27
|
+
### Worker
|
|
28
|
+
|
|
29
|
+
Add these lines to your Rakefile:
|
|
30
|
+
|
|
31
|
+
require "sklaventreiber"
|
|
32
|
+
require "sklaventreiber/tasks"
|
|
33
|
+
|
|
34
|
+
## Usage
|
|
35
|
+
|
|
36
|
+
Sklaventreiber expects a few environment variables to be set.
|
|
37
|
+
|
|
38
|
+
# either this
|
|
39
|
+
HEROKU_API_KEY=< your heroku api key >
|
|
40
|
+
# or this
|
|
41
|
+
HEROKU_USERNAME=< your heroku username >
|
|
42
|
+
HEROKU_PASSWORD=< your heroku password >
|
|
43
|
+
# but always this
|
|
44
|
+
HEROKU_APP=< your heroku app name >
|
|
45
|
+
|
|
46
|
+
You can use either the API key or the username/password combination. Sklaventreiber will try to connect via the API key and fall back to username/password if it's not possible.
|
|
47
|
+
|
|
48
|
+
Sklaventreiber logs to standard output via ``puts``. If you don't like that you can turn it off.
|
|
49
|
+
|
|
50
|
+
SKLAVENTREIBER_LOG="false"
|
|
51
|
+
|
|
52
|
+
### Plugin
|
|
53
|
+
|
|
54
|
+
There is nothing to be done other than adding Sklaventreiber to your Gemfile. It hooks automatically into ``Navvy::Job``. Just make sure you require it after Navvy and Sequel.
|
|
55
|
+
|
|
56
|
+
require "sequel"
|
|
57
|
+
require "navvy"
|
|
58
|
+
require "navvy/job/sequelhook"
|
|
59
|
+
require "sklaventreiber"
|
|
60
|
+
|
|
61
|
+
### Worker
|
|
62
|
+
|
|
63
|
+
Execute the following to start Sklaventreiber as a worker:
|
|
64
|
+
|
|
65
|
+
rake sklaventreiber:work
|
|
66
|
+
|
|
67
|
+
Sklaventreiber checks every 10 seconds if it needs to scale your Heroku worker. For a custom interval set
|
|
68
|
+
|
|
69
|
+
SKLAVENTREIBER_SLEEPTIME=< your custom interval in seconds >
|
|
70
|
+
|
|
71
|
+
## Contributing
|
|
72
|
+
|
|
73
|
+
For development you should also set these environment variables:
|
|
74
|
+
|
|
75
|
+
SKLAVENTREIBER_MOCK=< if heroku-api should run in mock mode >
|
|
76
|
+
DATABASE_URL=< database://user:password@host:port/database_name >
|
|
77
|
+
|
|
78
|
+
Then:
|
|
79
|
+
|
|
80
|
+
1. Fork it
|
|
81
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
82
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
83
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
84
|
+
5. Create new Pull Request
|
|
85
|
+
|
|
86
|
+
## Testing the worker
|
|
87
|
+
|
|
88
|
+
I tried to start all three necessary processes (Navvy, Sklaventreiber, test code) using ``foreman``. Because my test code contained a few ``sleep`` statements to wait for Navvy and Sklaventreiber, foreman halted all three processes instead of only the test code. I honestly have no idea why. Testing the worker was then done using three different terminals for the processes and looking if they behave as expected.
|
data/Rakefile
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
#!/usr/bin/env rake
|
|
2
|
+
require "bundler/gem_tasks"
|
|
3
|
+
require 'rake/testtask'
|
|
4
|
+
|
|
5
|
+
Rake::TestTask.new do |t|
|
|
6
|
+
t.libs << 'test'
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
require "sequel"
|
|
11
|
+
|
|
12
|
+
Sequel::Model.db = Sequel.connect( ENV['DATABASE_URL'] )
|
|
13
|
+
|
|
14
|
+
require "navvy"
|
|
15
|
+
require "navvy/job/sequel"
|
|
16
|
+
require "navvy/tasks"
|
|
17
|
+
|
|
18
|
+
require "sklaventreiber/worker"
|
|
19
|
+
require "sklaventreiber/tasks"
|
|
20
|
+
require "sklaventreiber/mock"
|
data/lib/.DS_Store
ADDED
|
Binary file
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require "sklaventreiber/workerplugin"
|
|
2
|
+
|
|
3
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
4
|
+
puts "Sklaventreiber tries to hook into Navvy::Job."
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
begin
|
|
8
|
+
Navvy::Job.plugin( Sklaventreiber::WorkerPlugin )
|
|
9
|
+
rescue StandardError => e
|
|
10
|
+
# Sklaventreiber shall be a worker
|
|
11
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
12
|
+
puts e.to_s
|
|
13
|
+
puts "Sklaventreiber was unsuccessful, expects to be used as a worker instead."
|
|
14
|
+
end
|
|
15
|
+
end
|
|
Binary file
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module Sklaventreiber
|
|
2
|
+
class Config
|
|
3
|
+
HEROKU_USERNAME = ENV['HEROKU_USERNAME']
|
|
4
|
+
HEROKU_PASSWORD = ENV['HEROKU_PASSWORD']
|
|
5
|
+
HEROKU_API_KEY = ENV['HEROKU_API_KEY']
|
|
6
|
+
HEROKU_APP = ENV['HEROKU_APP']
|
|
7
|
+
SKLAVENTREIBER_SLEEPTIME = ENV['SKLAVENTREIBER_SLEEPTIME'] == nil ? 10 : Integer( ENV['SKLAVENTREIBER_SLEEPTIME'] )
|
|
8
|
+
SKLAVENTREIBER_MOCK = ENV['SKLAVENTREIBER_MOCK'] == "true"
|
|
9
|
+
SKLAVENTREIBER_LOG = ENV['SKLAVENTREIBER_LOG'] == "true"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
require "sklaventreiber/config"
|
|
2
|
+
require "heroku-api"
|
|
3
|
+
|
|
4
|
+
module Sklaventreiber
|
|
5
|
+
class HerokuConnection
|
|
6
|
+
@@api = nil
|
|
7
|
+
@@worker = 0
|
|
8
|
+
|
|
9
|
+
# singleton for api connection
|
|
10
|
+
def self.init
|
|
11
|
+
# if there is no api connection yet
|
|
12
|
+
if @@api == nil
|
|
13
|
+
# then init api connection
|
|
14
|
+
if Sklaventreiber::Config::HEROKU_API_KEY != nil
|
|
15
|
+
@@api = Heroku::API.new( :api_key => Sklaventreiber::Config::HEROKU_API_KEY, :mock => Sklaventreiber::Config::SKLAVENTREIBER_MOCK )
|
|
16
|
+
else
|
|
17
|
+
@@api = Heroku::API.new( :username => Sklaventreiber::Config::HEROKU_USERNAME, :password => Sklaventreiber::Config::HEROKU_PASSWORD, :mock => Sklaventreiber::Config::SKLAVENTREIBER_MOCK )
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# then init worker count
|
|
21
|
+
@@worker = 0
|
|
22
|
+
response = @@api.get_ps( Sklaventreiber::Config::HEROKU_APP )
|
|
23
|
+
if ( response.status == 200 )
|
|
24
|
+
processes = response.body
|
|
25
|
+
processes.each do |proc|
|
|
26
|
+
if ( proc["process"].start_with?( "worker") )
|
|
27
|
+
@@worker = @@worker + 1
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
32
|
+
puts "Sklaventreiber: Worker count at start = " + @@worker.to_s
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def self.hire_worker
|
|
38
|
+
@@worker = 1
|
|
39
|
+
@@api.post_ps_scale( Sklaventreiber::Config::HEROKU_APP, "worker", @@worker.to_s )
|
|
40
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
41
|
+
puts "Sklaventreiber hired a worker."
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def self.fire_worker
|
|
46
|
+
@@worker = 0
|
|
47
|
+
@@api.post_ps_scale( Sklaventreiber::Config::HEROKU_APP, "worker", @@worker.to_s )
|
|
48
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
49
|
+
puts "Sklaventreiber fired the worker."
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.is_fired?
|
|
54
|
+
return @@worker == 0
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
def self.is_hired?
|
|
58
|
+
return @@worker == 1
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
end
|
|
62
|
+
end
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
module Sklaventreiber
|
|
2
|
+
|
|
3
|
+
class Mock
|
|
4
|
+
|
|
5
|
+
def initialize()
|
|
6
|
+
puts "mock created"
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def self.mock_method( sleeping_time )
|
|
10
|
+
puts "mock doing work for " + sleeping_time.to_s + " seconds"
|
|
11
|
+
sleep( sleeping_time )
|
|
12
|
+
puts "work finished"
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
end
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
require "sklaventreiber/config"
|
|
2
|
+
require "sklaventreiber/herokuconnection"
|
|
3
|
+
require "navvy"
|
|
4
|
+
require "navvy/job/sequel"
|
|
5
|
+
|
|
6
|
+
module Sklaventreiber
|
|
7
|
+
|
|
8
|
+
class Worker
|
|
9
|
+
|
|
10
|
+
##
|
|
11
|
+
# Start Sklaventreiber
|
|
12
|
+
def self.start
|
|
13
|
+
|
|
14
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
15
|
+
puts "Sklaventreiber goes to work."
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
trap('TERM') {
|
|
19
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
20
|
+
puts "Sklaventreiber was interrupted."
|
|
21
|
+
end
|
|
22
|
+
$exit = true;
|
|
23
|
+
}
|
|
24
|
+
trap( 'INT') {
|
|
25
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
26
|
+
puts "Sklaventreiber was interrupted."
|
|
27
|
+
end
|
|
28
|
+
$exit = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
Sklaventreiber::HerokuConnection.init()
|
|
32
|
+
|
|
33
|
+
loop do
|
|
34
|
+
check_and_hire()
|
|
35
|
+
|
|
36
|
+
if ( $exit )
|
|
37
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
38
|
+
puts "Sklaventreiber leaves work."
|
|
39
|
+
end
|
|
40
|
+
break;
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
44
|
+
puts "Sklaventreiber takes a nap."
|
|
45
|
+
end
|
|
46
|
+
sleep( Sklaventreiber::Config::SKLAVENTREIBER_SLEEPTIME )
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
##
|
|
51
|
+
# Check if there are jobs and act accordingly
|
|
52
|
+
def self.check_and_hire
|
|
53
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
54
|
+
puts "Sklaventreiber checks the situation."
|
|
55
|
+
end
|
|
56
|
+
# if there are uncompleted jobs
|
|
57
|
+
if ( Navvy::Job.filter( :failed_at => nil, :completed_at => nil ).count > 0 )
|
|
58
|
+
# then hire worker if necessary
|
|
59
|
+
if ( Sklaventreiber::HerokuConnection.is_fired?() )
|
|
60
|
+
Sklaventreiber::HerokuConnection.hire_worker()
|
|
61
|
+
else
|
|
62
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
63
|
+
puts "Sklaventreiber is happy."
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
else
|
|
67
|
+
# else fire worker if necessary
|
|
68
|
+
if ( Sklaventreiber::HerokuConnection.is_hired?() )
|
|
69
|
+
Sklaventreiber::HerokuConnection.fire_worker()
|
|
70
|
+
else
|
|
71
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
72
|
+
puts "Sklaventreiber is happy."
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
end
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
require "sklaventreiber/version"
|
|
2
|
+
require "sklaventreiber/config"
|
|
3
|
+
require "sklaventreiber/herokuconnection"
|
|
4
|
+
|
|
5
|
+
module Sklaventreiber
|
|
6
|
+
|
|
7
|
+
module WorkerPlugin
|
|
8
|
+
|
|
9
|
+
module InstanceMethods
|
|
10
|
+
|
|
11
|
+
def before_create
|
|
12
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
13
|
+
puts "Sklaventreiber: Job created."
|
|
14
|
+
end
|
|
15
|
+
Sklaventreiber::HerokuConnection.init()
|
|
16
|
+
# if there is no worker hired
|
|
17
|
+
if ( Sklaventreiber::HerokuConnection.is_fired?() )
|
|
18
|
+
# then hire one
|
|
19
|
+
Sklaventreiber::HerokuConnection.hire_worker()
|
|
20
|
+
end
|
|
21
|
+
super
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def after_destroy
|
|
25
|
+
super
|
|
26
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
27
|
+
puts "Sklaventreiber: Job #{self.id} destroyed."
|
|
28
|
+
end
|
|
29
|
+
Sklaventreiber::HerokuConnection.init()
|
|
30
|
+
# if there are no more jobs to work on
|
|
31
|
+
if ( Navvy::Job.filter( :failed_at => nil, :completed_at => nil ).count == 0 )
|
|
32
|
+
# then fire worker
|
|
33
|
+
Sklaventreiber::HerokuConnection.fire_worker()
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def after_update
|
|
38
|
+
super
|
|
39
|
+
|
|
40
|
+
if Sklaventreiber::Config::SKLAVENTREIBER_LOG
|
|
41
|
+
puts "Sklaventreiber: Job #{self.id} updated."
|
|
42
|
+
end
|
|
43
|
+
Sklaventreiber::HerokuConnection.init()
|
|
44
|
+
|
|
45
|
+
# check if failed
|
|
46
|
+
if ( self.failed? == true )
|
|
47
|
+
# check if there are uncompleted jobs left
|
|
48
|
+
if ( Job.filter( :failed_at => nil, :completed_at => nil ).count == 0 )
|
|
49
|
+
# then fire worker
|
|
50
|
+
Sklaventreiber::HerokuConnection.fire_worker()
|
|
51
|
+
end
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
data/navvy.proc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
navvy: bundle exec rake navvy:work --trace
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require File.expand_path('../lib/sklaventreiber/version', __FILE__)
|
|
3
|
+
|
|
4
|
+
Gem::Specification.new do |gem|
|
|
5
|
+
gem.authors = ["Nikolaus Piccolotto"]
|
|
6
|
+
gem.email = ["prayerslayer@gmail.com"]
|
|
7
|
+
gem.description = %q{Hire and fire a Navvy worker on Heroku as needed.}
|
|
8
|
+
gem.summary = %q{Navvy delayed job manager for Heroku}
|
|
9
|
+
gem.homepage = ""
|
|
10
|
+
|
|
11
|
+
gem.files = `git ls-files`.split($\)
|
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
14
|
+
gem.name = "sklaventreiber"
|
|
15
|
+
gem.require_paths = ["lib"]
|
|
16
|
+
gem.version = Sklaventreiber::VERSION
|
|
17
|
+
|
|
18
|
+
gem.add_dependency "sequel"
|
|
19
|
+
gem.add_dependency "heroku-api"
|
|
20
|
+
|
|
21
|
+
gem.add_development_dependency "pg"
|
|
22
|
+
gem.add_development_dependency "rake"
|
|
23
|
+
gem.add_development_dependency "foreman"
|
|
24
|
+
gem.add_development_dependency "navvy"
|
|
25
|
+
|
|
26
|
+
end
|
data/test.proc
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
test: bundle exec rake test --trace
|
data/test/.DS_Store
ADDED
|
Binary file
|
data/test/job.rb
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
require "sequel"
|
|
2
|
+
|
|
3
|
+
Sequel::Model.db=Sequel.postgres(
|
|
4
|
+
:host => ENV['DATABASE_HOST'],
|
|
5
|
+
:user => ENV['DATABASE_USER'],
|
|
6
|
+
:password => ENV['DATABASE_PWD'],
|
|
7
|
+
:database => ENV['DATABASE_NAME'],
|
|
8
|
+
:port => ENV['DATABASE_PORT']
|
|
9
|
+
)
|
|
10
|
+
|
|
11
|
+
class Job < Sequel::Model
|
|
12
|
+
def before_create
|
|
13
|
+
puts "job creation is awesome"
|
|
14
|
+
super
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def after_destroy
|
|
18
|
+
super
|
|
19
|
+
puts "job destruction is not"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
require "test/unit"
|
|
2
|
+
require "sequel"
|
|
3
|
+
|
|
4
|
+
Sequel::Model.db=Sequel.connect( ENV['DATABASE_URL'] )
|
|
5
|
+
|
|
6
|
+
# require "job.rb"
|
|
7
|
+
|
|
8
|
+
require "navvy"
|
|
9
|
+
require "navvy/job/sequel"
|
|
10
|
+
|
|
11
|
+
require "sklaventreiber"
|
|
12
|
+
require "sklaventreiber/mock"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class SklaventreiberPluginTest < Test::Unit::TestCase
|
|
16
|
+
|
|
17
|
+
$stdout.sync = true
|
|
18
|
+
|
|
19
|
+
def test_environment
|
|
20
|
+
assert_not_nil Sklaventreiber::Config::HEROKU_USERNAME
|
|
21
|
+
assert_not_nil Sklaventreiber::Config::HEROKU_PASSWORD
|
|
22
|
+
assert_not_nil Sklaventreiber::Config::HEROKU_API_KEY
|
|
23
|
+
assert_not_nil Sklaventreiber::Config::HEROKU_APP
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def test_app_available
|
|
27
|
+
api = Heroku::API.new( :api_key => ENV['HEROKU_API_KEY'], :mock => Sklaventreiber::Config::SKLAVENTREIBER_MOCK )
|
|
28
|
+
response = api.get_apps()
|
|
29
|
+
assert_not_nil response
|
|
30
|
+
assert_equal 200, response.status
|
|
31
|
+
puts response.status
|
|
32
|
+
assert_not_nil response.body
|
|
33
|
+
assert_operator response.body.length, :>, 0
|
|
34
|
+
app_found = false
|
|
35
|
+
apps = response.body
|
|
36
|
+
apps.each do |app|
|
|
37
|
+
puts app["name"]
|
|
38
|
+
if ( app["name"] == ENV['HEROKU_APP'] )
|
|
39
|
+
app_found = true
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
assert_equal true, app_found
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def get_remote_worker
|
|
46
|
+
test_worker = 0
|
|
47
|
+
api = Heroku::API.new( :api_key => ENV['HEROKU_API_KEY'], :mock => Sklaventreiber::Config::SKLAVENTREIBER_MOCK )
|
|
48
|
+
response = api.get_ps( ENV['HEROKU_APP'] )
|
|
49
|
+
assert_equal 200, response.status
|
|
50
|
+
|
|
51
|
+
test_worker = 0
|
|
52
|
+
processes = response.body
|
|
53
|
+
processes.each do |proc|
|
|
54
|
+
puts proc.to_s
|
|
55
|
+
if ( proc["process"].start_with?( "worker" ) )
|
|
56
|
+
test_worker = test_worker + 1
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
return test_worker
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def test_hiring
|
|
63
|
+
Sklaventreiber::HerokuConnection.init()
|
|
64
|
+
Sklaventreiber::HerokuConnection.hire_worker()
|
|
65
|
+
|
|
66
|
+
# wait
|
|
67
|
+
sleep( 5 )
|
|
68
|
+
|
|
69
|
+
# test local worker count
|
|
70
|
+
assert_equal true, Sklaventreiber::HerokuConnection.is_hired?()
|
|
71
|
+
|
|
72
|
+
# test remote worker count
|
|
73
|
+
assert_equal 1, get_remote_worker()
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def test_firing
|
|
77
|
+
Sklaventreiber::HerokuConnection.init()
|
|
78
|
+
Sklaventreiber::HerokuConnection.fire_worker()
|
|
79
|
+
|
|
80
|
+
# wait
|
|
81
|
+
sleep( 5 )
|
|
82
|
+
|
|
83
|
+
# test local worker count
|
|
84
|
+
assert_equal true, Sklaventreiber::HerokuConnection.is_fired?()
|
|
85
|
+
|
|
86
|
+
# test remote worker count
|
|
87
|
+
assert_equal 0, get_remote_worker()
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def test_create_job
|
|
91
|
+
# insert job
|
|
92
|
+
job = Navvy::Job.create()
|
|
93
|
+
|
|
94
|
+
# check if there is anything
|
|
95
|
+
assert_not_nil job
|
|
96
|
+
|
|
97
|
+
# wait
|
|
98
|
+
sleep( 10 )
|
|
99
|
+
|
|
100
|
+
# test if worker is hired
|
|
101
|
+
assert_equal true, Sklaventreiber::HerokuConnection.is_hired?()
|
|
102
|
+
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
def test_destroy_job
|
|
106
|
+
# destroy all jobs
|
|
107
|
+
Navvy::Job.destroy()
|
|
108
|
+
|
|
109
|
+
# check if they are gone
|
|
110
|
+
assert_equal 0, Navvy::Job.all.length
|
|
111
|
+
|
|
112
|
+
# wait
|
|
113
|
+
sleep( 10 )
|
|
114
|
+
|
|
115
|
+
# test if worker is fired
|
|
116
|
+
assert_equal true, Sklaventreiber::HerokuConnection.is_fired?()
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
def test_queue
|
|
120
|
+
job = Navvy::Job.enqueue( Sklaventreiber::Mock, :mock_method, 15 )
|
|
121
|
+
|
|
122
|
+
puts Navvy::Job.all.count.to_s + " jobs in queue"
|
|
123
|
+
|
|
124
|
+
sleep( 7 )
|
|
125
|
+
|
|
126
|
+
assert_equal true, Sklaventreiber::HerokuConnection.is_hired?()
|
|
127
|
+
|
|
128
|
+
sleep( 15 )
|
|
129
|
+
|
|
130
|
+
assert_equal true, Sklaventreiber::HerokuConnection.is_fired?()
|
|
131
|
+
end
|
|
132
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: sklaventreiber
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.0.1
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Nikolaus Piccolotto
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
|
|
13
|
+
date: 2013-01-23 00:00:00 Z
|
|
14
|
+
dependencies:
|
|
15
|
+
- !ruby/object:Gem::Dependency
|
|
16
|
+
name: sequel
|
|
17
|
+
prerelease: false
|
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
|
19
|
+
none: false
|
|
20
|
+
requirements:
|
|
21
|
+
- - ">="
|
|
22
|
+
- !ruby/object:Gem::Version
|
|
23
|
+
version: "0"
|
|
24
|
+
type: :runtime
|
|
25
|
+
version_requirements: *id001
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: heroku-api
|
|
28
|
+
prerelease: false
|
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
|
30
|
+
none: false
|
|
31
|
+
requirements:
|
|
32
|
+
- - ">="
|
|
33
|
+
- !ruby/object:Gem::Version
|
|
34
|
+
version: "0"
|
|
35
|
+
type: :runtime
|
|
36
|
+
version_requirements: *id002
|
|
37
|
+
- !ruby/object:Gem::Dependency
|
|
38
|
+
name: pg
|
|
39
|
+
prerelease: false
|
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ">="
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: "0"
|
|
46
|
+
type: :development
|
|
47
|
+
version_requirements: *id003
|
|
48
|
+
- !ruby/object:Gem::Dependency
|
|
49
|
+
name: rake
|
|
50
|
+
prerelease: false
|
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
|
52
|
+
none: false
|
|
53
|
+
requirements:
|
|
54
|
+
- - ">="
|
|
55
|
+
- !ruby/object:Gem::Version
|
|
56
|
+
version: "0"
|
|
57
|
+
type: :development
|
|
58
|
+
version_requirements: *id004
|
|
59
|
+
- !ruby/object:Gem::Dependency
|
|
60
|
+
name: foreman
|
|
61
|
+
prerelease: false
|
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
|
63
|
+
none: false
|
|
64
|
+
requirements:
|
|
65
|
+
- - ">="
|
|
66
|
+
- !ruby/object:Gem::Version
|
|
67
|
+
version: "0"
|
|
68
|
+
type: :development
|
|
69
|
+
version_requirements: *id005
|
|
70
|
+
- !ruby/object:Gem::Dependency
|
|
71
|
+
name: navvy
|
|
72
|
+
prerelease: false
|
|
73
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
|
74
|
+
none: false
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: "0"
|
|
79
|
+
type: :development
|
|
80
|
+
version_requirements: *id006
|
|
81
|
+
description: Hire and fire a Navvy worker on Heroku as needed.
|
|
82
|
+
email:
|
|
83
|
+
- prayerslayer@gmail.com
|
|
84
|
+
executables: []
|
|
85
|
+
|
|
86
|
+
extensions: []
|
|
87
|
+
|
|
88
|
+
extra_rdoc_files: []
|
|
89
|
+
|
|
90
|
+
files:
|
|
91
|
+
- .DS_Store
|
|
92
|
+
- .gitignore
|
|
93
|
+
- Gemfile
|
|
94
|
+
- Gemfile.lock
|
|
95
|
+
- LICENSE
|
|
96
|
+
- Procfile
|
|
97
|
+
- README.md
|
|
98
|
+
- Rakefile
|
|
99
|
+
- lib/.DS_Store
|
|
100
|
+
- lib/sklaventreiber.rb
|
|
101
|
+
- lib/sklaventreiber/.DS_Store
|
|
102
|
+
- lib/sklaventreiber/config.rb
|
|
103
|
+
- lib/sklaventreiber/herokuconnection.rb
|
|
104
|
+
- lib/sklaventreiber/mock.rb
|
|
105
|
+
- lib/sklaventreiber/tasks.rb
|
|
106
|
+
- lib/sklaventreiber/version.rb
|
|
107
|
+
- lib/sklaventreiber/worker.rb
|
|
108
|
+
- lib/sklaventreiber/workerplugin.rb
|
|
109
|
+
- navvy.proc
|
|
110
|
+
- sklaventreiber.gemspec
|
|
111
|
+
- test.proc
|
|
112
|
+
- test/.DS_Store
|
|
113
|
+
- test/job.rb
|
|
114
|
+
- test/test_sklaventreiber_plugin.rb
|
|
115
|
+
homepage: ""
|
|
116
|
+
licenses: []
|
|
117
|
+
|
|
118
|
+
post_install_message:
|
|
119
|
+
rdoc_options: []
|
|
120
|
+
|
|
121
|
+
require_paths:
|
|
122
|
+
- lib
|
|
123
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
124
|
+
none: false
|
|
125
|
+
requirements:
|
|
126
|
+
- - ">="
|
|
127
|
+
- !ruby/object:Gem::Version
|
|
128
|
+
version: "0"
|
|
129
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
|
+
none: false
|
|
131
|
+
requirements:
|
|
132
|
+
- - ">="
|
|
133
|
+
- !ruby/object:Gem::Version
|
|
134
|
+
version: "0"
|
|
135
|
+
requirements: []
|
|
136
|
+
|
|
137
|
+
rubyforge_project:
|
|
138
|
+
rubygems_version: 1.8.24
|
|
139
|
+
signing_key:
|
|
140
|
+
specification_version: 3
|
|
141
|
+
summary: Navvy delayed job manager for Heroku
|
|
142
|
+
test_files:
|
|
143
|
+
- test/.DS_Store
|
|
144
|
+
- test/job.rb
|
|
145
|
+
- test/test_sklaventreiber_plugin.rb
|