Class: Zold::Routines::Gc
- Inherits:
-
Object
- Object
- Zold::Routines::Gc
- Defined in:
- lib/zold/commands/routines/gc.rb
Overview
Gargage collecting. It goes through the list of all wallets and removes those that are older than 10 days and don’t have any transactions inside.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2018 Yegor Bugayenko
- License
-
MIT
Instance Method Summary collapse
- #exec(_ = 0) ⇒ Object
-
#initialize(opts, wallets, log: Log::NULL) ⇒ Gc
constructor
A new instance of Gc.
Constructor Details
Instance Method Details
#exec(_ = 0) ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/zold/commands/routines/gc.rb', line 39 def exec(_ = 0) sleep(60) unless @opts['routine-immediately'] cmd = Zold::Remove.new(wallets: @wallets, log: @log) args = ['remove'] seen = 0 removed = 0 @wallets.all.each do |id| seen += 1 next unless @wallets.acq(id) { |w| w.exists? && w.mtime < Time.now - @opts['gc-age'] && w.txns.empty? } cmd.run(args + [id.to_s]) removed += 1 end @log.info("Removed #{removed} empty+old wallets out of #{seen} total") unless removed.zero? end |