warming_drawer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ lib/**/*.rb
2
+ -
3
+ LICENSE
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2012 Chris Ball and echobind, inc.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # WarmingDrawer
2
+ [![Build Status](https://secure.travis-ci.org/echobind/warming_drawer.png?branch=master)](https://travis-ci.org/echobind/warming_drawer) [![Dependency Status](https://gemnasium.com/echobind/warming_drawer.png)](https://gemnasium.com/echobind/warming_drawer) [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/echobind/warming_drawer)
2
3
 
3
4
  Warms caches based on a specified url using an optional background queueing system. For now, only supports Sidekiq or the lack of a queing system, but in the future will support others.
4
5
 
@@ -1,6 +1,6 @@
1
1
  module WarmingDrawer
2
2
  class Configuration
3
- attr_accessor :queue_name, :retry, :queue_system, :basic_auth_username, :basic_auth_password
3
+ attr_accessor :queue_name, :retry, :queue_system, :basic_auth_username, :basic_auth_password, :preheat_url
4
4
 
5
5
  def initialize
6
6
  @queue_name = 'high'
@@ -12,13 +12,4 @@ module WarmingDrawer
12
12
  end
13
13
 
14
14
  end
15
-
16
- class << self
17
- attr_accessor :configuration
18
- end
19
-
20
- def self.configure
21
- self.configuration ||= Configuration.new
22
- yield(configuration)
23
- end
24
15
  end
@@ -1,3 +1,3 @@
1
1
  module WarmingDrawer
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -5,12 +5,31 @@ require 'warming_drawer/workers/url_worker'
5
5
 
6
6
  module WarmingDrawer
7
7
 
8
+ class << self
9
+ attr_accessor :configuration
10
+ end
11
+
12
+ def self.configure
13
+ self.configuration ||= Configuration.new
14
+ yield(configuration)
15
+ end
16
+
8
17
  # Warms a cache. Delegates to the proper worker depending on the type.
18
+ # If being used within Rails, returns false unless action_controller caching is enabled.
9
19
  #
20
+ # @param [Array] Arguments or Array to warm
21
+ # @return [Boolean]
10
22
  # @example
11
23
  # WarmingDrawer.warm('http://sweet.dev/1', 'http://sweet2.dev/2', :type => :url)
24
+ # => true
12
25
  def self.warm(*args)
13
- options = args.extract_options!
26
+ return false unless cachable?
27
+
28
+ if args.last.is_a?(Hash)
29
+ options = args.pop
30
+ else
31
+ options = {}
32
+ end
14
33
  options[:type] ||= :url
15
34
 
16
35
  if worker = available_worker_for_type(options[:type])
@@ -18,16 +37,31 @@ module WarmingDrawer
18
37
  worker.options queue: configuration.queue_name, retry: configuration.retry
19
38
  worker.perform_with(args)
20
39
  end
40
+
41
+ !worker.nil?
21
42
  end
22
43
 
44
+ # Returns true if a queuing system is defined
45
+ # @return [Boolean]
23
46
  def self.use_queue?
24
47
  configuration.queue_system != :inline
25
48
  end
26
49
 
27
- def self.available_worker_for_type(type)
28
- if worker_name = Workers.constants.detect {|c| c.downcase.match /^#{type.to_s.downcase}/}
29
- WarmingDrawer::Workers.const_get worker_name.to_s
50
+
51
+ private
52
+
53
+ def self.cachable?
54
+ (using_rails? && Rails.configuration.action_controller.perform_caching) || !using_rails?
55
+ end
56
+
57
+ def self.using_rails?
58
+ defined?(::Rails)
59
+ end
60
+
61
+ def self.available_worker_for_type(type)
62
+ if worker_name = Workers.constants.detect {|c| c.downcase.match /^#{type.to_s.downcase}/}
63
+ WarmingDrawer::Workers.const_get worker_name.to_s
64
+ end
30
65
  end
31
- end
32
66
 
33
67
  end
@@ -7,15 +7,27 @@ describe WarmingDrawer do
7
7
 
8
8
  describe 'warm' do
9
9
 
10
- it 'takes any number of items to warm' do
10
+ before do
11
11
  stub_request(:any, 'foo.com').to_return(:body => "good", :status => 200)
12
12
  stub_request(:any, 'yep.com').to_return(:body => "good", :status => 200)
13
+ end
14
+
15
+ it 'takes any number of items to warm' do
13
16
  lambda {
14
17
  WarmingDrawer.warm 'http://foo.com'
15
18
  WarmingDrawer.warm 'http://foo.com', 'http://yep.com'
16
- WarmingDrawer.warm 'http://foo.com', :something => :else
17
19
  }.must_be_silent
18
20
  end
21
+
22
+ it 'returns true if the warming request is queued' do
23
+ warmed = WarmingDrawer.warm 'http://foo.com'
24
+ warmed.must_equal true
25
+ end
26
+
27
+ it 'returns false if the warming request fails' do
28
+ warmed = WarmingDrawer.warm 'http://foo.com', :type => :fakeworker
29
+ warmed.must_equal false
30
+ end
19
31
  end
20
32
 
21
33
  describe 'use_queue?' do
@@ -10,16 +10,18 @@ Gem::Specification.new do |gem|
10
10
  gem.email = ["chris@echobind.com"]
11
11
  gem.description = %q{Adds a generic worker that hits url's to prewarm caches}
12
12
  gem.summary = %q{Adds a generic worker that hits url's to prewarm caches}
13
- gem.homepage = ""
13
+ gem.homepage = "http://github.com/echobind/warming_drawer"
14
14
 
15
15
  gem.files = `git ls-files`.split($/)
16
16
  gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ["lib", "spec"]
19
19
 
20
20
  gem.add_dependency 'sidekiq'
21
21
  gem.add_dependency 'httpclient'
22
22
  gem.add_development_dependency 'rspec'
23
23
  gem.add_development_dependency 'simplecov'
24
24
  gem.add_development_dependency 'yard'
25
+ gem.add_development_dependency 'rake'
26
+ gem.add_development_dependency 'webmock'
25
27
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warming_drawer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-12 00:00:00.000000000 Z
12
+ date: 2012-11-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sidekiq
@@ -91,6 +91,38 @@ dependencies:
91
91
  - - ! '>='
92
92
  - !ruby/object:Gem::Version
93
93
  version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: webmock
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
94
126
  description: Adds a generic worker that hits url's to prewarm caches
95
127
  email:
96
128
  - chris@echobind.com
@@ -99,8 +131,10 @@ extensions: []
99
131
  extra_rdoc_files: []
100
132
  files:
101
133
  - .gitignore
134
+ - .travis.yml
135
+ - .yardopts
102
136
  - Gemfile
103
- - LICENSE.txt
137
+ - LICENSE
104
138
  - README.md
105
139
  - Rakefile
106
140
  - lib/warming_drawer.rb
@@ -112,12 +146,13 @@ files:
112
146
  - spec/url_worker_spec.rb
113
147
  - spec/warming_drawer_spec.rb
114
148
  - warming_drawer.gemspec
115
- homepage: ''
149
+ homepage: http://github.com/echobind/warming_drawer
116
150
  licenses: []
117
151
  post_install_message:
118
152
  rdoc_options: []
119
153
  require_paths:
120
154
  - lib
155
+ - spec
121
156
  required_ruby_version: !ruby/object:Gem::Requirement
122
157
  none: false
123
158
  requirements:
data/LICENSE.txt DELETED
@@ -1,22 +0,0 @@
1
- Copyright (c) 2012 Chris Ball
2
-
3
- MIT License
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining
6
- a copy of this software and associated documentation files (the
7
- "Software"), to deal in the Software without restriction, including
8
- without limitation the rights to use, copy, modify, merge, publish,
9
- distribute, sublicense, and/or sell copies of the Software, and to
10
- permit persons to whom the Software is furnished to do so, subject to
11
- the following conditions:
12
-
13
- The above copyright notice and this permission notice shall be
14
- included in all copies or substantial portions of the Software.
15
-
16
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.