Class: Bosh::Director::LogBundlesCleaner
- Defined in:
- lib/bosh/director/log_bundles_cleaner.rb
Instance Method Summary collapse
- #clean ⇒ Object
-
#initialize(blobstore, log_bundle_ttl, logger) ⇒ LogBundlesCleaner
constructor
A new instance of LogBundlesCleaner.
- #register_blobstore_id(blobstore_id) ⇒ Object
Constructor Details
#initialize(blobstore, log_bundle_ttl, logger) ⇒ LogBundlesCleaner
Returns a new instance of LogBundlesCleaner.
4 5 6 7 8 |
# File 'lib/bosh/director/log_bundles_cleaner.rb', line 4 def initialize(blobstore, log_bundle_ttl, logger) @blobstore = blobstore @bundle_lifetime = log_bundle_ttl @logger = logger end |
Instance Method Details
#clean ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/bosh/director/log_bundles_cleaner.rb', line 15 def clean cut_off_time = Time.now - @bundle_lifetime old_bundles = Models::LogBundle.filter("timestamp <= ?", cut_off_time) @logger.info("Deleting #{old_bundles.count} old log bundle(s) before #{cut_off_time}") old_bundles.each do |bundle| begin @logger.info("Deleting log bundle #{bundle.id} with blobstore id #{bundle.blobstore_id}") @blobstore.delete(bundle.blobstore_id) bundle.delete rescue Bosh::Blobstore::BlobstoreError => e @logger.warn("Could not delete #{bundle.blobstore_id}: #{e.inspect}") # Assuming object has been deleted from blobstore by someone else, # cleaning up DB record accordingly bundle.delete if e.kind_of?(Bosh::Blobstore::NotFound) end end end |
#register_blobstore_id(blobstore_id) ⇒ Object
10 11 12 13 |
# File 'lib/bosh/director/log_bundles_cleaner.rb', line 10 def register_blobstore_id(blobstore_id) @logger.info("Registering log bundle with blobstore id #{blobstore_id}") Models::LogBundle.create(blobstore_id: blobstore_id, timestamp: Time.now) end |