maidservice 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -1
- data/TODO.md +1 -4
- data/lib/maidservice.rb +17 -34
- data/lib/maidservice/configuration.rb +52 -0
- data/lib/maidservice/listener.rb +50 -0
- data/lib/maidservice/railtie.rb +15 -0
- data/lib/maidservice/tasks/maidservice.rake +8 -0
- data/lib/maidservice/version.rb +1 -1
- data/maidservice.gemspec +6 -2
- data/spec/spec_helper.rb +3 -0
- metadata +71 -10
- data/lib/maidservice/tasks.rb +0 -8
- data/tasks/maidservice.rake +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0d0bb84642e3c3cfcc81f86391352c0783a5a6af
|
4
|
+
data.tar.gz: 456d903a1c87157fecdd4bed51da34b225b63cbd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95b89eba31a243141ad2a8d416320303e9d854d45a246b87f822c594af548f3fab264a99a8fb3d033c3cccd47797f7bc0f6b98209d35cf2db3a9d07250663b84
|
7
|
+
data.tar.gz: 731b5cd2250c7abfddde51a6f4af0f1ee89ce0579a967ebdaf44cab8f3d3f58ec76300a85145490630ed4dc33af1af86e3e72bbeb67f53a71c72a1582df33e05
|
data/README.md
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
Distributed Page Cache Clearing using Redis pub/sub
|
4
4
|
|
5
|
+
Note: This gem has the power to remove files from your server. Be very careful about how you use it so you don't end up force removing your root. I'm working on adding some protections against this.
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
7
9
|
Add this line to your application's Gemfile:
|
@@ -24,10 +26,17 @@ Maidservice will need to be run as a daemon to listen for page expiring events.
|
|
24
26
|
|
25
27
|
It hooks into the existing `expire_page` logic and make sure that all servers running maidservice will also expire those pages.
|
26
28
|
|
27
|
-
You can also expire folders and files directly by calling
|
29
|
+
You can also expire folders and files directly by calling. Be very careful to pass in a full path here. Because it will remove whatever file you give it.
|
28
30
|
|
29
31
|
MaidService.clear "page/path/to/clear"
|
30
32
|
|
33
|
+
If you want to configure your redis instance for maidservice
|
34
|
+
|
35
|
+
# initializers/maidservice.rb
|
36
|
+
Maidservice.configure do |config|
|
37
|
+
config.redis = Redis.new # can also be a redis url
|
38
|
+
end
|
39
|
+
|
31
40
|
## Contributing
|
32
41
|
|
33
42
|
1. Fork it
|
data/TODO.md
CHANGED
data/lib/maidservice.rb
CHANGED
@@ -1,44 +1,27 @@
|
|
1
|
-
require
|
1
|
+
require 'maidservice/configuration'
|
2
|
+
require "maidservice/listener"
|
3
|
+
require 'maidservice/railtie'
|
2
4
|
require 'redis'
|
3
5
|
|
4
6
|
module Maidservice
|
7
|
+
class << self
|
8
|
+
def redis
|
9
|
+
Maidservice.configuration.redis
|
10
|
+
end
|
5
11
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
# Quote from the resque/worker.
|
13
|
-
# Fix buffering so we can `rake resque:scheduler > scheduler.log` and
|
14
|
-
# get output from the child in there.
|
15
|
-
$stdout.sync = true
|
16
|
-
$stderr.sync = true
|
17
|
-
|
18
|
-
redis = ::Redis.new
|
19
|
-
|
20
|
-
begin
|
21
|
-
redis.subscribe('pages.expire') do |on|
|
22
|
-
on.subscribe do |channel, subscriptions|
|
23
|
-
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)"
|
24
|
-
end
|
25
|
-
|
26
|
-
on.message do |channel, message|
|
27
|
-
puts "##{channel}: #{message}"
|
28
|
-
redis.unsubscribe if message == "exit"
|
29
|
-
end
|
12
|
+
# Publishing to redis
|
13
|
+
# Playing with fire here
|
14
|
+
def clear(full_path)
|
15
|
+
redis.publish('expire_page.action_controller', full_path)
|
16
|
+
end
|
30
17
|
|
31
|
-
|
32
|
-
|
33
|
-
|
18
|
+
# Delegate the active support notifications
|
19
|
+
def subscribe
|
20
|
+
ActiveSupport::Notifications.subscribe('expire_page.action_controller') do |*args|
|
21
|
+
event = ActiveSupport::Notifications::Event.new *args
|
22
|
+
Maidservice.clear(event.payload[:path])
|
34
23
|
end
|
35
|
-
rescue ::Redis::BaseConnectionError => error
|
36
|
-
puts "#{error}, retrying in 1s"
|
37
|
-
sleep 1
|
38
|
-
retry
|
39
24
|
end
|
40
|
-
|
41
|
-
# never gets here.
|
42
25
|
end
|
43
26
|
|
44
27
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'redis-namespace'
|
2
|
+
|
3
|
+
module Maidservice
|
4
|
+
class << self
|
5
|
+
def configure
|
6
|
+
yield configuration
|
7
|
+
end
|
8
|
+
|
9
|
+
def configuration
|
10
|
+
@configuration ||= Maidservice::Configuration.new
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Configuration
|
15
|
+
|
16
|
+
# Accepts:
|
17
|
+
# 1. A 'hostname:port' String
|
18
|
+
# 2. A 'hostname:port:db' String (to select the Redis db)
|
19
|
+
# 3. A 'hostname:port/namespace' String (to set the Redis namespace)
|
20
|
+
# 4. A Redis URL String 'redis://host:port'
|
21
|
+
# 5. An instance of `Redis`, `Redis::Client`, `Redis::DistRedis`,
|
22
|
+
# or `Redis::Namespace`.
|
23
|
+
def redis=(server)
|
24
|
+
case server
|
25
|
+
when String
|
26
|
+
if server =~ /redis\:\/\//
|
27
|
+
redis = Redis.connect(:url => server, :thread_safe => true)
|
28
|
+
else
|
29
|
+
server, namespace = server.split('/', 2)
|
30
|
+
host, port, db = server.split(':')
|
31
|
+
redis = Redis.new(:host => host, :port => port,
|
32
|
+
:thread_safe => true, :db => db)
|
33
|
+
end
|
34
|
+
namespace ||= :maidservice
|
35
|
+
|
36
|
+
@redis = Redis::Namespace.new(namespace, :redis => redis)
|
37
|
+
when Redis::Namespace
|
38
|
+
@redis = server
|
39
|
+
else
|
40
|
+
@redis = Redis::Namespace.new(:maidservice, :redis => server)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Returns the current Redis connection. If none has been created, will
|
45
|
+
# create a new one.
|
46
|
+
def redis
|
47
|
+
return @redis if @redis
|
48
|
+
self.redis = Redis.respond_to?(:connect) ? Redis.connect : "localhost:6379"
|
49
|
+
self.redis
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
module Maidservice
|
2
|
+
module Listener
|
3
|
+
|
4
|
+
# Daemon that runs and listens
|
5
|
+
def self.run
|
6
|
+
$0 = "Maidservice: Starting"
|
7
|
+
|
8
|
+
# get output from the child in there.
|
9
|
+
$stdout.sync = true
|
10
|
+
$stderr.sync = true
|
11
|
+
|
12
|
+
redis = Maidservice.redis
|
13
|
+
|
14
|
+
begin
|
15
|
+
|
16
|
+
redis.subscribe('expire_page.action_controller') do |on|
|
17
|
+
on.subscribe do |channel, subscriptions|
|
18
|
+
puts "Subscribed to ##{channel} (#{subscriptions} subscriptions)"
|
19
|
+
end
|
20
|
+
|
21
|
+
on.message do |channel, message|
|
22
|
+
puts "##{channel}: #{message}"
|
23
|
+
clear_page(message)
|
24
|
+
end
|
25
|
+
|
26
|
+
on.unsubscribe do |channel, subscriptions|
|
27
|
+
puts "Unsubscribed from ##{channel} (#{subscriptions} subscriptions)"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
rescue ::Redis::BaseConnectionError => error
|
32
|
+
puts "#{error}, retrying in 1s"
|
33
|
+
sleep 1
|
34
|
+
retry
|
35
|
+
end
|
36
|
+
|
37
|
+
# never gets here.
|
38
|
+
end
|
39
|
+
|
40
|
+
# TODO: duplicate of rails expire_page
|
41
|
+
def self.clear_page(full_path)
|
42
|
+
return unless ActionController::Base.perform_caching
|
43
|
+
File.delete(full_path) if File.exist?(full_path)
|
44
|
+
File.delete(full_path + '.gz') if File.exist?(full_path + '.gz')
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails'
|
2
|
+
|
3
|
+
module Maidservice
|
4
|
+
class Railtie < ::Rails::Railtie
|
5
|
+
|
6
|
+
initializer "maidservice.subscribe" do
|
7
|
+
Maidservice.subscribe
|
8
|
+
end
|
9
|
+
|
10
|
+
rake_tasks do
|
11
|
+
Dir[File.join(File.dirname(__FILE__),'tasks/*.rake')].each { |f| load f }
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
data/lib/maidservice/version.rb
CHANGED
data/maidservice.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = Maidservice::VERSION
|
9
9
|
spec.authors = ["Scott Carleton"]
|
10
10
|
spec.email = ["scott@artsicle.com"]
|
11
|
-
spec.description = %q{Distributed Page Cache Clearing using Redis pub/sub}
|
11
|
+
spec.description = %q{Distributed Page Cache Clearing using Redis pub/sub and hooking into Rails page caching}
|
12
12
|
spec.summary = %q{Distributed Page Cache Clearing using Redis pub/sub}
|
13
13
|
spec.homepage = "https://github.com/ScotterC/maidservice"
|
14
14
|
spec.license = "MIT"
|
@@ -20,6 +20,10 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.add_development_dependency "bundler", "~> 1.3"
|
22
22
|
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "rspec"
|
24
|
+
spec.add_development_dependency 'railties'
|
23
25
|
|
24
|
-
spec.add_dependency "redis", "3
|
26
|
+
spec.add_dependency "redis-namespace", "~> 1.3"
|
27
|
+
spec.add_dependency "redis", "> 3"
|
28
|
+
spec.add_dependency "activesupport", "< 4"
|
25
29
|
end
|
data/spec/spec_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: maidservice
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Scott Carleton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-10-
|
11
|
+
date: 2013-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,21 +38,78 @@ dependencies:
|
|
38
38
|
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: railties
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: redis-namespace
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '1.3'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '1.3'
|
41
83
|
- !ruby/object:Gem::Dependency
|
42
84
|
name: redis
|
43
85
|
requirement: !ruby/object:Gem::Requirement
|
44
86
|
requirements:
|
45
|
-
- - '
|
87
|
+
- - '>'
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>'
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: activesupport
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - <
|
46
102
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
103
|
+
version: '4'
|
48
104
|
type: :runtime
|
49
105
|
prerelease: false
|
50
106
|
version_requirements: !ruby/object:Gem::Requirement
|
51
107
|
requirements:
|
52
|
-
- -
|
108
|
+
- - <
|
53
109
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
55
|
-
description: Distributed Page Cache Clearing using Redis pub/sub
|
110
|
+
version: '4'
|
111
|
+
description: Distributed Page Cache Clearing using Redis pub/sub and hooking into
|
112
|
+
Rails page caching
|
56
113
|
email:
|
57
114
|
- scott@artsicle.com
|
58
115
|
executables: []
|
@@ -66,10 +123,13 @@ files:
|
|
66
123
|
- Rakefile
|
67
124
|
- TODO.md
|
68
125
|
- lib/maidservice.rb
|
69
|
-
- lib/maidservice/
|
126
|
+
- lib/maidservice/configuration.rb
|
127
|
+
- lib/maidservice/listener.rb
|
128
|
+
- lib/maidservice/railtie.rb
|
129
|
+
- lib/maidservice/tasks/maidservice.rake
|
70
130
|
- lib/maidservice/version.rb
|
71
131
|
- maidservice.gemspec
|
72
|
-
-
|
132
|
+
- spec/spec_helper.rb
|
73
133
|
homepage: https://github.com/ScotterC/maidservice
|
74
134
|
licenses:
|
75
135
|
- MIT
|
@@ -94,4 +154,5 @@ rubygems_version: 2.0.3
|
|
94
154
|
signing_key:
|
95
155
|
specification_version: 4
|
96
156
|
summary: Distributed Page Cache Clearing using Redis pub/sub
|
97
|
-
test_files:
|
157
|
+
test_files:
|
158
|
+
- spec/spec_helper.rb
|
data/lib/maidservice/tasks.rb
DELETED
data/tasks/maidservice.rake
DELETED