dynopoker 1.2.1 → 1.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.travis.yml +12 -0
- data/README.md +6 -2
- data/dynopoker.gemspec +3 -1
- data/lib/dynopoker.rb +12 -6
- data/lib/dynopoker/version.rb +1 -1
- data/spec/dynopoker_spec.rb +47 -0
- data/spec/poker_spec.rb +91 -0
- data/spec/spec_helper.rb +2 -0
- metadata +46 -15
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a517653def897da013aac4e959cd295d69ea64f5
|
4
|
+
data.tar.gz: a2ea00e6a9c9cffafe6fd2af97df299db5acb876
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c4c5b44ff5b5c32a555882349fcd68d4eacae9d24367ab920c3f8d2529ffc368406f03ec98fd71811aba23a57f0b389109f80385876faf033b1d9ac9aef5f222
|
7
|
+
data.tar.gz: 5e8d23878eb81398de4658e1fd81aecab76daaaa03ae39b304c4e2e559a321dde80828a06ef9006693c02dfee84eed17fc7e7e10c388849c7168b412cd4bb7e3
|
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
DynoPoker
|
1
|
+
DynoPoker [![Build Status](https://travis-ci.org/kubenstein/dynopoker.png?branch=master)](https://travis-ci.org/kubenstein/dynopoker)
|
2
2
|
=============
|
3
3
|
|
4
4
|
Dynopoker is a gem which prevent your Heroku dyno from falling asleep.
|
@@ -24,4 +24,8 @@ Add this configuration to your config file:
|
|
24
24
|
# config.enable = false # default is true
|
25
25
|
# config.poke_frequency = 123 # default is 1800s (30min)
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
|
+
TODO
|
29
|
+
-----
|
30
|
+
Dynopoker is already doing what it was designed for. No extra features are needed. Code is very simple and well written.
|
31
|
+
I recently added specs but I feel that those specs could be written better. Feel free to contribute.
|
data/dynopoker.gemspec
CHANGED
@@ -15,8 +15,10 @@ Gem::Specification.new do |s|
|
|
15
15
|
|
16
16
|
s.files = `git ls-files`.split("\n")
|
17
17
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
18
|
s.require_paths = ["lib"]
|
20
19
|
|
21
20
|
s.add_dependency "logger"
|
21
|
+
|
22
|
+
s.add_development_dependency 'rspec', '~> 2.14.1'
|
23
|
+
s.add_development_dependency 'webmock', '~> 1.16.0'
|
22
24
|
end
|
data/lib/dynopoker.rb
CHANGED
@@ -1,18 +1,23 @@
|
|
1
1
|
require 'dynopoker/version'
|
2
2
|
require 'open-uri'
|
3
|
+
require 'logger'
|
3
4
|
|
4
5
|
module Dynopoker
|
5
6
|
|
6
|
-
def self.configure
|
7
|
-
|
7
|
+
def self.configure(poker_factory = Poker, execution_flow = $0)
|
8
|
+
poker_factory.new.tap do |p|
|
9
|
+
yield p
|
10
|
+
p.start! unless execution_flow =~ /rake/
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
class Poker
|
11
15
|
attr_accessor :enable, :address, :poke_frequency, :logger
|
16
|
+
alias_method :enable?, :enable
|
12
17
|
|
13
18
|
def start!
|
14
19
|
merge_default_options!
|
15
|
-
start_poking_thread! if
|
20
|
+
start_poking_thread! if enable?
|
16
21
|
end
|
17
22
|
|
18
23
|
|
@@ -41,12 +46,13 @@ module Dynopoker
|
|
41
46
|
self.poke_frequency ||= 1800
|
42
47
|
self.logger ||= Logger.new($stdout)
|
43
48
|
self.enable = enable.nil? ? true : enable
|
44
|
-
raise('Dynopoker: no address provided!') if
|
49
|
+
raise('Dynopoker: no address provided!') if (enable? && !valid_address?)
|
45
50
|
end
|
46
51
|
|
47
|
-
def
|
48
|
-
|
52
|
+
def valid_address?
|
53
|
+
address && !address.empty?
|
49
54
|
end
|
50
55
|
|
51
56
|
end
|
57
|
+
|
52
58
|
end
|
data/lib/dynopoker/version.rb
CHANGED
@@ -0,0 +1,47 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
|
6
|
+
describe Dynopoker do
|
7
|
+
|
8
|
+
subject { Dynopoker }
|
9
|
+
let(:fake_poker) { Struct.new(:enable, :address, :poke_frequency, :logger, :start!) }
|
10
|
+
let(:fake_logger) { OpenStruct.new(fake?: true) }
|
11
|
+
|
12
|
+
context 'configuration' do
|
13
|
+
|
14
|
+
it 'should pass config vars during configuration' do
|
15
|
+
new_instance_of_poker = subject.configure(fake_poker) do |config|
|
16
|
+
config.address = 'http://test.org'
|
17
|
+
config.enable = false
|
18
|
+
config.poke_frequency = 123
|
19
|
+
config.logger = fake_logger
|
20
|
+
end
|
21
|
+
|
22
|
+
new_instance_of_poker.address.should eq 'http://test.org'
|
23
|
+
new_instance_of_poker.enable.should be_false
|
24
|
+
new_instance_of_poker.poke_frequency.should eq 123
|
25
|
+
new_instance_of_poker.logger.should be_fake
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should pass start poking!' do
|
29
|
+
fake_poker.any_instance.should_receive(:start!).once
|
30
|
+
subject.configure(fake_poker) {}
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'asset precompile process' do
|
36
|
+
it 'should not start while in asset precompile process' do
|
37
|
+
fake_poker.any_instance.should_not_receive(:start!)
|
38
|
+
subject.configure(fake_poker, '/bin/rake') {}
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'should start while not in asset precompile process' do
|
42
|
+
fake_poker.any_instance.should_receive(:start!).once
|
43
|
+
subject.configure(fake_poker, '/bin/rails') {}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/spec/poker_spec.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
require 'spec_helper'
|
3
|
+
require 'ostruct'
|
4
|
+
|
5
|
+
|
6
|
+
describe Dynopoker::Poker do
|
7
|
+
|
8
|
+
context 'default params' do
|
9
|
+
it 'should use default params if no other params are given' do
|
10
|
+
subject.stub(start_poking_thread!: false, address: 'http://test.org')
|
11
|
+
subject.start!
|
12
|
+
subject.poke_frequency.should eq 1800
|
13
|
+
subject.logger.class.name.should eq 'Logger'
|
14
|
+
subject.enable.should be_true
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context 'no address provided error' do
|
19
|
+
it 'should raise exception if address is not given' do
|
20
|
+
expect { subject.start! }.to raise_error(Exception, 'Dynopoker: no address provided!')
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should raise exception if address is empty' do
|
24
|
+
subject.stub(address: '')
|
25
|
+
expect { subject.start! }.to raise_error(Exception, 'Dynopoker: no address provided!')
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should NOT raise exception if address is not given but poking is disabled' do
|
29
|
+
subject.stub(enable: false)
|
30
|
+
expect { subject.start! }.not_to raise_error(Exception, 'Dynopoker: no address provided!')
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'should NOT raise exception if address is empty but poking is disabled' do
|
34
|
+
subject.stub(enable: false, address: '')
|
35
|
+
expect { subject.start! }.not_to raise_error(Exception, 'Dynopoker: no address provided!')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'thread' do
|
40
|
+
it 'should start thread' do
|
41
|
+
subject.stub(address: 'http://test.org')
|
42
|
+
Thread.should_receive(:new).once
|
43
|
+
subject.start!
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'poking' do
|
48
|
+
before do
|
49
|
+
#
|
50
|
+
# testing while(true) in separate thread can be really tuff task
|
51
|
+
# first I skip thread itself by replacing 'start_poking_thread!' method with 'poking'
|
52
|
+
def subject.start_poking_thread!; poking end
|
53
|
+
|
54
|
+
#
|
55
|
+
# then I need to break while true loop...
|
56
|
+
# I replace sleep method in the loop to raise exception after x calls
|
57
|
+
def subject.sleep(_)
|
58
|
+
break_after_attempts = 2
|
59
|
+
@x ||= 0
|
60
|
+
raise('breaking while true loop') if ((@x+=1) == break_after_attempts)
|
61
|
+
end
|
62
|
+
|
63
|
+
#
|
64
|
+
# One thing that can not be tested in this configuration is poking frequency
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'should poke address' do
|
68
|
+
stub_request(:get, 'http://test.org')
|
69
|
+
subject.stub(address: 'http://test.org')
|
70
|
+
|
71
|
+
expect {
|
72
|
+
subject.start!
|
73
|
+
}.to raise_error(Exception, 'breaking while true loop')
|
74
|
+
|
75
|
+
WebMock.should have_requested(:get, 'http://test.org').twice
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'should write to logger error if any exception was raised during poking' do
|
79
|
+
fake_logger = double()
|
80
|
+
fake_logger.stub(:info)
|
81
|
+
fake_logger.stub(:error)
|
82
|
+
fake_logger.should_receive(:error).with('Dynopoker: poking error Errno::ENOENT: No such file or directory - INVALID_ADDRESS').twice
|
83
|
+
|
84
|
+
subject.stub(address: 'INVALID_ADDRESS', logger: fake_logger)
|
85
|
+
expect {
|
86
|
+
subject.start!
|
87
|
+
}.to raise_error(Exception, 'breaking while true loop')
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,32 +1,57 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dynopoker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2
|
5
|
-
prerelease:
|
4
|
+
version: 1.3.2
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- kubenstein
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
11
|
+
date: 2014-07-11 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: logger
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.14.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.14.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: webmock
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 1.16.0
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 1.16.0
|
30
55
|
description: Dynopoker is a gem that will make your ruby based heroku app self pinging
|
31
56
|
system, preventing single dyno from falling asleep
|
32
57
|
email:
|
@@ -36,34 +61,40 @@ extensions: []
|
|
36
61
|
extra_rdoc_files: []
|
37
62
|
files:
|
38
63
|
- .gitignore
|
64
|
+
- .travis.yml
|
39
65
|
- Gemfile
|
40
66
|
- README.md
|
41
67
|
- Rakefile
|
42
68
|
- dynopoker.gemspec
|
43
69
|
- lib/dynopoker.rb
|
44
70
|
- lib/dynopoker/version.rb
|
71
|
+
- spec/dynopoker_spec.rb
|
72
|
+
- spec/poker_spec.rb
|
73
|
+
- spec/spec_helper.rb
|
45
74
|
homepage: https://github.com/kubenstein/dynopoker
|
46
75
|
licenses: []
|
76
|
+
metadata: {}
|
47
77
|
post_install_message:
|
48
78
|
rdoc_options: []
|
49
79
|
require_paths:
|
50
80
|
- lib
|
51
81
|
required_ruby_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
82
|
requirements:
|
54
|
-
- -
|
83
|
+
- - '>='
|
55
84
|
- !ruby/object:Gem::Version
|
56
85
|
version: '0'
|
57
86
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
87
|
requirements:
|
60
|
-
- -
|
88
|
+
- - '>='
|
61
89
|
- !ruby/object:Gem::Version
|
62
90
|
version: '0'
|
63
91
|
requirements: []
|
64
92
|
rubyforge_project: dynopoker
|
65
|
-
rubygems_version: 1.
|
93
|
+
rubygems_version: 2.1.11
|
66
94
|
signing_key:
|
67
|
-
specification_version:
|
68
|
-
summary:
|
69
|
-
test_files:
|
95
|
+
specification_version: 4
|
96
|
+
summary: 'Dynopoker: prevent your heroku dyno from falling asleep'
|
97
|
+
test_files:
|
98
|
+
- spec/dynopoker_spec.rb
|
99
|
+
- spec/poker_spec.rb
|
100
|
+
- spec/spec_helper.rb
|