maxaf-fluke 0.0.3 → 0.0.4

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/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ === 0.0.4 2009-09-09
2
+
3
+ * HTTP proxy support.
4
+ * Added MIME type recording.
5
+
1
6
  === 0.0.3 2009-09-08
2
7
 
3
8
  * Added Watcher#url_strftime to simplify time-based URL generation.
@@ -0,0 +1,13 @@
1
+ class AddMethToWatchers < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :watchers do |t|
4
+ t.string :meth, :null => false, :default => 'GET'
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ change_table :watchers do |t|
10
+ t.remove :meth
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ class AddUrlToResults < ActiveRecord::Migration
2
+ def self.up
3
+ change_table :results do |t|
4
+ t.string :url, :null => true
5
+ end
6
+ end
7
+
8
+ def self.down
9
+ change_table :results do |t|
10
+ t.remove :url
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,19 @@
1
+ :db:
2
+ adapter: jdbcmysql
3
+ encoding: utf8
4
+ reconnect: true
5
+ database: fluke
6
+ pool: 5
7
+ username: fluke
8
+ password: fluke
9
+ host: localhost
10
+ port: 3306
11
+ :s3:
12
+ :connection:
13
+ :access_key_id: booya
14
+ :secret_access_key: kasha
15
+ :bucket:
16
+ :result: my-result-bucket
17
+ :proxy:
18
+ :host: localhost
19
+ :port: 8080
@@ -0,0 +1,3 @@
1
+ watch :foo do
2
+ self.url_generator { |raw| "#{raw}?_=#{Time.now.to_i}" }
3
+ end
@@ -0,0 +1,3 @@
1
+ watch :foo_two do
2
+ self.url_strftime(-3.weeks)
3
+ end
data/fluke.gemspec ADDED
@@ -0,0 +1,48 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{fluke}
5
+ s.version = "0.0.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Max Afonov"]
9
+ s.date = %q{2009-09-09}
10
+ s.default_executable = %q{fluke}
11
+ s.description = %q{A simple resource observer designed to detect change over time.}
12
+ s.email = ["max@bumnetworks.com"]
13
+ s.executables = ["fluke"]
14
+ s.extra_rdoc_files = ["History.txt", "Manifest.txt"]
15
+ s.files = ["bin/fluke", "db/migrate/0001_create_watchers.rb", "db/migrate/0002_create_results.rb", "db/migrate/0003_add_meth_to_watchers.rb", "db/migrate/0004_add_url_to_results.rb", "examples/dot-fluke.yml", "examples/gen_url.rb", "examples/strftime_url.rb", "fluke.gemspec", "History.txt", "lib/fluke/cli.rb", "lib/fluke/monkey_patch.rb", "lib/fluke.rb", "lib/fluke/result.rb", "lib/fluke/watcher.rb", "Manifest.txt", "Rakefile", "README.rdoc", "script/console", "script/destroy", "script/generate", "tasks/ar.rake", "test/test_fluke_cli.rb", "test/test_fluke.rb", "test/test_helper.rb"]
16
+ s.homepage = %q{http://github.com/maxaf/fluke}
17
+ s.rdoc_options = ["--main", "README.rdoc"]
18
+ s.require_paths = ["lib"]
19
+ s.rubyforge_project = %q{fluke}
20
+ s.rubygems_version = %q{1.3.3}
21
+ s.summary = %q{A simple resource observer designed to detect change over time.}
22
+ s.test_files = ["test/test_fluke_cli.rb", "test/test_helper.rb", "test/test_fluke.rb"]
23
+
24
+ if s.respond_to? :specification_version then
25
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
26
+ s.specification_version = 3
27
+
28
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
29
+ s.add_runtime_dependency(%q<activerecord>, [">= 2.3"])
30
+ s.add_runtime_dependency(%q<aws-s3>, [">= 0.6.2"])
31
+ s.add_runtime_dependency(%q<httpclient>, [">= 2.1.5.2"])
32
+ s.add_runtime_dependency(%q<pvande-differ>, [">= 0.1.1"])
33
+ s.add_development_dependency(%q<hoe>, [">= 2.3.3"])
34
+ else
35
+ s.add_dependency(%q<activerecord>, [">= 2.3"])
36
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
37
+ s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
38
+ s.add_dependency(%q<pvande-differ>, [">= 0.1.1"])
39
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
40
+ end
41
+ else
42
+ s.add_dependency(%q<activerecord>, [">= 2.3"])
43
+ s.add_dependency(%q<aws-s3>, [">= 0.6.2"])
44
+ s.add_dependency(%q<httpclient>, [">= 2.1.5.2"])
45
+ s.add_dependency(%q<pvande-differ>, [">= 0.1.1"])
46
+ s.add_dependency(%q<hoe>, [">= 2.3.3"])
47
+ end
48
+ end
data/lib/fluke.rb CHANGED
@@ -9,7 +9,7 @@ require 'activerecord'
9
9
  require 'aws/s3'
10
10
 
11
11
  module Fluke
12
- VERSION = '0.0.3'
12
+ VERSION = '0.0.4'
13
13
  ROOT = Dir.new(File.expand_path(File.dirname(__FILE__) + "/../"))
14
14
  DEFAULT_CONF_PATH = "~/.fluke.yml"
15
15
  @@verbose = false
@@ -55,12 +55,17 @@ module Fluke
55
55
  }
56
56
  p.merge! opts
57
57
  @@log_here = p[p[:log_here]] || p[:stderr]
58
+
58
59
  begin
59
60
  @@conf = YAML::load(File.open(p[:conf_path]))
61
+ if !@@conf[:proxy].nil?
62
+ @@conf[:s3][:connection][:proxy] = @@conf[:proxy]
63
+ @@conf[:proxy_string] = "http://#{@@conf[:proxy][:host]}:#{@@conf[:proxy][:port]}"
64
+ end
60
65
  ActiveRecord::Base.colorize_logging = false
61
66
  ActiveRecord::Base.logger = Logger.new(@@log_here) if verbose?
62
67
  ActiveRecord::Base.establish_connection(@@conf[:db])
63
- AWS::S3::Base.establish_connection!(@@conf[:s3][:auth])
68
+ AWS::S3::Base.establish_connection!(@@conf[:s3][:connection])
64
69
  Result::Body.set_current_bucket_to @@conf[:s3][:bucket][:result]
65
70
  rescue => e
66
71
  STDERR.puts e.inspect
@@ -73,8 +78,12 @@ module Fluke
73
78
  watchers.each do |n,watcher|
74
79
  watcher.thread = Thread.new do
75
80
  while true
76
- watcher.run
77
- watcher.wait
81
+ begin
82
+ watcher.run
83
+ watcher.wait
84
+ rescue => e
85
+ Fluke.log { "#{watcher}: failed to run: #{e.inspect}; backtrace: #{e.backtrace.join("; ")}" }
86
+ end
78
87
  end
79
88
  end
80
89
  end
data/lib/fluke/result.rb CHANGED
@@ -25,12 +25,17 @@ module Fluke
25
25
  Body.exists? self.body_key
26
26
  end
27
27
 
28
- def self.from_response(watcher, content, generated_url = nil)
29
- checksum = Digest::SHA1.hexdigest(content)
28
+ def self.from_response(args)
29
+ opts = {
30
+ :mime_type => 'binary/octet-stream',
31
+ :generated_url => nil
32
+ }.merge(args)
33
+
34
+ checksum = Digest::SHA1.hexdigest(opts[:content])
30
35
  result = Result.new :checksum => checksum
31
- result.watcher = watcher
32
- if generated_url and generated_url != watcher.url
33
- result.url = generated_url
36
+ result.watcher = opts[:watcher]
37
+ if opts[:generated_url] and opts[:generated_url] != opts[:watcher].url
38
+ result.url = opts[:generated_url]
34
39
  end
35
40
  result.save
36
41
 
@@ -39,7 +44,7 @@ module Fluke
39
44
  Fluke.log { "#{result.watcher} exists: #{result.body_key}" }
40
45
  else
41
46
  Fluke.log { "#{result.watcher} store: #{result.body_key}" }
42
- Body.store(result.body_key, content.dup)
47
+ Body.store(result.body_key, opts[:content].dup, :content_type => opts[:mime_type])
43
48
  end
44
49
  end
45
50
 
data/lib/fluke/watcher.rb CHANGED
@@ -20,18 +20,18 @@ module Fluke
20
20
  end
21
21
 
22
22
  def run_file(path)
23
- result = Result.from_response(self, File.read(path), "file://#{path}")
23
+ result = Result.from_response :watcher => self, :content => File.read(path), :generated_url => "file://#{path}"
24
24
  end
25
25
 
26
26
  def run_http(generated_url)
27
- hc = HTTPClient.new
27
+ hc = HTTPClient.new :proxy => Fluke.conf[:proxy_string], :user_agent => "Fluke/#{Fluke::VERSION}"
28
28
  http_method = self.meth.downcase.to_sym
29
29
  unless hc.respond_to?(http_method)
30
30
  Fluke::log { "#{self}: invalid method '#{http_method}', converting to :get" }
31
31
  http_method = :get
32
32
  end
33
33
  res = hc.send(http_method, generated_url, { 'Cache-Control' => 'no-cache', 'Pragma' => 'no-cache' })
34
- result = Result.from_response(self, res.body.dump.dup, generated_url)
34
+ result = Result.from_response :watcher => self, :content => res.body.dump.dup, :generated_url => generated_url, :mime_type => res.header['Content-Type']
35
35
  end
36
36
 
37
37
  def url_generator(&block)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: maxaf-fluke
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Afonov
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-09-08 00:00:00 -07:00
12
+ date: 2009-09-09 00:00:00 -07:00
13
13
  default_executable: fluke
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -76,6 +76,12 @@ files:
76
76
  - bin/fluke
77
77
  - db/migrate/0001_create_watchers.rb
78
78
  - db/migrate/0002_create_results.rb
79
+ - db/migrate/0003_add_meth_to_watchers.rb
80
+ - db/migrate/0004_add_url_to_results.rb
81
+ - examples/dot-fluke.yml
82
+ - examples/gen_url.rb
83
+ - examples/strftime_url.rb
84
+ - fluke.gemspec
79
85
  - History.txt
80
86
  - lib/fluke/cli.rb
81
87
  - lib/fluke/monkey_patch.rb