dynport_tools 0.2.14 → 0.2.15

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.14
1
+ 0.2.15
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{dynport_tools}
8
- s.version = "0.2.14"
8
+ s.version = "0.2.15"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tobias Schwab"]
12
- s.date = %q{2011-09-02}
12
+ s.date = %q{2011-09-05}
13
13
  s.description = %q{Collection of various tools}
14
14
  s.email = %q{tobias.schwab@dynport.de}
15
15
  s.executables = ["xmldiff", "redis_dumper"]
@@ -36,6 +36,7 @@ Gem::Specification.new do |s|
36
36
  "lib/dynport_tools/ascii_table.rb",
37
37
  "lib/dynport_tools/deep_merger.rb",
38
38
  "lib/dynport_tools/differ.rb",
39
+ "lib/dynport_tools/embedded_redis.rb",
39
40
  "lib/dynport_tools/eta.rb",
40
41
  "lib/dynport_tools/have_attributes.rb",
41
42
  "lib/dynport_tools/jenkins.rb",
@@ -0,0 +1,82 @@
1
+ require "redis"
2
+ require "singleton"
3
+ require "logger"
4
+
5
+ class EmbeddedRedis
6
+ include Singleton
7
+
8
+ attr_accessor :started, :base_path
9
+ attr_writer :logger
10
+
11
+ def initialize(options = {})
12
+ self.base_path = options[:base_path] || "/tmp"
13
+ self.logger = options[:logger] || Logger.new($stderr)
14
+ end
15
+
16
+ def pid_path
17
+ "#{base_path}/pids/redis.#{Process.pid}.pid"
18
+ end
19
+
20
+ def socket_path
21
+ "#{base_path}/sockets/redis.#{Process.pid}.socket"
22
+ end
23
+
24
+ def pid
25
+ File.read(pid_path).strip.presence if File.exists?(pid_path)
26
+ end
27
+
28
+ def running?
29
+ !!(pid && `ps -p #{pid} | tail -n +2`.present?)
30
+ end
31
+
32
+ def start
33
+ if !running?
34
+ [socket_path, pid_path].each { |path| FileUtils.mkdir_p(File.dirname(path)) }
35
+ system(%(echo "#{config}" | redis-server -))
36
+ sleep 0.1
37
+ self.started = true
38
+ log "started redis with pid #{pid}"
39
+ at_exit do
40
+ kill
41
+ end
42
+ connection
43
+ else
44
+ log "already running with pid #{pid}"
45
+ end
46
+ end
47
+
48
+ def started?
49
+ !!self.started
50
+ end
51
+
52
+ def connection
53
+ start if !started?
54
+ @connection ||= Redis.new(:path => socket_path)
55
+ end
56
+
57
+ def log(message)
58
+ logger.info("EMBEDDED_REDIS: #{message}")
59
+ end
60
+
61
+ def logger
62
+ @logger ||= Logger.new($stdout)
63
+ end
64
+
65
+ def kill
66
+ log "killing redis"
67
+ if pid
68
+ system(%(kill #{pid}))
69
+ FileUtils.rm_f(socket_path)
70
+ end
71
+ end
72
+
73
+ def config
74
+ [
75
+ "daemonize yes",
76
+ "pidfile #{pid_path}",
77
+ "port 0",
78
+ "unixsocket #{socket_path}"
79
+
80
+ ].join("\n")
81
+ end
82
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dynport_tools
3
3
  version: !ruby/object:Gem::Version
4
- hash: 11
4
+ hash: 9
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 14
10
- version: 0.2.14
9
+ - 15
10
+ version: 0.2.15
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tobias Schwab
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-09-02 00:00:00 +02:00
18
+ date: 2011-09-05 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -251,6 +251,7 @@ files:
251
251
  - lib/dynport_tools/ascii_table.rb
252
252
  - lib/dynport_tools/deep_merger.rb
253
253
  - lib/dynport_tools/differ.rb
254
+ - lib/dynport_tools/embedded_redis.rb
254
255
  - lib/dynport_tools/eta.rb
255
256
  - lib/dynport_tools/have_attributes.rb
256
257
  - lib/dynport_tools/jenkins.rb