Class: GitlabJanitor::BaseCleaner
- Inherits:
-
Object
- Object
- GitlabJanitor::BaseCleaner
- Defined in:
- lib/gitlab_janitor/base_cleaner.rb
Direct Known Subclasses
Defined Under Namespace
Classes: Model
Instance Attribute Summary collapse
-
#deadline ⇒ Object
readonly
Returns the value of attribute deadline.
-
#delay ⇒ Object
readonly
Returns the value of attribute delay.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
Instance Method Summary collapse
- #clean(remove: false) ⇒ Object
- #exiting? ⇒ Boolean
-
#initialize(delay: 10, deadline: 1.second, logger: GitlabJanitor::Util.logger, **_args) ⇒ BaseCleaner
constructor
A new instance of BaseCleaner.
- #log_exception(text) ⇒ Object
Constructor Details
#initialize(delay: 10, deadline: 1.second, logger: GitlabJanitor::Util.logger, **_args) ⇒ BaseCleaner
Returns a new instance of BaseCleaner.
30 31 32 33 34 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 30 def initialize(delay: 10, deadline: 1.second, logger: GitlabJanitor::Util.logger, **_args) @delay = delay @deadline = deadline @logger = logger.tagged(self.class.to_s) end |
Instance Attribute Details
#deadline ⇒ Object (readonly)
Returns the value of attribute deadline.
28 29 30 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 28 def deadline @deadline end |
#delay ⇒ Object (readonly)
Returns the value of attribute delay.
28 29 30 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 28 def delay @delay end |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
28 29 30 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 28 def logger @logger end |
Instance Method Details
#clean(remove: false) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 36 def clean(remove: false) return nil if @cleaned_at && (::Process.clock_gettime(::Process::CLOCK_MONOTONIC) - @cleaned_at) < @delay.seconds do_clean(remove: remove) @cleaned_at = ::Process.clock_gettime(::Process::CLOCK_MONOTONIC) true end |
#exiting? ⇒ Boolean
45 46 47 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 45 def exiting? GitlabJanitor::Util.exiting? end |
#log_exception(text) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/gitlab_janitor/base_cleaner.rb', line 49 def log_exception(text) yield rescue StandardError => e logger.error("Exception in #{text}: #{e}") logger.error e.backtrace end |