Module: Watcher
- Extended by:
- Fallen
- Defined in:
- lib/filer/watcher.rb
Constant Summary collapse
- FILER_LOG =
"filer_watcher.log"
Class Method Summary collapse
Class Method Details
.instance(settings) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/filer/watcher.rb', line 10 def self.instance(settings) @settings = settings Watcher.pid_file 'filer_watcher.pid' Watcher.stderr FILER_LOG Watcher.stdout FILER_LOG self.s3 self end |
.notify(msg) ⇒ Object
28 29 30 31 32 |
# File 'lib/filer/watcher.rb', line 28 def self.notify(msg) Notifier.notify( title: "Filer", message: msg) end |
.run ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/filer/watcher.rb', line 34 def self.run begin while running? dirs_files = @settings[:directories].flat_map do |d| Dir["#{d}/**/*"].reject {|f| File.directory?(f)}. map {|f| [d, f]} end dirs_files.each do |(d, f)| key = @s3.s3_key(d, f) @s3.put_file(key, f) fd = Filer::Filed.new( key: key, attachment: Base64.encode64(File.read(f))) fd.save File.delete(f) end self.notify("Processed #{dirs_files.size} files") unless dirs_files.empty? sleep 10 end rescue Exception => e self.notify("Filer encountered an error. " << "See #{File.dirname(__FILE__)}/#{FILER_LOG}") raise e end end |
.s3 ⇒ Object
19 20 21 22 23 24 25 26 |
# File 'lib/filer/watcher.rb', line 19 def self.s3 params = [:s3_key, :s3_secret, :s3_bucket].map {|m| @settings[m]} unless params.compact.size == 3 puts "Please run filer configure-s3 first" exit end @s3 ||= Filer::S3.new(*params) end |