redis-repeater 0.0.3 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/bin/redis-repeater CHANGED
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require File.dirname(__FILE__) + '/../lib/redis-repeater'
3
+ require File.dirname(__FILE__) + '/../lib/redis_repeater'
4
4
 
5
5
  if ARGV.empty?
6
6
  puts "Please specify a config directory"
@@ -4,19 +4,14 @@ module RedisRepeater
4
4
 
5
5
  def initialize(logger = nil)
6
6
  @logger = logger
7
+ @logger.info 'Running on schedule forever...'
7
8
  end
8
9
 
9
10
  # When adding, we move through the current queue, and
10
11
  # find the first one that is performing after we want to
11
12
  def <<(job)
12
13
  scheduler = self
13
- EventMachine.run {
14
- EventMachine::add_timer(job.timeout) { job.perform; scheduler << job }
15
- }
16
- end
17
-
18
- def perform
19
- @logger.info 'Running on schedule forever...'
14
+ EventMachine::add_timer(job.timeout) { job.perform; scheduler << job }
20
15
  end
21
16
 
22
17
  end
@@ -13,6 +13,7 @@ module RedisRepeater
13
13
  def perform
14
14
  count = 0
15
15
  while (item = @redis_from.lpop @name)
16
+ # work the same direction resque does
16
17
  @redis_to.rpush(@name, item)
17
18
  count += 1
18
19
  end
@@ -1,5 +1,5 @@
1
1
  module RedisRepeater
2
2
 
3
- VERSION = [0, 0, 3]
3
+ VERSION = [0, 0, 5]
4
4
 
5
5
  end
@@ -0,0 +1,70 @@
1
+ require File.dirname(__FILE__) + '/redis_repeater/scheduler.rb'
2
+ require File.dirname(__FILE__) + '/redis_repeater/scheduler_job.rb'
3
+ require File.dirname(__FILE__) + '/redis_repeater/transfer_scheduler_job.rb'
4
+
5
+ require 'yaml'
6
+ require 'logger'
7
+ require 'fileutils'
8
+
9
+ require 'eventmachine'
10
+ require 'redis'
11
+
12
+ module RedisRepeater
13
+
14
+ DefaultRedisHost = 'localhost'
15
+ DefaultRedisPort = 6379
16
+ LogDefaultFilename = File.dirname(__FILE__) + '/../log/redis_repeater.log'
17
+
18
+ def self.start(config_dir)
19
+
20
+ # Connect to redis
21
+ config = YAML::load File.open("#{config_dir}/config.yml")
22
+ redis_from = redis_configure(config, 'origin')
23
+ redis_to = redis_configure(config, 'destination')
24
+
25
+ # Load the queues from the config file
26
+ queues = YAML::load File.open("#{config_dir}/queues.yml")
27
+
28
+ # replace 'magic' resque:queues key with all resque queues, but don't overwrite otherwise configured queues
29
+ # warning: only resolves queue names on startup, if new queue is created it will not pick it up.
30
+ if queues.has_key?("resque:queues")
31
+ redis_from.smembers("resque:queues").each do |queue|
32
+ queues["resque:queue:#{queue}"] = queues["resque:queues"] unless queues.has_key?("resque:queue:#{queue}")
33
+ end
34
+ queues.delete("resque:queues")
35
+ end
36
+
37
+ # Logger
38
+ if config.has_key?('log')
39
+ log_filename = config['log']
40
+ FileUtils.mkdir_p(File.dirname(log_filename))
41
+ logger = Logger.new(log_filename)
42
+ else
43
+ logger = Logger.new(STDOUT)
44
+ end
45
+
46
+ # Load the queues into the scheduler
47
+ scheduler = Scheduler.new(logger)
48
+ EventMachine::run do
49
+ queues.each do |name, timeout|
50
+ puts "#{name} - #{timeout}"
51
+ scheduler << TransferSchedulerJob.new(name, timeout, logger, redis_from, redis_to)
52
+ end
53
+ end
54
+
55
+ # Perform forever
56
+ scheduler.perform # TODO make configurable
57
+
58
+ end
59
+
60
+ def self.redis_configure(config, name)
61
+ host = DefaultRedisHost
62
+ port = DefaultRedisPort
63
+ if config.has_key?(name)
64
+ host = config[name]['host'] if config[name].has_key?('host')
65
+ port = config[name]['port'] if config[name].has_key?('port')
66
+ end
67
+ Redis.new(:host => host, :port => port)
68
+ end
69
+
70
+ end
@@ -0,0 +1,39 @@
1
+ require File.dirname(__FILE__) + '/../lib/redis_repeater'
2
+
3
+ SERVER_PORT = 6391
4
+ CLIENT_PORT = 6392
5
+ QN = 'queue-1234'
6
+
7
+ SERVERS = ['client', 'server']
8
+
9
+ def start_servers
10
+ SERVERS.each do |s|
11
+ print "starting a #{s}.. "
12
+ `redis-server #{File.dirname(__FILE__) + "/support/#{s}.conf"}`
13
+ puts 'DONE'
14
+ end
15
+ end
16
+
17
+ def stop_servers
18
+ SERVERS.each do |s|
19
+ pid = `cat #{s}.pidfile`.chop
20
+ print "stopping #{s} (PID:#{pid}).. "
21
+ `kill #{pid}`
22
+ puts 'DONE'
23
+ end
24
+ end
25
+
26
+ def start_repeater
27
+ print 'starting the repeater.. '
28
+ # TODO deamonize
29
+ @rthread = Thread.start do
30
+ RedisRepeater.start(File.dirname(__FILE__) + '/support/config')
31
+ end
32
+ puts 'DONE'
33
+ end
34
+
35
+ def stop_repeater
36
+ print 'stopping the repeater.. '
37
+ @rthread.kill
38
+ puts 'DONE'
39
+ end
metadata CHANGED
@@ -1,13 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redis-repeater
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
5
- prerelease: false
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
4
+ prerelease:
5
+ version: 0.0.5
11
6
  platform: ruby
12
7
  authors:
13
8
  - John Crepezzi
@@ -15,7 +10,7 @@ autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
12
 
18
- date: 2010-11-09 00:00:00 -05:00
13
+ date: 2011-03-10 00:00:00 -05:00
19
14
  default_executable:
20
15
  dependencies:
21
16
  - !ruby/object:Gem::Dependency
@@ -26,9 +21,6 @@ dependencies:
26
21
  requirements:
27
22
  - - ">="
28
23
  - !ruby/object:Gem::Version
29
- hash: 3
30
- segments:
31
- - 0
32
24
  version: "0"
33
25
  type: :development
34
26
  version_requirements: *id001
@@ -40,9 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ">="
42
34
  - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
35
  version: "0"
47
36
  type: :runtime
48
37
  version_requirements: *id002
@@ -54,9 +43,6 @@ dependencies:
54
43
  requirements:
55
44
  - - ">="
56
45
  - !ruby/object:Gem::Version
57
- hash: 3
58
- segments:
59
- - 0
60
46
  version: "0"
61
47
  type: :runtime
62
48
  version_requirements: *id003
@@ -69,11 +55,12 @@ extensions: []
69
55
  extra_rdoc_files: []
70
56
 
71
57
  files:
72
- - lib/redis-repeater/scheduler.rb
73
- - lib/redis-repeater/scheduler_job.rb
74
- - lib/redis-repeater/transfer_scheduler_job.rb
75
- - lib/redis-repeater/version.rb
76
- - lib/redis-repeater.rb
58
+ - lib/redis_repeater/scheduler.rb
59
+ - lib/redis_repeater/scheduler_job.rb
60
+ - lib/redis_repeater/transfer_scheduler_job.rb
61
+ - lib/redis_repeater/version.rb
62
+ - lib/redis_repeater.rb
63
+ - spec/spec_helper.rb
77
64
  - bin/redis-repeater
78
65
  has_rdoc: true
79
66
  homepage: http://seejohnrun.github.com/redis-repeater/
@@ -89,25 +76,19 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
76
  requirements:
90
77
  - - ">="
91
78
  - !ruby/object:Gem::Version
92
- hash: 3
93
- segments:
94
- - 0
95
79
  version: "0"
96
80
  required_rubygems_version: !ruby/object:Gem::Requirement
97
81
  none: false
98
82
  requirements:
99
83
  - - ">="
100
84
  - !ruby/object:Gem::Version
101
- hash: 3
102
- segments:
103
- - 0
104
85
  version: "0"
105
86
  requirements: []
106
87
 
107
88
  rubyforge_project: redis-repeater
108
- rubygems_version: 1.3.7
89
+ rubygems_version: 1.5.0
109
90
  signing_key:
110
91
  specification_version: 3
111
92
  summary: Redis Repeater
112
- test_files: []
113
-
93
+ test_files:
94
+ - spec/spec_helper.rb
@@ -1,56 +0,0 @@
1
- require File.dirname(__FILE__) + '/redis-repeater/scheduler.rb'
2
- require File.dirname(__FILE__) + '/redis-repeater/scheduler_job.rb'
3
- require File.dirname(__FILE__) + '/redis-repeater/transfer_scheduler_job.rb'
4
-
5
- require 'yaml'
6
- require 'logger'
7
- require 'fileutils'
8
-
9
- require 'rubygems'
10
- require 'redis'
11
- require 'eventmachine'
12
-
13
- module RedisRepeater
14
-
15
- DefaultRedisHost = 'localhost'
16
- DefaultRedisPort = 6380
17
- LogDefaultFilename = File.dirname(__FILE__) + '/../log/redis-repeater.log'
18
-
19
- def self.start(config_dir)
20
-
21
- # Connect to redis
22
- config = YAML::load File.open("#{config_dir}/config.yml")
23
- redis_from = redis_configure(config, 'origin')
24
- redis_to = redis_configure(config, 'destination')
25
-
26
- # Load the queues from the config file
27
- queues = YAML::load File.open("#{config_dir}/queues.yml")
28
-
29
- # Logger
30
- log_filename = config.has_key?('log') ? config['log'] : LogDefaultFilename
31
- log_path = File.dirname(log_filename)
32
- FileUtils.mkdir_p(log_path)
33
- logger = Logger.new(log_filename)
34
-
35
- # Load the queues into the scheduler
36
- scheduler = Scheduler.new(logger)
37
- queues.each do |name, timeout|
38
- scheduler << TransferSchedulerJob.new(name, timeout, logger, redis_from, redis_to)
39
- end
40
-
41
- # Perform forever
42
- scheduler.perform # TODO make configurable
43
-
44
- end
45
-
46
- def self.redis_configure(config, name)
47
- host = DefaultRedisHost
48
- port = DefaultRedisPort
49
- if config.has_key?(name)
50
- host = config[name]['host'] if config[name].has_key?('host')
51
- port = config[name]['port'] if config[name].has_key?('port')
52
- end
53
- Redis.new(:host => host, :port => port)
54
- end
55
-
56
- end