Class: Exekutor::Internal::CLI::Cleanup

Inherits:
Object
  • Object
show all
Includes:
ApplicationLoader
Defined in:
lib/exekutor/internal/cli/cleanup.rb

Overview

Cleanup for the CLI

Constant Summary

Constants included from ApplicationLoader

ApplicationLoader::LOADING_MESSAGE

Instance Method Summary collapse

Methods included from ApplicationLoader

#clear_application_loading_message, #different_time_zone?, #load_application, #print_time_zone_warning

Constructor Details

#initialize(options) ⇒ Cleanup

Returns a new instance of Cleanup.



16
17
18
# File 'lib/exekutor/internal/cli/cleanup.rb', line 16

def initialize(options)
  @global_options = options
end

Instance Method Details

#cleanup_jobs(options) ⇒ Object

Cleans up the jobs table

See Also:



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/exekutor/internal/cli/cleanup.rb', line 38

def cleanup_jobs(options)
  load_application options[:environment], print_message: !quiet?

  ActiveSupport.on_load(:active_record, yield: true) do
    clear_application_loading_message
    print_time_zone_warning if different_time_zone? && !quiet?

    timeout = job_cleanup_timeout(options)
    purged_count = cleaner.cleanup_jobs before: timeout.hours.ago, status: job_cleanup_statuses(options)

    print_job_cleanup_result(options, purged_count) unless quiet?
  end
end

#cleanup_workers(options) ⇒ Object

Cleans up the workers table

See Also:



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/exekutor/internal/cli/cleanup.rb', line 22

def cleanup_workers(options)
  load_application options[:environment], print_message: !quiet?

  ActiveSupport.on_load(:active_record, yield: true) do
    clear_application_loading_message
    print_time_zone_warning if different_time_zone? && !quiet?

    timeout = worker_cleanup_timeout(options)
    workers = cleaner.cleanup_workers timeout: timeout.hours

    print_worker_cleanup_result(options, workers) unless quiet?
  end
end