sfc_ikiteru 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,8 @@
1
- === 0.0.2 2011-03-24
1
+ === 0.0.4 2011-03-24
2
+
3
+ * use eventmachine
4
+
5
+ === 0.0.3 2011-03-24
2
6
 
3
7
  * add www.mag.keio.ac.jp
4
8
 
data/Rakefile CHANGED
@@ -14,7 +14,7 @@ $hoe = Hoe.spec 'sfc_ikiteru' do
14
14
  self.developer 'Sho Hashimoto', 'hashimoto@shokai.org'
15
15
  self.rubyforge_name = self.name # TODO this is default value
16
16
  #self.extra_deps = [['activesupport','>= 2.0.2']]
17
- self.extra_deps = [['rainbow']]
17
+ self.extra_deps = [['rainbow'],['eventmachine']]
18
18
 
19
19
  end
20
20
 
@@ -1,7 +1,11 @@
1
- require 'ping'
1
+ # -*- coding: utf-8 -*-
2
+ require 'rubygems'
3
+ require 'socket'
4
+ require 'timeout'
5
+ require 'eventmachine'
2
6
 
3
7
  module SfcIkiteru
4
- VERSION = '0.0.3'
8
+ VERSION = '0.0.4'
5
9
  def SfcIkiteru.servers
6
10
  [
7
11
  {:host => 'web.sfc.keio.ac.jp', :service => 'echo'},
@@ -15,9 +19,21 @@ module SfcIkiteru
15
19
 
16
20
  def SfcIkiteru.ikiteru(timeout=3)
17
21
  results = Array.new
18
- servers.each{|s|
19
- results << {:host => s[:host], :ping => Ping.pingecho(s[:host], timeout, s[:service])}
20
- }
22
+
23
+ EM::run do
24
+ servers.each{|s|
25
+ EM::defer do
26
+ res = ping(s[:host], timeout, s[:service])
27
+ results << {:host => s[:host], :ping => res}
28
+ end
29
+ }
30
+ EM::defer do
31
+ loop do
32
+ EM::stop if results.size >= servers.size
33
+ sleep 0.1
34
+ end
35
+ end
36
+ end
21
37
  count = 0
22
38
  results.each{|i|
23
39
  count+=1 if i[:ping] == true
@@ -25,4 +41,17 @@ module SfcIkiteru
25
41
  per = count.to_f / results.size
26
42
  return per, results
27
43
  end
44
+
45
+ def SfcIkiteru.ping(host, timeout=5, service="echo")
46
+ begin
47
+ timeout(timeout) do
48
+ TCPSocket.new(host, service).close
49
+ end
50
+ rescue Errno::ECONNREFUSED
51
+ return true
52
+ rescue Timeout::Error, StandardError
53
+ return false
54
+ end
55
+ return true
56
+ end
28
57
  end
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
  require 'rubygems'
3
- #require File.dirname(__FILE__)+'/../lib/sfc_ikiteru'
4
- require 'sfc_ikiteru'
3
+ require File.dirname(__FILE__)+'/../lib/sfc_ikiteru'
4
+ #require 'sfc_ikiteru'
5
5
 
6
6
  per, details = SfcIkiteru.ikiteru
7
7
  p per
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sfc_ikiteru
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 3
10
- version: 0.0.3
9
+ - 4
10
+ version: 0.0.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sho Hashimoto
@@ -33,9 +33,23 @@ dependencies:
33
33
  type: :runtime
34
34
  version_requirements: *id001
35
35
  - !ruby/object:Gem::Dependency
36
- name: hoe
36
+ name: eventmachine
37
37
  prerelease: false
38
38
  requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 3
44
+ segments:
45
+ - 0
46
+ version: "0"
47
+ type: :runtime
48
+ version_requirements: *id002
49
+ - !ruby/object:Gem::Dependency
50
+ name: hoe
51
+ prerelease: false
52
+ requirement: &id003 !ruby/object:Gem::Requirement
39
53
  none: false
40
54
  requirements:
41
55
  - - ">="
@@ -47,7 +61,7 @@ dependencies:
47
61
  - 1
48
62
  version: 2.9.1
49
63
  type: :development
50
- version_requirements: *id002
64
+ version_requirements: *id003
51
65
  description: check status of Keio Univ SFC.
52
66
  email:
53
67
  - hashimoto@shokai.org