resque-swapper 0.1

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) Endel Dreyer
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,4 @@
1
+ require 'resque'
2
+ require 'resque-swapper/resque-swapper'
3
+
4
+ Resque.servers = 'config/resque.yml'
@@ -0,0 +1,44 @@
1
+ require 'yaml'
2
+
3
+ module Resque
4
+ def self.swap server
5
+ current = Resque.redis
6
+
7
+ # Create Redis connection.
8
+ Resque.redis = server_connect(server, @swapper_config[server])
9
+ if block_given?
10
+ yield Resque
11
+ Resque.redis = current
12
+ end
13
+ Resque
14
+ end
15
+
16
+ def self.servers &block
17
+ @swapper_config.collect do |server, config|
18
+ swap(server, &block)
19
+ end
20
+ end
21
+
22
+ def self.servers= (path)
23
+ @swapper_redis = Hash.new
24
+ if File.exists?(path)
25
+ config = YAML.load_file(path)
26
+ # Force configuration keys as symbols
27
+ @swapper_config = Hash[config.collect {|n| [n[0].to_sym, Hash[n[1].collect{|c| [c[0].to_sym, c[1]] }] ] }]
28
+ else
29
+ puts "Warning: config file doesn't not exists."
30
+ end
31
+ end
32
+
33
+ def self.server(server)
34
+ server_connect(server, @swapper_config[server])
35
+ end
36
+
37
+ protected
38
+ def self.server_connect(server, config)
39
+ unless @swapper_redis[server]
40
+ @swapper_redis[server] = Redis.new(config)
41
+ end
42
+ @swapper_redis[server]
43
+ end
44
+ end
@@ -0,0 +1,25 @@
1
+ require 'fileutils'
2
+
3
+ namespace 'resque' do
4
+ desc 'Append configuration to Resque server.'
5
+ task 'config' do
6
+ name = ENV['NAME'] || 'default'
7
+ host = ENV['HOST'] || 'localhost'
8
+ port = ENV['PORT'] || '6379'
9
+
10
+ file = 'config/resque.yml'
11
+ FileUtils.mkdir_p('config')
12
+
13
+ append_config = <<YML
14
+ #{name}:
15
+ host: #{host}
16
+ port: #{port}
17
+
18
+ YML
19
+ File.open(file, 'a') do |f|
20
+ f.write(append_config)
21
+ end
22
+ puts "Write into #{file}: "
23
+ puts append_config
24
+ end
25
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: resque-swapper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: "0.1"
6
+ platform: ruby
7
+ authors:
8
+ - Endel Dreyer
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-08-07 00:00:00 -03:00
14
+ default_executable:
15
+ dependencies: []
16
+
17
+ description: " Swapping tool for Resque server on runtime.\n"
18
+ email: endel.dreyer@gmail.com
19
+ executables: []
20
+
21
+ extensions: []
22
+
23
+ extra_rdoc_files: []
24
+
25
+ files:
26
+ - LICENSE
27
+ - lib/resque-swapper/resque-swapper.rb
28
+ - lib/resque-swapper/tasks.rb
29
+ - lib/resque-swapper.rb
30
+ has_rdoc: true
31
+ homepage: http://github.com/endel/resque-swapper
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: "0"
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: "0"
51
+ requirements: []
52
+
53
+ rubyforge_project:
54
+ rubygems_version: 1.6.2
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Swapping tool for Resque server on runtime.
58
+ test_files: []
59
+