filbunke 1.6.0 → 1.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.6.0
1
+ 1.7.0
data/bin/filbunked CHANGED
@@ -1,13 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  $0=File.join(File.dirname(__FILE__), 'filbunked')
3
3
  require 'rubygems'
4
- require 'filbunke'
5
4
  require 'yaml'
6
5
  require 'getoptlong'
7
6
 
8
7
  raw_opts = GetoptLong.new(
9
8
  [ '--help', '-h', GetoptLong::NO_ARGUMENT ],
10
- [ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT ]
9
+ [ '--config', '-c', GetoptLong::REQUIRED_ARGUMENT ],
10
+ [ '--dev', '-d', GetoptLong::NO_ARGUMENT]
11
11
  )
12
12
 
13
13
  opts = {}
@@ -15,21 +15,35 @@ raw_opts.each do |opt, arg|
15
15
  opts[opt] = arg
16
16
  end
17
17
 
18
- if Process.uid != 0 then
19
- puts "Filbunke should be started as root!"
20
- exit 1
21
- end
22
-
23
18
  if opts['--help'] || opts['--config'] == nil || opts['--config'] == ""
24
19
  puts "Usage: filbunked -c <config_file.yml>"
25
20
  exit 1
26
21
  else
27
- child_process = fork {
22
+ if opts['--dev'] then
23
+ require 'lib/filbunke.rb'
24
+
28
25
  config_file = File.read(opts['--config'])
29
26
  config = YAML.load(config_file)
30
- daemon = Filbunke::Daemon.new(config)
31
- Process::UID.change_privilege(Etc.getpwnam(config["user"]).uid)
32
- daemon.run!
33
- }
34
- Process.detach(child_process)
27
+ daemon = Filbunke::Daemon.new(config, true)
28
+
29
+ daemon.run!
30
+ else
31
+ if Process.uid != 0 then
32
+ puts "Filbunke should be started as root!"
33
+ exit 1
34
+ end
35
+
36
+ require 'filbunke'
37
+ child_process = fork {
38
+ config_file = File.read(opts['--config'])
39
+ config = YAML.load(config_file)
40
+ daemon = Filbunke::Daemon.new(config)
41
+ Process::UID.change_privilege(Etc.getpwnam(config["user"]).uid)
42
+ daemon.run!
43
+ }
44
+ Process.detach(child_process)
45
+
46
+ end
47
+
48
+
35
49
  end
@@ -2,7 +2,7 @@ require 'net/http'
2
2
 
3
3
  class HttpEvictCache < Filbunke::Callbacks
4
4
 
5
- def on_update(file)
5
+ def on_update(file, local_file_path)
6
6
  begin
7
7
  evict_http = Net::HTTP.new(@config["host"], @config["port"].to_i)
8
8
  evict_http.start do |http|
@@ -0,0 +1,27 @@
1
+ class HttpFileUpload < Filbunke::Callbacks
2
+
3
+ def on_update(file, local_file_path)
4
+ begin
5
+ basename = ::File.basename(file.path).chomp(".json")
6
+ basename =~ /(.*)_(\d)/
7
+ classname = $1
8
+ id = $2
9
+
10
+ upload_path = "/model/update/#{classname}/#{id}"
11
+ file_contents = ::File.read(local_file_path)
12
+
13
+ uri = "http://#{@config['host']}:#{@config['port']}#{upload_path}"
14
+ response = ::Typhoeus::Request.post(uri, :body => file_contents)
15
+
16
+ if response.code.to_i != 200
17
+ @logger.log "Failed to upload: #{file.path}. Server responded with #{response.code}"
18
+ end
19
+
20
+ rescue StandardError => e
21
+ @logger.log(e.message)
22
+ @logger.log("Failed to upload entry: #{file.path}")
23
+ @logger.log(e.backtrace.join("\n"))
24
+ end
25
+ end
26
+
27
+ end
data/filbunke.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{filbunke}
8
- s.version = "1.6.0"
8
+ s.version = "1.7.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Wouter de Bie"]
12
- s.date = %q{2010-12-10}
12
+ s.date = %q{2011-02-14}
13
13
  s.default_executable = %q{filbunked}
14
14
  s.description = %q{Filbunke client and library}
15
15
  s.email = %q{wouter@deltaprojects.se}
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
23
23
  "bin/filbunked",
24
24
  "doc/examples/filbunke_config.yml",
25
25
  "doc/examples/http_evict_cache.rb",
26
+ "doc/examples/http_file_upload.rb",
26
27
  "doc/examples/init_script",
27
28
  "filbunke.gemspec",
28
29
  "lib/filbunke.rb",
@@ -6,7 +6,7 @@ module Filbunke
6
6
  @logger = logger
7
7
  end
8
8
 
9
- def on_update(file)
9
+ def on_update(file, local_file_path)
10
10
  end
11
11
 
12
12
  end
@@ -61,8 +61,6 @@ module Filbunke
61
61
  failure ? last_checkpoint : (new_checkpoint || last_checkpoint)
62
62
  end
63
63
 
64
-
65
-
66
64
  def update_files!(last_checkpoint)
67
65
  with_updated_files(last_checkpoint) {}
68
66
  end
@@ -132,9 +130,9 @@ module Filbunke
132
130
  end
133
131
  end
134
132
 
135
- def run_callbacks(file)
133
+ def run_callbacks(file, local_file_path)
136
134
  @callbacks.each do |callback|
137
- callback.on_update(file)
135
+ callback.on_update(file, local_file_path)
138
136
  end
139
137
  end
140
138
 
@@ -191,7 +189,7 @@ module Filbunke
191
189
  @logger.log "Failed to update file #{file.url}, error code = #{response.code}"
192
190
  success = false
193
191
  end
194
- run_callbacks(file) if success
192
+ run_callbacks(file, local_file_path) if success
195
193
  rescue StandardError => e
196
194
  @logger.log "Failed to update file #{file.url}: #{e.message}"
197
195
  success = false
@@ -1,15 +1,15 @@
1
1
  module Filbunke
2
2
  class Daemon
3
3
 
4
- def initialize(config)
4
+ def initialize(config, local = false)
5
5
  @config = config
6
6
  @clients = []
7
- setup_clients!
8
- write_pid!(config["pid_file"])
7
+ setup_clients!(local)
8
+ write_pid!(config["pid_file"]) unless local
9
9
  end
10
10
 
11
- def setup_clients!
12
- @logger = Logger.new(@config["log_file"])
11
+ def setup_clients!(local = false)
12
+ @logger = Logger.new(@config["log_file"], local)
13
13
  @logger.log("Initializing filbunked")
14
14
  @config["repositories"].each do |repository_name, repository_config|
15
15
  @logger.log("Initializing repository: #{repository_name}")
@@ -39,12 +39,10 @@ module Filbunke
39
39
  @logger.log("Starting filbunked version #{version}")
40
40
  while true
41
41
  begin
42
-
43
- @clients.each do |client|
44
- new_checkpoint = client.update_files!(checkpoint_for_repository(client.repository))
45
- update_checkpoint_for_repository(client.repository, new_checkpoint)
46
- end
47
-
42
+ @clients.each do |client|
43
+ new_checkpoint = client.update_files!(checkpoint_for_repository(client.repository))
44
+ update_checkpoint_for_repository(client.repository, new_checkpoint)
45
+ end
48
46
  rescue StandardError => e
49
47
  @logger.log("Died.. #{e.message}")
50
48
  exit 1
@@ -1,13 +1,18 @@
1
1
  module Filbunke
2
2
  class Logger
3
3
 
4
- def initialize(log_file_name)
5
- @log_file = ::File.open(log_file_name, "a")
4
+ def initialize(log_file_name, local)
5
+ @local = local
6
+ @log_file = ::File.open(log_file_name, "a") unless local
6
7
  end
7
8
 
8
9
  def log(msg)
9
- @log_file.write("#{Time.now}: #{msg}\n")
10
- @log_file.flush
10
+ if @local then
11
+ puts "#{Time.now}: #{msg}"
12
+ else
13
+ @log_file.write("#{Time.now}: #{msg}\n")
14
+ @log_file.flush
15
+ end
11
16
  end
12
17
 
13
18
  end
data/lib/filbunke.rb CHANGED
@@ -6,9 +6,9 @@ require 'digest/md5'
6
6
  require 'typhoeus'
7
7
  require 'open4'
8
8
 
9
- require 'filbunke/client.rb'
10
- require 'filbunke/file.rb'
11
- require 'filbunke/repository.rb'
12
- require 'filbunke/callbacks.rb'
13
- require 'filbunke/daemon.rb'
14
- require 'filbunke/logger.rb'
9
+ require File.expand_path(File.dirname(__FILE__) + '/filbunke/client.rb')
10
+ require File.expand_path(File.dirname(__FILE__) + '/filbunke/file.rb')
11
+ require File.expand_path(File.dirname(__FILE__) + '/filbunke/repository.rb')
12
+ require File.expand_path(File.dirname(__FILE__) + '/filbunke/callbacks.rb')
13
+ require File.expand_path(File.dirname(__FILE__) + '/filbunke/daemon.rb')
14
+ require File.expand_path(File.dirname(__FILE__) + '/filbunke/logger.rb')
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 1
7
- - 6
7
+ - 7
8
8
  - 0
9
- version: 1.6.0
9
+ version: 1.7.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Wouter de Bie
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2010-12-10 00:00:00 +01:00
17
+ date: 2011-02-14 00:00:00 +01:00
18
18
  default_executable: filbunked
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -88,6 +88,7 @@ files:
88
88
  - bin/filbunked
89
89
  - doc/examples/filbunke_config.yml
90
90
  - doc/examples/http_evict_cache.rb
91
+ - doc/examples/http_file_upload.rb
91
92
  - doc/examples/init_script
92
93
  - filbunke.gemspec
93
94
  - lib/filbunke.rb