Class: PactBroker::DB::DeleteOverwrittenDataTask

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/pact_broker/tasks/delete_overwritten_data_task.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ DeleteOverwrittenDataTask

Returns a new instance of DeleteOverwrittenDataTask.



10
11
12
13
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 10

def initialize &block
  @max_age = 7
  rake_task(&block)
end

Instance Attribute Details

#database_connectionObject

Returns the value of attribute database_connection.



4
5
6
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 4

def database_connection
  @database_connection
end

#deletion_limitObject

Returns the value of attribute deletion_limit.



7
8
9
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 7

def deletion_limit
  @deletion_limit
end

#dry_runObject

Returns the value of attribute dry_run.



8
9
10
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 8

def dry_run
  @dry_run
end

#loggerObject

Returns the value of attribute logger.



6
7
8
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 6

def logger
  @logger
end

#max_ageObject

Returns the value of attribute max_age.



5
6
7
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 5

def max_age
  @max_age
end

Instance Method Details

#output(string, payload = {}) ⇒ Object



48
49
50
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 48

def output string, payload = {}
  logger ? logger.info(string, payload) : puts("#{string} #{payload.to_json}")
end

#rake_task(&block) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/pact_broker/tasks/delete_overwritten_data_task.rb', line 15

def rake_task &block
  namespace :pact_broker do
    namespace :db do
      desc "Delete overwritten pacts and verifications from database"
      task :delete_overwritten_data do | _t, _args |
        require "pact_broker/db/delete_overwritten_data"
        require "yaml"

        instance_eval(&block)
        options = {}

        prefix = dry_run ? "[DRY RUN] " : ""

        if max_age
          options[:max_age] = max_age
          output "#{prefix}Deleting overwritten pact publications and verifications older than #{max_age} days"
        else
          output "#{prefix}Deleting overwritten pact publications and verifications"
        end

        options[:limit] = deletion_limit if deletion_limit
        options[:dry_run] = dry_run

        start_time = Time.now
        results = PactBroker::DB::DeleteOverwrittenData.call(database_connection, options)
        end_time = Time.now
        elapsed_seconds = (end_time - start_time).to_i
        output "Results (#{elapsed_seconds} seconds)", results
      end
    end
  end
end