polling 0.0.3 → 0.0.5
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/README.md +21 -2
- data/lib/polling/target.rb +9 -5
- data/lib/polling/version.rb +1 -1
- data/lib/polling.rb +5 -4
- data/test/test_confirm.rb +2 -0
- data/test/test_run.rb +10 -7
- data/test/test_target.rb +7 -5
- metadata +2 -2
data/README.md
CHANGED
@@ -17,10 +17,29 @@ Or install it yourself as:
|
|
17
17
|
It starts at per minute 0 second.
|
18
18
|
|
19
19
|
time = [0,10,20,30,40,50]
|
20
|
-
Polling::run(time,debug=
|
20
|
+
Polling::run(time,debug=true) do
|
21
21
|
puts "test"
|
22
22
|
sleep 2
|
23
23
|
end
|
24
|
+
|
25
|
+
result
|
26
|
+
|
27
|
+
start: 2012-11-16 19:47:36 +0900
|
28
|
+
sleep 23.980872869491577seconds (until 2012-11-16 19:48:00 +0900)
|
29
|
+
test
|
30
|
+
sleep 7.999034881591797seconds (until 2012-11-16 19:48:10 +0900)
|
31
|
+
test
|
32
|
+
sleep 7.999000072479248seconds (until 2012-11-16 19:48:20 +0900)
|
33
|
+
test
|
34
|
+
sleep 7.998318195343018seconds (until 2012-11-16 19:48:30 +0900)
|
35
|
+
test
|
36
|
+
sleep 7.998938083648682seconds (until 2012-11-16 19:48:40 +0900)
|
37
|
+
test
|
38
|
+
sleep 7.999677896499634seconds (until 2012-11-16 19:48:50 +0900)
|
39
|
+
test
|
40
|
+
sleep 7.998055934906006seconds (until 2012-11-16 19:49:00 +0900)
|
41
|
+
test
|
42
|
+
sleep 7.998072147369385seconds (until 2012-11-16 19:49:10 +0900)
|
24
43
|
|
25
44
|
The multiple of 60 is set up.
|
26
45
|
|
@@ -32,7 +51,7 @@ The multiple of 60 is set up.
|
|
32
51
|
|
33
52
|
Please set a vlue that is divisible by 60.
|
34
53
|
|
35
|
-
time = ["5s"]
|
54
|
+
time = ["5s"] #or 5. support string is s,m,h,d.
|
36
55
|
Polling::run(time) do
|
37
56
|
puts "test"
|
38
57
|
sleep 2
|
data/lib/polling/target.rb
CHANGED
@@ -4,18 +4,22 @@ module Polling
|
|
4
4
|
module Target
|
5
5
|
module_function
|
6
6
|
|
7
|
-
def interval(interval
|
7
|
+
def interval(interval,*args)
|
8
8
|
init = 60
|
9
9
|
now_to_f = Time.now.to_f
|
10
|
-
|
11
10
|
stime = interval - (now_to_f % init)
|
12
|
-
|
11
|
+
|
12
|
+
args.each do |arg|
|
13
|
+
@start = arg[:start]
|
14
|
+
@debug = arg[:debug]
|
15
|
+
end
|
16
|
+
|
17
|
+
if !@start && stime < 0
|
13
18
|
stime = init - stime.abs
|
14
19
|
end
|
15
20
|
|
16
21
|
### debug
|
17
|
-
print "sleep #{stime}seconds (until #{Time.at(now_to_f + stime)})\n" if debug
|
18
|
-
|
22
|
+
print "sleep #{stime}seconds (until #{Time.at(now_to_f + stime)})\n" if @debug && stime > 0
|
19
23
|
return stime
|
20
24
|
end
|
21
25
|
|
data/lib/polling/version.rb
CHANGED
data/lib/polling.rb
CHANGED
@@ -6,14 +6,15 @@ require 'polling/target'
|
|
6
6
|
module Polling
|
7
7
|
module_function
|
8
8
|
def run(arr, debug=false)
|
9
|
-
start = true
|
10
9
|
arr = Confirm::check_arr(arr)
|
10
|
+
args = {:start => false, :debug => debug}
|
11
|
+
Sleep::exec Target::interval(0,args)
|
12
|
+
args[:start] = true
|
11
13
|
loop do
|
12
14
|
arr.each do |time|
|
13
15
|
time = Confirm::check_value(time)
|
14
|
-
Sleep::exec Target::interval(
|
15
|
-
|
16
|
-
start = false
|
16
|
+
Sleep::exec Target::interval(time,args)
|
17
|
+
args[:start] = false
|
17
18
|
yield
|
18
19
|
end
|
19
20
|
end
|
data/test/test_confirm.rb
CHANGED
@@ -13,6 +13,8 @@ class PollingTest < Test::Unit::TestCase
|
|
13
13
|
assert_equal 300, Polling::Confirm::convert("5m")
|
14
14
|
assert_equal 18000, Polling::Confirm::convert("5h")
|
15
15
|
|
16
|
+
assert_equal ["0","10","20","30","40","50"], Polling::Confirm::check_arr(["0","10","20","30","40","50"])
|
17
|
+
assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr([0,10,20,30,40,50])
|
16
18
|
assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr(["10s"])
|
17
19
|
assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr(["10"])
|
18
20
|
assert_equal [0,10,20,30,40,50], Polling::Confirm::check_arr([10])
|
data/test/test_run.rb
CHANGED
@@ -1,11 +1,14 @@
|
|
1
1
|
require File.expand_path(File.dirname(__FILE__)) + "/helper.rb"
|
2
2
|
|
3
3
|
class PollingTest < Test::Unit::TestCase
|
4
|
-
def test_run
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
4
|
+
#def test_run
|
5
|
+
# puts "start: #{Time.now}"
|
6
|
+
# #arr = [5,15,25,35,45,55]
|
7
|
+
# #arr = ["0","10","20","30","40","50"]
|
8
|
+
# arr = ["10s"]
|
9
|
+
# Polling::run(arr,true) do
|
10
|
+
# puts Time.now
|
11
|
+
# sleep 2
|
12
|
+
# end
|
13
|
+
#end
|
11
14
|
end
|
data/test/test_target.rb
CHANGED
@@ -16,11 +16,13 @@ class PollingTest < Test::Unit::TestCase
|
|
16
16
|
assert_equal time+1, Polling::Target::interval(time)
|
17
17
|
end
|
18
18
|
|
19
|
+
debug = {:debug => true}
|
20
|
+
|
19
21
|
Time.stubs(:now).returns(Time.parse "2012/01/01 00:00:00")
|
20
|
-
assert_equal 180, Polling::Target::interval(180,
|
21
|
-
assert_equal 300, Polling::Target::interval(300,
|
22
|
-
assert_equal 300, Polling::Target::interval(300,
|
23
|
-
assert_equal 3600, Polling::Target::interval(3600,
|
24
|
-
|
22
|
+
assert_equal 180, Polling::Target::interval(180,debug)
|
23
|
+
assert_equal 300, Polling::Target::interval(300,debug)
|
24
|
+
assert_equal 300, Polling::Target::interval(300,debug)
|
25
|
+
assert_equal 3600, Polling::Target::interval(3600,debug)
|
25
26
|
end
|
27
|
+
|
26
28
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polling
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-11-
|
12
|
+
date: 2012-11-18 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: polling
|
15
15
|
email:
|