Class: PactBroker::DB::DeleteOverwrittenDataTask
- Inherits:
-
Rake::TaskLib
- Object
- Rake::TaskLib
- PactBroker::DB::DeleteOverwrittenDataTask
- Defined in:
- lib/pact_broker/tasks/delete_overwritten_data_task.rb
Instance Attribute Summary collapse
-
#database_connection ⇒ Object
Returns the value of attribute database_connection.
-
#deletion_limit ⇒ Object
Returns the value of attribute deletion_limit.
-
#dry_run ⇒ Object
Returns the value of attribute dry_run.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#max_age ⇒ Object
Returns the value of attribute max_age.
Instance Method Summary collapse
-
#initialize(&block) ⇒ DeleteOverwrittenDataTask
constructor
A new instance of DeleteOverwrittenDataTask.
- #output(string, payload = {}) ⇒ Object
- #rake_task(&block) ⇒ Object
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_connection ⇒ Object
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_limit ⇒ Object
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_run ⇒ Object
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 |
#logger ⇒ Object
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_age ⇒ Object
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) = {} prefix = dry_run ? "[DRY RUN] " : "" if max_age [: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 [:limit] = deletion_limit if deletion_limit [:dry_run] = dry_run start_time = Time.now results = PactBroker::DB::DeleteOverwrittenData.call(database_connection, ) end_time = Time.now elapsed_seconds = (end_time - start_time).to_i output "Results (#{elapsed_seconds} seconds)", results end end end end |