Class: Zold::JournaledPipeline
- Inherits:
-
Object
- Object
- Zold::JournaledPipeline
- Defined in:
- lib/zold/node/journaled_pipeline.rb
Overview
The entrance that keeps a journal for each wallet
Defined Under Namespace
Classes: Wallets
Instance Method Summary collapse
-
#initialize(pipeline, dir) ⇒ JournaledPipeline
constructor
A new instance of JournaledPipeline.
-
#push(id, body, wallets, log, lifetime: 6) ⇒ Object
Returns a list of modifed wallets (as Zold::Id).
- #start {|_self| ... } ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(pipeline, dir) ⇒ JournaledPipeline
Returns a new instance of JournaledPipeline.
60 61 62 63 |
# File 'lib/zold/node/journaled_pipeline.rb', line 60 def initialize(pipeline, dir) @pipeline = pipeline @dir = dir end |
Instance Method Details
#push(id, body, wallets, log, lifetime: 6) ⇒ Object
Returns a list of modifed wallets (as Zold::Id)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/zold/node/journaled_pipeline.rb', line 78 def push(id, body, wallets, log, lifetime: 6) DirItems.new(@dir).fetch.each do |f| f = File.join(@dir, f) File.delete(f) if File.mtime(f) < Time.now - lifetime * 60 * 60 end journal = File.join(@dir, "#{Time.now.utc.iso8601.gsub(/[^0-9]/, '-')}-#{id}") jlog = Logger.new(journal) jlog.level = Logger::DEBUG jlog.formatter = Log::COMPACT jlog.info("push(#{id}, #{body.length} bytes): starting...") jlog.info("Time: #{Time.now.utc.iso8601}") jlog.info("Zold gem version: #{Zold::VERSION}") modified = @pipeline.push(id, body, JournaledPipeline::Wallets.new(wallets, jlog), Log::Tee.new(log, jlog)) jlog.info("push(#{id}): done") FileUtils.mv(journal, journal + '-done') modified end |
#start {|_self| ... } ⇒ Object
65 66 67 68 69 |
# File 'lib/zold/node/journaled_pipeline.rb', line 65 def start raise 'Block must be given to start()' unless block_given? FileUtils.mkdir_p(@dir) yield(self) end |
#to_json ⇒ Object
71 72 73 74 75 |
# File 'lib/zold/node/journaled_pipeline.rb', line 71 def to_json @pipeline.to_json.merge( 'dir': @dir ) end |