redis_resque_initializer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in redis_resque_initializer.gemspec
4
+ gemspec
data/README ADDED
@@ -0,0 +1,6 @@
1
+ Initializes Redis and Resque
2
+
3
+ Usage:
4
+
5
+ Create an initializer in your app, with this line:
6
+ RedisResqueInitializer.initialize_redis_and_resque( ::Rails.root.to_s, ::Rails.env.to_s )
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,55 @@
1
+ require "yaml"
2
+
3
+ module RedisResqueInitializer
4
+
5
+ def initialize_redis_and_resque( app_root = ".", app_env = "development" )
6
+
7
+ # redis
8
+ # @see https://github.com/ezmobius/redis-rb
9
+ # redis options:
10
+ # host default "127.0.0.1"
11
+ # port default 6379
12
+ # db default 0
13
+ # timeout default 5
14
+ # password no default
15
+ # logger no default
16
+ # thread_safe no default; necessary for threaded environments; what about fibered environments?
17
+
18
+ # redis-namespace
19
+ # @see https://github.com/defunkt/redis-namespace
20
+ # namespace options:
21
+ # namespace no default
22
+
23
+ yml = YAML.load( IO.read( "#{app_root}/config/redis.yml" ) ) [ app_env ]
24
+ config = Hash[ yml.map { |k,v| [ k.to_sym, v ] } ] # mlanett 2011-02 poor man's symbolize_keys
25
+
26
+ redis = Redis.connect( config )
27
+ STDERR.puts "[#{Process.pid}] redis_resque_initializer: connecting to #{config.inspect}"
28
+
29
+ if namespace = config[:namespace] then
30
+ $redis = Redis::Namespace.new( namespace, :redis => redis )
31
+ else
32
+ $redis = redis
33
+ end
34
+
35
+ # Support Phusion Passenger smart spawning/forking mode.
36
+ # Reset the connection so it isn"t accidentally shared between multiple processes.
37
+ begin
38
+ PhusionPassenger.on_event(:starting_worker_process) do |forked|
39
+ if forked
40
+ $redis.client.reconnect
41
+ STDERR.puts "[#{Process.pid}] redis_resque_initializer: reconnected to #{config.inspect}"
42
+ end
43
+ end
44
+ rescue ArgumentError, NameError => error
45
+ # NameError: Ruby 1.8
46
+ # ArgumentError: Ruby 1.9
47
+ # This statement block intentionally left blank.
48
+ end
49
+
50
+ Resque.redis = $redis
51
+
52
+ end # initialize
53
+
54
+ extend RedisResqueInitializer
55
+ end
@@ -0,0 +1,3 @@
1
+ module RedisResqueInitializer
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "redis_resque_initializer/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "redis_resque_initializer"
7
+ s.version = RedisResqueInitializer::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Mark Lanett"]
10
+ s.email = ["mark.lanett@gmail.com"]
11
+ s.homepage = ""
12
+ s.summary = %q{Initializes Redis and Resque}
13
+ s.description = %Q{RedisResqueInitializer.initialize_redis_and_resque( ::Rails.root.to_s, ::Rails.env.to_s )}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_dependency "redis"
21
+ s.add_dependency "redis-namespace"
22
+ s.add_dependency "resque"
23
+ end
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: redis_resque_initializer
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Mark Lanett
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-04-03 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: redis
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ type: :runtime
32
+ version_requirements: *id001
33
+ - !ruby/object:Gem::Dependency
34
+ name: redis-namespace
35
+ prerelease: false
36
+ requirement: &id002 !ruby/object:Gem::Requirement
37
+ none: false
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ segments:
42
+ - 0
43
+ version: "0"
44
+ type: :runtime
45
+ version_requirements: *id002
46
+ - !ruby/object:Gem::Dependency
47
+ name: resque
48
+ prerelease: false
49
+ requirement: &id003 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ type: :runtime
58
+ version_requirements: *id003
59
+ description: RedisResqueInitializer.initialize_redis_and_resque( ::Rails.root.to_s, ::Rails.env.to_s )
60
+ email:
61
+ - mark.lanett@gmail.com
62
+ executables: []
63
+
64
+ extensions: []
65
+
66
+ extra_rdoc_files: []
67
+
68
+ files:
69
+ - .gitignore
70
+ - Gemfile
71
+ - README
72
+ - Rakefile
73
+ - lib/redis_resque_initializer.rb
74
+ - lib/redis_resque_initializer/version.rb
75
+ - redis_resque_initializer.gemspec
76
+ has_rdoc: true
77
+ homepage: ""
78
+ licenses: []
79
+
80
+ post_install_message:
81
+ rdoc_options: []
82
+
83
+ require_paths:
84
+ - lib
85
+ required_ruby_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ segments:
91
+ - 0
92
+ version: "0"
93
+ required_rubygems_version: !ruby/object:Gem::Requirement
94
+ none: false
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ segments:
99
+ - 0
100
+ version: "0"
101
+ requirements: []
102
+
103
+ rubyforge_project:
104
+ rubygems_version: 1.3.7
105
+ signing_key:
106
+ specification_version: 3
107
+ summary: Initializes Redis and Resque
108
+ test_files: []
109
+