Sha256: 118d30af84425dbf792e3d0e803df764f70eb07a7e8e239f6f517b5aa91fd8a2
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
require 'rubygems' gem 'shovel' require 'ruby-debug' require 'shovel' class Example #include the shovel mixin include MediaShelf::Shovel def initialize super #make the ingest directory. root = File.dirname(__FILE__) indir = File.join(root, 'ingest') faildir= File.join(root, 'failboat') FileUtils.mkdir_p faildir unless File.exist?(faildir) #configure an ingest process to scan our ingest directory for compressed archives every 10s, consider an archive #stable if it doesn't change in 10s, and don't suppress file events for files that are already in there(!) flow = configure_process(indir, 4, 1, %w(**/*.zip **/*.tgz **/*.tar.gz **/*.tar), false) #let's react to stable events by... flow.add_reaction(:stable) do |file| #extracting the file... extract(file) do |inner| #and doing some stuff to it puts "i'm doing stuff to #{inner} of size #{File.size(inner)}" #and possibly raising an exception, so we can demonstrate exception handling raise "This file is Exceptional! !" if file =~ /.*\.gz/ end end flow.add_reaction(:stable) do |file| #now let's delete it. these reactions are executed _in_order! FileUtils.rm(file, :verbose=>true) end flow.add_reaction(:removed) do |file| d("so long #{file}!") end flow.on_exception(RuntimeError) do |f, e| d "URF!, an exception was thrown on #{f}! Welcome to the FAILboat!" d e.message FileUtils.mv(f, File.join(faildir, "%s.%d"%[File.basename(f),Time.now]), :verbose=>true) end end end #create our example class ex = Example.new #and start it. ex.start
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
shovel-0.0.1 | spec/example.rb |