Class: GitlabJanitor::BaseCleaner

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_janitor/base_cleaner.rb

Defined Under Namespace

Classes: Model

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#deadlineObject (readonly)

Returns the value of attribute deadline.



28
29
30
# File 'lib/gitlab_janitor/base_cleaner.rb', line 28

def deadline
  @deadline
end

#delayObject (readonly)

Returns the value of attribute delay.



28
29
30
# File 'lib/gitlab_janitor/base_cleaner.rb', line 28

def delay
  @delay
end

#loggerObject (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

Returns:

  • (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