warming_drawer 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +20 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +10 -0
- data/lib/warming_drawer/configuration.rb +24 -0
- data/lib/warming_drawer/version.rb +3 -0
- data/lib/warming_drawer/workers/base_worker.rb +39 -0
- data/lib/warming_drawer/workers/url_worker.rb +22 -0
- data/lib/warming_drawer.rb +33 -0
- data/spec/helper.rb +3 -0
- data/spec/url_worker_spec.rb +28 -0
- data/spec/warming_drawer_spec.rb +41 -0
- data/warming_drawer.gemspec +25 -0
- metadata +143 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# WarmingDrawer
|
2
|
+
|
3
|
+
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
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'warming_drawer'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install warming_drawer
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
module WarmingDrawer
|
2
|
+
class Configuration
|
3
|
+
attr_accessor :queue_name, :retry, :queue_system, :basic_auth_username, :basic_auth_password
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
@queue_name = 'high'
|
7
|
+
@retry = false
|
8
|
+
# TODO: would be nice to have values:
|
9
|
+
# :inline, :sidekiq, :resque, :delayed_job
|
10
|
+
# use Rails queue if defined
|
11
|
+
@queue_system = :inline
|
12
|
+
end
|
13
|
+
|
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
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module WarmingDrawer
|
2
|
+
module Workers
|
3
|
+
class BaseWorker
|
4
|
+
|
5
|
+
class << self
|
6
|
+
|
7
|
+
# Sets up perform with or without queue
|
8
|
+
def perform_with(*args)
|
9
|
+
if WarmingDrawer.use_queue?
|
10
|
+
perform_with_queue(args)
|
11
|
+
else
|
12
|
+
perform_without_queue(args)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def options(options_hash)
|
17
|
+
# TODO: change this based on queuing system
|
18
|
+
sidekiq_options options_hash
|
19
|
+
end
|
20
|
+
|
21
|
+
def perform_with_queue(*args)
|
22
|
+
# TODO: change this based on queuing system
|
23
|
+
perform_async(args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def perform_without_queue(*args)
|
27
|
+
new.perform(args)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
# Does the actual work
|
33
|
+
def perform(*args)
|
34
|
+
raise 'Override perform in your worker'
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module WarmingDrawer
|
2
|
+
module Workers
|
3
|
+
class UrlWorker < BaseWorker
|
4
|
+
require 'httpclient'
|
5
|
+
require 'sidekiq'
|
6
|
+
|
7
|
+
# for now since we assume Sidekiq, just add that in.
|
8
|
+
include Sidekiq::Worker
|
9
|
+
|
10
|
+
def perform(*urls)
|
11
|
+
config = WarmingDrawer.configuration
|
12
|
+
auth_present = config.basic_auth_username && config.basic_auth_password
|
13
|
+
|
14
|
+
http = HTTPClient.new
|
15
|
+
http.set_auth(nil, config.basic_auth_username, config.basic_auth_password)
|
16
|
+
|
17
|
+
urls.flatten.each { |url| http.get url }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'warming_drawer/configuration'
|
2
|
+
require 'warming_drawer/version'
|
3
|
+
require 'warming_drawer/workers/base_worker'
|
4
|
+
require 'warming_drawer/workers/url_worker'
|
5
|
+
|
6
|
+
module WarmingDrawer
|
7
|
+
|
8
|
+
# Warms a cache. Delegates to the proper worker depending on the type.
|
9
|
+
#
|
10
|
+
# @example
|
11
|
+
# WarmingDrawer.warm('http://sweet.dev/1', 'http://sweet2.dev/2', :type => :url)
|
12
|
+
def self.warm(*args)
|
13
|
+
options = args.extract_options!
|
14
|
+
options[:type] ||= :url
|
15
|
+
|
16
|
+
if worker = available_worker_for_type(options[:type])
|
17
|
+
# TODO: can this move into worker since its reading config?
|
18
|
+
worker.options queue: configuration.queue_name, retry: configuration.retry
|
19
|
+
worker.perform_with(args)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.use_queue?
|
24
|
+
configuration.queue_system != :inline
|
25
|
+
end
|
26
|
+
|
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
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/spec/helper.rb
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'warming_drawer'
|
5
|
+
|
6
|
+
describe WarmingDrawer::Workers::UrlWorker do
|
7
|
+
|
8
|
+
describe 'with Sidekiq as a queuing system' do
|
9
|
+
before do
|
10
|
+
WarmingDrawer.configure do |config|
|
11
|
+
config.queue_system = :sidekiq
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'queues up http calls'
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'without a queuing system' do
|
19
|
+
before do
|
20
|
+
WarmingDrawer.configure do |config|
|
21
|
+
config.queue_system = :sidekiq
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'makes the http calls directly'
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'helper'
|
2
|
+
require 'minitest/spec'
|
3
|
+
require 'minitest/autorun'
|
4
|
+
require 'warming_drawer'
|
5
|
+
|
6
|
+
describe WarmingDrawer do
|
7
|
+
|
8
|
+
describe 'warm' do
|
9
|
+
|
10
|
+
it 'takes any number of items to warm' do
|
11
|
+
stub_request(:any, 'foo.com').to_return(:body => "good", :status => 200)
|
12
|
+
stub_request(:any, 'yep.com').to_return(:body => "good", :status => 200)
|
13
|
+
lambda {
|
14
|
+
WarmingDrawer.warm 'http://foo.com'
|
15
|
+
WarmingDrawer.warm 'http://foo.com', 'http://yep.com'
|
16
|
+
WarmingDrawer.warm 'http://foo.com', :something => :else
|
17
|
+
}.must_be_silent
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe 'use_queue?' do
|
22
|
+
it 'uses a queue if the queue_system is not inline' do
|
23
|
+
WarmingDrawer.configure { |c| c.queue_system = :sidekiq }
|
24
|
+
WarmingDrawer.use_queue?.must_equal true
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'doesnt use a queue if the queue system is inline' do
|
28
|
+
WarmingDrawer.configure { |c| c.queue_system = :inline }
|
29
|
+
WarmingDrawer.use_queue?.must_equal false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe 'available_worker_for_type' do
|
34
|
+
it 'returns a worker based on a type' do
|
35
|
+
worker = WarmingDrawer.available_worker_for_type(:url)
|
36
|
+
worker.must_be_kind_of Class
|
37
|
+
worker.new.must_be_instance_of WarmingDrawer::Workers::UrlWorker
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'warming_drawer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "warming_drawer"
|
8
|
+
gem.version = WarmingDrawer::VERSION
|
9
|
+
gem.authors = ["Chris Ball"]
|
10
|
+
gem.email = ["chris@echobind.com"]
|
11
|
+
gem.description = %q{Adds a generic worker that hits url's to prewarm caches}
|
12
|
+
gem.summary = %q{Adds a generic worker that hits url's to prewarm caches}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_dependency 'sidekiq'
|
21
|
+
gem.add_dependency 'httpclient'
|
22
|
+
gem.add_development_dependency 'rspec'
|
23
|
+
gem.add_development_dependency 'simplecov'
|
24
|
+
gem.add_development_dependency 'yard'
|
25
|
+
end
|
metadata
ADDED
@@ -0,0 +1,143 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: warming_drawer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Ball
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-11-12 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: sidekiq
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: httpclient
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: simplecov
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: yard
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
description: Adds a generic worker that hits url's to prewarm caches
|
95
|
+
email:
|
96
|
+
- chris@echobind.com
|
97
|
+
executables: []
|
98
|
+
extensions: []
|
99
|
+
extra_rdoc_files: []
|
100
|
+
files:
|
101
|
+
- .gitignore
|
102
|
+
- Gemfile
|
103
|
+
- LICENSE.txt
|
104
|
+
- README.md
|
105
|
+
- Rakefile
|
106
|
+
- lib/warming_drawer.rb
|
107
|
+
- lib/warming_drawer/configuration.rb
|
108
|
+
- lib/warming_drawer/version.rb
|
109
|
+
- lib/warming_drawer/workers/base_worker.rb
|
110
|
+
- lib/warming_drawer/workers/url_worker.rb
|
111
|
+
- spec/helper.rb
|
112
|
+
- spec/url_worker_spec.rb
|
113
|
+
- spec/warming_drawer_spec.rb
|
114
|
+
- warming_drawer.gemspec
|
115
|
+
homepage: ''
|
116
|
+
licenses: []
|
117
|
+
post_install_message:
|
118
|
+
rdoc_options: []
|
119
|
+
require_paths:
|
120
|
+
- lib
|
121
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
122
|
+
none: false
|
123
|
+
requirements:
|
124
|
+
- - ! '>='
|
125
|
+
- !ruby/object:Gem::Version
|
126
|
+
version: '0'
|
127
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: '0'
|
133
|
+
requirements: []
|
134
|
+
rubyforge_project:
|
135
|
+
rubygems_version: 1.8.23
|
136
|
+
signing_key:
|
137
|
+
specification_version: 3
|
138
|
+
summary: Adds a generic worker that hits url's to prewarm caches
|
139
|
+
test_files:
|
140
|
+
- spec/helper.rb
|
141
|
+
- spec/url_worker_spec.rb
|
142
|
+
- spec/warming_drawer_spec.rb
|
143
|
+
has_rdoc:
|