polling 0.0.2
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 +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +29 -0
- data/Rakefile +4 -0
- data/lib/polling/confirm.rb +10 -0
- data/lib/polling/sleep.rb +8 -0
- data/lib/polling/target.rb +27 -0
- data/lib/polling/version.rb +3 -0
- data/lib/polling.rb +21 -0
- data/polling.gemspec +19 -0
- data/test/helper.rb +6 -0
- data/test/test_confirm.rb +11 -0
- data/test/test_run.rb +10 -0
- data/test/test_sleep.rb +9 -0
- data/test/test_target.rb +26 -0
- metadata +66 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
Copyright (c) 2012, Internet Initiative Japan Inc.
|
2
|
+
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
you may not use this file except in compliance with the License.
|
5
|
+
You may obtain a copy of the License at
|
6
|
+
|
7
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
|
9
|
+
Unless required by applicable law or agreed to in writing, software
|
10
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
See the License for the specific language governing permissions and
|
13
|
+
limitations under the License.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Polling
|
2
|
+
|
3
|
+
fluent-plugin-snmp用pollingライブラリ
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'polling'
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
必ず0秒からスタートします
|
14
|
+
|
15
|
+
time = [0,10,20,30,40,50]
|
16
|
+
Polling::run(time,debug=false) do
|
17
|
+
p "hoge"
|
18
|
+
end
|
19
|
+
|
20
|
+
もし60以上の値を設定する場合には60で割り切れる値を設定
|
21
|
+
|
22
|
+
time = [300]
|
23
|
+
Polling::run(time,debug=false) do
|
24
|
+
p "hoge"
|
25
|
+
end
|
26
|
+
|
27
|
+
## Copyright
|
28
|
+
|
29
|
+
Copyright:: Copyright (c) 2012, Internet Initiative Japan Inc. All rights reserved.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'time'
|
2
|
+
|
3
|
+
module Polling
|
4
|
+
module Target
|
5
|
+
module_function
|
6
|
+
|
7
|
+
class << self
|
8
|
+
#TODO imple delay
|
9
|
+
attr_accessor :delay
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_time(interval,debug=false)
|
13
|
+
init = 60
|
14
|
+
now_to_f = Time.now.to_f
|
15
|
+
|
16
|
+
stime = interval - (now_to_f % init)
|
17
|
+
if stime < 0
|
18
|
+
stime = init - stime.abs
|
19
|
+
end
|
20
|
+
|
21
|
+
### debug
|
22
|
+
print "sleep #{stime}seconds (until #{Time.at(now_to_f + stime)})\n" if debug
|
23
|
+
|
24
|
+
return stime
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/polling.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'polling/version'
|
2
|
+
require 'polling/confirm'
|
3
|
+
require 'polling/sleep'
|
4
|
+
require 'polling/target'
|
5
|
+
|
6
|
+
module Polling
|
7
|
+
module_function
|
8
|
+
def run(arr, debug=false)
|
9
|
+
start = true
|
10
|
+
|
11
|
+
loop do
|
12
|
+
arr.each do |time|
|
13
|
+
time = Confirm::check_value(time)
|
14
|
+
Sleep::exec Target::create_time(0, debug) if start
|
15
|
+
Sleep::exec Target::create_time(time, debug) unless start
|
16
|
+
start = false
|
17
|
+
yield
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/polling.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'polling/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "polling"
|
8
|
+
gem.version = Polling::VERSION
|
9
|
+
gem.authors = ["hiroshi sugimoto"]
|
10
|
+
gem.email = ["h-sugimoto@iij.ad.jp"]
|
11
|
+
gem.description = %q{polling}
|
12
|
+
gem.summary = %q{polling}
|
13
|
+
gem.homepage = "https://github.com/iij/polling"
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/test/helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper.rb"
|
2
|
+
|
3
|
+
class PollingTest < Test::Unit::TestCase
|
4
|
+
def test_check_value
|
5
|
+
assert_equal 0, Polling::Confirm::check_value(0)
|
6
|
+
assert_equal 0, Polling::Confirm::check_value("0")
|
7
|
+
assert_equal 60, Polling::Confirm::check_value(60)
|
8
|
+
assert_equal 60, Polling::Confirm::check_value("60")
|
9
|
+
assert_equal RuntimeError, Polling::Confirm::check_value(61)
|
10
|
+
end
|
11
|
+
end
|
data/test/test_run.rb
ADDED
data/test/test_sleep.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper.rb"
|
2
|
+
|
3
|
+
class PollingTest < Test::Unit::TestCase
|
4
|
+
def test_sleep
|
5
|
+
assert_equal false, Polling::Sleep::exec(-1)
|
6
|
+
assert_equal false, Polling::Sleep::exec(0)
|
7
|
+
#assert_equal 5, Polling::Sleep::exec(5)
|
8
|
+
end
|
9
|
+
end
|
data/test/test_target.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__)) + "/helper.rb"
|
2
|
+
require 'time'
|
3
|
+
|
4
|
+
class PollingTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def test_target_time
|
7
|
+
Time.stubs(:now).returns(Time.parse "2012/12/31 23:59:59")
|
8
|
+
assert_equal 1, Polling::Target::create_time(0)
|
9
|
+
assert_equal 6, Polling::Target::create_time(5)
|
10
|
+
assert_equal 0, Polling::Target::create_time(59)
|
11
|
+
assert_equal 1, Polling::Target::create_time(60)
|
12
|
+
assert_equal 2, Polling::Target::create_time(61)
|
13
|
+
|
14
|
+
arr = [0,1,5,10,20,30,40,50,58]
|
15
|
+
arr.each do |time|
|
16
|
+
assert_equal time+1, Polling::Target::create_time(time)
|
17
|
+
end
|
18
|
+
|
19
|
+
Time.stubs(:now).returns(Time.parse "2012/01/01 00:00:00")
|
20
|
+
assert_equal 180, Polling::Target::create_time(180,true)
|
21
|
+
assert_equal 300, Polling::Target::create_time(300,true)
|
22
|
+
assert_equal 300, Polling::Target::create_time(300,true)
|
23
|
+
assert_equal 3600, Polling::Target::create_time(3600,true)
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,66 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: polling
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- hiroshi sugimoto
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: polling
|
15
|
+
email:
|
16
|
+
- h-sugimoto@iij.ad.jp
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE.txt
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- lib/polling.rb
|
27
|
+
- lib/polling/confirm.rb
|
28
|
+
- lib/polling/sleep.rb
|
29
|
+
- lib/polling/target.rb
|
30
|
+
- lib/polling/version.rb
|
31
|
+
- polling.gemspec
|
32
|
+
- test/helper.rb
|
33
|
+
- test/test_confirm.rb
|
34
|
+
- test/test_run.rb
|
35
|
+
- test/test_sleep.rb
|
36
|
+
- test/test_target.rb
|
37
|
+
homepage: https://github.com/iij/polling
|
38
|
+
licenses: []
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
requirements: []
|
56
|
+
rubyforge_project:
|
57
|
+
rubygems_version: 1.8.24
|
58
|
+
signing_key:
|
59
|
+
specification_version: 3
|
60
|
+
summary: polling
|
61
|
+
test_files:
|
62
|
+
- test/helper.rb
|
63
|
+
- test/test_confirm.rb
|
64
|
+
- test/test_run.rb
|
65
|
+
- test/test_sleep.rb
|
66
|
+
- test/test_target.rb
|