pact_broker 2.71.0 → 2.72.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/test.yml +1 -21
- data/CHANGELOG.md +11 -0
- data/Dockerfile +5 -1
- data/docker-compose-ci-mysql.yml +37 -0
- data/lib/pact_broker/api/pact_broker_urls.rb +5 -1
- data/lib/pact_broker/api/resources/metadata_resource_methods.rb +23 -0
- data/lib/pact_broker/api/resources/pact.rb +2 -13
- data/lib/pact_broker/api/resources/pact_resource_methods.rb +23 -0
- data/lib/pact_broker/api/resources/pact_version.rb +3 -0
- data/lib/pact_broker/api/resources/tagged_pact_versions.rb +4 -0
- data/lib/pact_broker/api/resources/verifications.rb +2 -4
- data/lib/pact_broker/db/clean_incremental.rb +132 -22
- data/lib/pact_broker/db/delete_overwritten_data.rb +55 -27
- data/lib/pact_broker/domain/tag.rb +42 -0
- data/lib/pact_broker/domain/verification.rb +87 -0
- data/lib/pact_broker/metrics/service.rb +5 -3
- data/lib/pact_broker/pacts/all_pact_publications.rb +8 -0
- data/lib/pact_broker/pacts/repository.rb +35 -11
- data/lib/pact_broker/tasks/clean_task.rb +9 -3
- data/lib/pact_broker/tasks/delete_overwritten_data_task.rb +23 -7
- data/lib/pact_broker/test/test_data_builder.rb +24 -0
- data/lib/pact_broker/version.rb +1 -1
- data/script/docker-container/test.sh +3 -0
- data/script/docker/db-psql.sh +3 -0
- data/script/docker/db-reload.sh +11 -0
- data/script/pry.rb +25 -0
- data/script/seed.rb +1 -0
- data/script/test/run-rake-on-docker-compose-mysql.sh +8 -0
- data/spec/features/delete_tagged_pact_versions_spec.rb +2 -2
- data/spec/features/get_pact_spec.rb +2 -2
- data/spec/features/get_pact_version.rb +26 -3
- data/spec/fixtures/approvals/clean_incremental_dry_run.approved.json +100 -0
- data/spec/lib/pact_broker/api/pact_broker_urls_spec.rb +6 -0
- data/spec/lib/pact_broker/api/resources/pact_spec.rb +20 -9
- data/spec/lib/pact_broker/api/resources/tagged_pact_versions_spec.rb +10 -2
- data/spec/lib/pact_broker/api/resources/verifications_spec.rb +7 -3
- data/spec/lib/pact_broker/db/clean_incremental_spec.rb +9 -1
- data/spec/lib/pact_broker/db/delete_overwritten_data_spec.rb +71 -11
- data/spec/lib/pact_broker/domain/tag_spec.rb +23 -9
- data/spec/lib/pact_broker/domain/verification_spec.rb +49 -0
- data/spec/lib/pact_broker/metrics/service_spec.rb +4 -1
- data/spec/lib/pact_broker/pacts/repository_spec.rb +54 -7
- data/spec/migrations/change_migration_strategy_spec.rb +1 -1
- metadata +12 -2
@@ -11,65 +11,93 @@ module PactBroker
|
|
11
11
|
def initialize database_connection, options = {}
|
12
12
|
@db = database_connection
|
13
13
|
@options = options
|
14
|
-
@
|
14
|
+
@cut_off_date = options[:max_age] ? (DateTime.now - options[:max_age]) : DateTime.now
|
15
|
+
@limit = options[:limit] || 1000
|
15
16
|
end
|
16
17
|
|
17
18
|
def call
|
19
|
+
require 'pact_broker/pacts/pact_publication'
|
20
|
+
require 'pact_broker/domain/verification'
|
21
|
+
|
18
22
|
deleted_counts = {}
|
19
23
|
kept_counts = {}
|
20
24
|
|
21
|
-
|
22
25
|
deleted_counts.merge!(delete_overwritten_pact_publications)
|
23
26
|
deleted_counts.merge!(delete_overwritten_verifications)
|
24
27
|
deleted_counts.merge!(delete_orphan_pact_versions)
|
28
|
+
deleted_counts.merge!(delete_webhook_data)
|
25
29
|
|
26
30
|
kept_counts[:pact_publications] = db[:pact_publications].count
|
27
31
|
kept_counts[:verification_results] = db[:verifications].count
|
28
32
|
kept_counts[:pact_versions] = db[:pact_versions].count
|
33
|
+
kept_counts[:triggered_webhooks] = db[:triggered_webhooks].count
|
29
34
|
|
30
|
-
|
31
|
-
|
35
|
+
if dry_run?
|
36
|
+
to_keep = deleted_counts.keys.each_with_object({}) do | table_name, new_counts |
|
37
|
+
new_counts[table_name] = kept_counts[table_name] - deleted_counts[table_name]
|
38
|
+
end
|
39
|
+
{ toDelete: deleted_counts, toKeep: to_keep }
|
40
|
+
else
|
41
|
+
{ deleted: deleted_counts, kept: kept_counts }
|
42
|
+
end
|
32
43
|
end
|
33
44
|
|
34
45
|
private
|
35
46
|
|
36
|
-
attr_reader :db, :options, :
|
47
|
+
attr_reader :db, :options, :cut_off_date, :limit
|
48
|
+
|
49
|
+
def dry_run?
|
50
|
+
options[:dry_run]
|
51
|
+
end
|
52
|
+
|
53
|
+
def delete_webhook_data
|
54
|
+
ids_to_keep = db[:latest_triggered_webhooks].select(:id)
|
55
|
+
resolved_ids_to_delete = db[:triggered_webhooks]
|
56
|
+
.where(id: ids_to_keep)
|
57
|
+
.invert
|
58
|
+
.where(Sequel.lit('created_at < ?', cut_off_date))
|
59
|
+
.limit(limit)
|
60
|
+
.collect{ |row| row[:id] }
|
37
61
|
|
38
|
-
|
39
|
-
|
40
|
-
db[:triggered_webhooks].where(id: triggered_webhook_ids).delete
|
62
|
+
PactBroker::Webhooks::TriggeredWebhook.where(id: resolved_ids_to_delete).delete unless dry_run?
|
63
|
+
{ triggered_webhooks: resolved_ids_to_delete.count }
|
41
64
|
end
|
42
65
|
|
43
66
|
def delete_orphan_pact_versions
|
44
67
|
referenced_pact_version_ids = db[:pact_publications].select(:pact_version_id).union(db[:verifications].select(:pact_version_id))
|
45
|
-
pact_version_ids_to_delete = db[:pact_versions].where(id: referenced_pact_version_ids).invert
|
46
|
-
|
47
|
-
pact_version_ids_to_delete.
|
48
|
-
deleted_counts
|
68
|
+
pact_version_ids_to_delete = db[:pact_versions].where(id: referenced_pact_version_ids).invert.order(:id).limit(limit).collect{ |row| row[:id] }
|
69
|
+
db[:pact_versions].where(id: pact_version_ids_to_delete).delete unless dry_run?
|
70
|
+
{ pact_versions: pact_version_ids_to_delete.count }
|
49
71
|
end
|
50
72
|
|
51
73
|
def delete_overwritten_pact_publications
|
52
|
-
|
53
|
-
|
54
|
-
|
74
|
+
ids_to_keep = db[:latest_pact_publication_ids_for_consumer_versions].select(:pact_publication_id)
|
75
|
+
|
76
|
+
resolved_ids_to_delete = db[:pact_publications]
|
77
|
+
.where(id: ids_to_keep)
|
55
78
|
.invert
|
56
|
-
.where(Sequel.lit('created_at < ?',
|
79
|
+
.where(Sequel.lit('created_at < ?', cut_off_date))
|
80
|
+
.order(:id)
|
81
|
+
.limit(limit)
|
82
|
+
.collect{ |row| row[:id] }
|
57
83
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
deleted_counts
|
84
|
+
PactBroker::Pacts::PactPublication.where(id: resolved_ids_to_delete).delete unless dry_run?
|
85
|
+
|
86
|
+
{ pact_publications: resolved_ids_to_delete.count }
|
62
87
|
end
|
63
88
|
|
64
89
|
def delete_overwritten_verifications
|
65
|
-
|
66
|
-
|
90
|
+
ids_to_keep = db[:latest_verification_id_for_pact_version_and_provider_version].select(:verification_id)
|
91
|
+
resolved_ids_to_delete = db[:verifications]
|
92
|
+
.where(id: ids_to_keep)
|
67
93
|
.invert
|
68
|
-
.where(Sequel.lit('created_at < ?',
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
94
|
+
.where(Sequel.lit('created_at < ?', cut_off_date))
|
95
|
+
.order(:id)
|
96
|
+
.limit(limit)
|
97
|
+
.collect{ |row| row[:id] }
|
98
|
+
|
99
|
+
PactBroker::Domain::Verification.where(id: resolved_ids_to_delete).delete unless dry_run?
|
100
|
+
{ verification_results: resolved_ids_to_delete.count }
|
73
101
|
end
|
74
102
|
end
|
75
103
|
end
|
@@ -13,6 +13,48 @@ module PactBroker
|
|
13
13
|
dataset_module do
|
14
14
|
include PactBroker::Repositories::Helpers
|
15
15
|
|
16
|
+
def latest_tags
|
17
|
+
tags_versions_join = {
|
18
|
+
Sequel[:tags][:version_id] => Sequel[:versions][:id],
|
19
|
+
}
|
20
|
+
|
21
|
+
latest_tags_versions_join = {
|
22
|
+
Sequel[:latest_tags][:name] => Sequel[:tags][:name],
|
23
|
+
Sequel[:latest_tags][:latest_order] => Sequel[:versions][:order],
|
24
|
+
Sequel[:latest_tags][:pacticipant_id] => Sequel[:versions][:pacticipant_id],
|
25
|
+
}
|
26
|
+
|
27
|
+
latest_tags = PactBroker::Domain::Tag
|
28
|
+
.select_group(Sequel[:tags][:name], Sequel[:versions][:pacticipant_id])
|
29
|
+
.select_append{ max(order).as(latest_order) }
|
30
|
+
.join(:versions, tags_versions_join)
|
31
|
+
|
32
|
+
PactBroker::Domain::Tag
|
33
|
+
.select_all_qualified
|
34
|
+
.join(:versions,
|
35
|
+
{ Sequel[:tags][:version_id] => Sequel[:versions][:id] }
|
36
|
+
)
|
37
|
+
.join(latest_tags, latest_tags_versions_join, { table_alias: :latest_tags })
|
38
|
+
end
|
39
|
+
|
40
|
+
# Ron's fancy join
|
41
|
+
# performs every so slightly better
|
42
|
+
def latest_tags_2
|
43
|
+
tag_versions = PactBroker::Domain::Tag
|
44
|
+
.select_all_qualified
|
45
|
+
.select_append(Sequel[:versions][:pacticipant_id])
|
46
|
+
.select_append(Sequel[:versions][:order])
|
47
|
+
.join(:versions,
|
48
|
+
{ Sequel[:tags][:version_id] => Sequel[:versions][:id] }
|
49
|
+
)
|
50
|
+
|
51
|
+
tag_versions
|
52
|
+
.left_join(tag_versions, { Sequel[:tags][:name] => Sequel[:tags_2][:name], Sequel[:versions][:pacticipant_id] => Sequel[:tags_2][:pacticipant_id] }, { table_alias: :tags_2 }) do | table, joined_table, js |
|
53
|
+
Sequel.qualify(table, :order) > Sequel.qualify(joined_table, :order)
|
54
|
+
end
|
55
|
+
.where(Sequel[:tags_2][:name] => nil)
|
56
|
+
end
|
57
|
+
|
16
58
|
# Does NOT care about whether or not there is a pact publication
|
17
59
|
# for the version
|
18
60
|
def latest_tags_for_pacticipant_ids(pacticipant_ids)
|
@@ -3,11 +3,13 @@ require 'sequel'
|
|
3
3
|
require 'pact_broker/repositories/helpers'
|
4
4
|
require 'pact_broker/tags/tag_with_latest_flag'
|
5
5
|
require 'pact_broker/pacts/content'
|
6
|
+
require 'sequel/extensions/symbol_aref_refinement'
|
6
7
|
|
7
8
|
|
8
9
|
module PactBroker
|
9
10
|
module Domain
|
10
11
|
class Verification < Sequel::Model
|
12
|
+
using Sequel::SymbolAref
|
11
13
|
|
12
14
|
set_primary_key :id
|
13
15
|
associate(:many_to_one, :pact_version, class: "PactBroker::Pacts::PactVersion", key: :pact_version_id, primary_key: :id)
|
@@ -25,6 +27,82 @@ module PactBroker
|
|
25
27
|
dataset_module do
|
26
28
|
include PactBroker::Repositories::Helpers
|
27
29
|
|
30
|
+
def latest_verification_ids_for_all_consumer_version_tags
|
31
|
+
verif_pact_join = { Sequel[:verifications][:pact_version_id] => Sequel[:lpp][:pact_version_id] }
|
32
|
+
tag_join = { Sequel[:lpp][:consumer_version_id] => Sequel[:cvt][:version_id] }
|
33
|
+
verisons_join = { Sequel[:v][:provider_version_id] => Sequel[:pv][:id] }
|
34
|
+
|
35
|
+
db[:verifications]
|
36
|
+
.select_group(
|
37
|
+
Sequel[:pv][:pacticipant_id].as(:provider_id),
|
38
|
+
Sequel[:lpp][:consumer_id],
|
39
|
+
Sequel[:cvt][:name].as(:consumer_version_tag_name)
|
40
|
+
)
|
41
|
+
.select_append{ max(verifications[id]).as(latest_verification_id) }
|
42
|
+
.join(:latest_pact_publication_ids_for_consumer_versions, verif_pact_join, { table_alias: :lpp } )
|
43
|
+
.join(:tags, tag_join, { table_alias: :cvt })
|
44
|
+
.join(:versions, verisons_join, { table_alias: :pv })
|
45
|
+
end
|
46
|
+
|
47
|
+
# Do not use this query. It performs worse than the view.
|
48
|
+
# Keeping for posterity
|
49
|
+
def latest_verifications_for_all_consumer_version_tags
|
50
|
+
verif_pact_join = { Sequel[:v][:pact_version_id] => Sequel[:lpp][:pact_version_id] }
|
51
|
+
tag_join = { Sequel[:lpp][:consumer_version_id] => Sequel[:cvt][:version_id] }
|
52
|
+
verisons_join = { Sequel[:v][:provider_version_id] => Sequel[:pv][:id] }
|
53
|
+
|
54
|
+
base_query = db[Sequel.as(:latest_verification_id_for_pact_version_and_provider_version, :v)]
|
55
|
+
.select(:v[:verification_id], :pv[:pacticipant_id].as(:provider_id), :lpp[:consumer_id], :cvt[:name].as(:consumer_version_tag_name))
|
56
|
+
.join(:latest_pact_publication_ids_for_consumer_versions, verif_pact_join, { table_alias: :lpp } )
|
57
|
+
.join(:tags, tag_join, { table_alias: :cvt })
|
58
|
+
.join(:versions, verisons_join, { table_alias: :pv })
|
59
|
+
|
60
|
+
|
61
|
+
base_join = {
|
62
|
+
:pv[:pacticipant_id] => :v2[:provider_id],
|
63
|
+
:lpp[:consumer_id] => :v2[:consumer_id],
|
64
|
+
:cvt[:name] => :v2[:consumer_version_tag_name]
|
65
|
+
}
|
66
|
+
|
67
|
+
thing = base_query
|
68
|
+
.left_join(base_query, base_join, { table_alias: :v2 }) do | table, joined_table, something |
|
69
|
+
:v2[:verification_id] > :v[:verification_id]
|
70
|
+
end.where(:v2[:verification_id] => nil)
|
71
|
+
|
72
|
+
where(id: thing.from_self.select(:verification_id))
|
73
|
+
end
|
74
|
+
|
75
|
+
def latest_verification_ids_for_consumer_version_tags(consumer_ids, consumer_version_tag_names)
|
76
|
+
pact_join = { :verifications[:pact_version_id] => :lpp[:pact_version_id], :lpp[:consumer_id] => consumer_ids }
|
77
|
+
tag_join = { :lpp[:consumer_version_id] => :cvt[:version_id], :cvt[:name] => consumer_version_tag_names }
|
78
|
+
provider_versions_join = { :verifications[:provider_version_id] => :pv[:id] }
|
79
|
+
|
80
|
+
db[Sequel.as(:latest_verification_id_for_pact_version_and_provider_version, :verifications)]
|
81
|
+
.select_group(
|
82
|
+
:pv[:pacticipant_id].as(:provider_id),
|
83
|
+
:lpp[:consumer_id],
|
84
|
+
:cvt[:name].as(:consumer_version_tag_name)
|
85
|
+
)
|
86
|
+
.select_append{ max(verifications[verification_id]).as(latest_verification_id) }
|
87
|
+
.join(:latest_pact_publication_ids_for_consumer_versions, pact_join, { table_alias: :lpp } )
|
88
|
+
.join(:tags, tag_join, { table_alias: :cvt })
|
89
|
+
.join(:versions, provider_versions_join, { table_alias: :pv })
|
90
|
+
.where(:verifications[:consumer_id] => consumer_ids)
|
91
|
+
end
|
92
|
+
|
93
|
+
# Do not use this query. It performs worse than the view.
|
94
|
+
# Keeping for posterity
|
95
|
+
def latest_verifications_for_consumer_version_tags(consumer_ids, consumer_version_tag_names)
|
96
|
+
latest_ids_for_cv_tags = latest_verification_ids_for_consumer_version_tags(consumer_ids, consumer_version_tag_names)
|
97
|
+
join_cols = {
|
98
|
+
Sequel[:verifications][:id] => Sequel[:t2][:latest_verification_id]
|
99
|
+
}
|
100
|
+
select_all_qualified
|
101
|
+
.select_append(Sequel[:t2][:consumer_version_tag_name])
|
102
|
+
.where(Sequel[:verifications][:consumer_id] => consumer_ids)
|
103
|
+
.join(latest_ids_for_cv_tags, join_cols, { table_alias: :t2 })
|
104
|
+
end
|
105
|
+
|
28
106
|
# Expects to be joined with AllPactPublications or subclass
|
29
107
|
# Beware that when columns with the same name exist in both datasets
|
30
108
|
# you may get the wrong column back in your model.
|
@@ -102,6 +180,15 @@ module PactBroker
|
|
102
180
|
def pact_content_with_test_results
|
103
181
|
@pact_content_with_test_results = PactBroker::Pacts::Content.from_json(pact_version.content).with_test_results(test_results)
|
104
182
|
end
|
183
|
+
|
184
|
+
# So consumer_version_tag_name can be accessed by method name
|
185
|
+
def method_missing(m, *args, &block)
|
186
|
+
if values.key?(m) && args.size == 0
|
187
|
+
values[m]
|
188
|
+
else
|
189
|
+
super
|
190
|
+
end
|
191
|
+
end
|
105
192
|
end
|
106
193
|
|
107
194
|
Verification.plugin :timestamps
|
@@ -54,6 +54,11 @@ module PactBroker
|
|
54
54
|
webhooks: {
|
55
55
|
count: PactBroker::Webhooks::Webhook.count
|
56
56
|
},
|
57
|
+
tags: {
|
58
|
+
count: PactBroker::Domain::Tag.count,
|
59
|
+
distinctCount: PactBroker::Domain::Tag.select(:name).distinct.count,
|
60
|
+
distinctWithPacticipantCount: PactBroker::Domain::Tag.join(:versions, { id: :version_id }).select_group(:name, :pacticipant_id).count
|
61
|
+
},
|
57
62
|
triggeredWebhooks: {
|
58
63
|
count: PactBroker::Webhooks::TriggeredWebhook.count
|
59
64
|
},
|
@@ -62,9 +67,6 @@ module PactBroker
|
|
62
67
|
},
|
63
68
|
matrix: {
|
64
69
|
count: PactBroker::Matrix::Row.count
|
65
|
-
},
|
66
|
-
headMatrix: {
|
67
|
-
count: PactBroker::Matrix::HeadRow.count
|
68
70
|
}
|
69
71
|
}
|
70
72
|
end
|
@@ -54,6 +54,14 @@ module PactBroker
|
|
54
54
|
where(name_like(:consumer_version_number, number))
|
55
55
|
end
|
56
56
|
|
57
|
+
def maybe_consumer_version_number number
|
58
|
+
if number
|
59
|
+
where(name_like(:consumer_version_number, number))
|
60
|
+
else
|
61
|
+
self
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
57
65
|
def revision_number number
|
58
66
|
where(revision_number: number)
|
59
67
|
end
|
@@ -3,6 +3,7 @@ require 'ostruct'
|
|
3
3
|
require 'pact_broker/logging'
|
4
4
|
require 'pact_broker/pacts/generate_sha'
|
5
5
|
require 'pact_broker/pacts/pact_publication'
|
6
|
+
require 'pact_broker/pacts/pact_version'
|
6
7
|
require 'pact_broker/pacts/all_pact_publications'
|
7
8
|
require 'pact_broker/pacts/latest_pact_publications_by_consumer_version'
|
8
9
|
require 'pact_broker/pacts/latest_pact_publications'
|
@@ -295,20 +296,43 @@ module PactBroker
|
|
295
296
|
end
|
296
297
|
|
297
298
|
def find_pact consumer_name, consumer_version, provider_name, pact_version_sha = nil
|
298
|
-
|
299
|
-
|
299
|
+
pact_publication_by_consumer_version = scope_for(LatestPactPublicationsByConsumerVersion)
|
300
|
+
.consumer(consumer_name)
|
301
|
+
.provider(provider_name)
|
302
|
+
.maybe_consumer_version_number(consumer_version)
|
303
|
+
.limit(1)
|
304
|
+
|
305
|
+
latest_pact_publication_by_sha = scope_for(AllPactPublications)
|
306
|
+
.consumer(consumer_name)
|
307
|
+
.provider(provider_name)
|
300
308
|
.pact_version_sha(pact_version_sha)
|
301
|
-
.reverse_order(:consumer_version_order)
|
309
|
+
.reverse_order(:consumer_version_order, :revision_number)
|
302
310
|
.limit(1)
|
311
|
+
|
312
|
+
query = if consumer_version && !pact_version_sha
|
313
|
+
pact_publication_by_consumer_version
|
314
|
+
.eager(:tags)
|
315
|
+
.collect(&:to_domain_with_content).first
|
316
|
+
elsif pact_version_sha && !consumer_version
|
317
|
+
latest_pact_publication_by_sha
|
318
|
+
.eager(:tags)
|
319
|
+
.collect(&:to_domain_with_content).first
|
320
|
+
elsif consumer_version && pact_version_sha
|
321
|
+
pact_publication = pact_publication_by_consumer_version.all.first
|
322
|
+
if pact_publication && pact_publication.pact_version.sha == pact_version_sha
|
323
|
+
pact_publication.tags
|
324
|
+
pact_publication.to_domain_with_content
|
325
|
+
else
|
326
|
+
latest_pact_publication_by_sha
|
327
|
+
.eager(:tags)
|
328
|
+
.collect(&:to_domain_with_content).first
|
329
|
+
end
|
303
330
|
else
|
304
|
-
|
331
|
+
pact_publication_by_consumer_version
|
332
|
+
.eager(:tags)
|
333
|
+
.reverse_order(:consumer_version_order, :revision_number)
|
334
|
+
.collect(&:to_domain_with_content).first
|
305
335
|
end
|
306
|
-
query = query
|
307
|
-
.eager(:tags)
|
308
|
-
.consumer(consumer_name)
|
309
|
-
.provider(provider_name)
|
310
|
-
query = query.consumer_version_number(consumer_version) if consumer_version
|
311
|
-
query.collect(&:to_domain_with_content)[0]
|
312
336
|
end
|
313
337
|
|
314
338
|
def find_all_revisions consumer_name, consumer_version, provider_name
|
@@ -502,7 +526,7 @@ module PactBroker
|
|
502
526
|
end
|
503
527
|
|
504
528
|
def create_pact_version consumer_id, provider_id, sha, json_content
|
505
|
-
PactVersion.new(
|
529
|
+
PactBroker::Pacts::PactVersion.new(
|
506
530
|
consumer_id: consumer_id,
|
507
531
|
provider_id: provider_id,
|
508
532
|
sha: sha,
|
@@ -38,15 +38,21 @@ module PactBroker
|
|
38
38
|
|
39
39
|
raise PactBroker::Error.new("You must specify the version_deletion_limit") unless version_deletion_limit
|
40
40
|
|
41
|
+
prefix = dry_run ? "[DRY RUN] " : ""
|
42
|
+
|
41
43
|
if keep_version_selectors.nil? || keep_version_selectors.empty?
|
42
44
|
raise PactBroker::Error.new("You must specify which versions to keep")
|
43
45
|
else
|
44
|
-
output "Deleting oldest #{version_deletion_limit} versions, keeping versions that match the configured selectors", keep_version_selectors
|
46
|
+
output "#{prefix}Deleting oldest #{version_deletion_limit} versions, keeping versions that match the configured selectors", keep_version_selectors
|
45
47
|
end
|
46
48
|
|
47
49
|
start_time = Time.now
|
48
|
-
results = PactBroker::DB::CleanIncremental.call(
|
49
|
-
|
50
|
+
results = PactBroker::DB::CleanIncremental.call(database_connection,
|
51
|
+
keep: keep_version_selectors,
|
52
|
+
limit: version_deletion_limit,
|
53
|
+
logger: logger,
|
54
|
+
dry_run: dry_run
|
55
|
+
)
|
50
56
|
end_time = Time.now
|
51
57
|
elapsed_seconds = (end_time - start_time).to_i
|
52
58
|
output "Results (#{elapsed_seconds} seconds)", results
|
@@ -2,9 +2,13 @@ module PactBroker
|
|
2
2
|
module DB
|
3
3
|
class DeleteOverwrittenDataTask < ::Rake::TaskLib
|
4
4
|
attr_accessor :database_connection
|
5
|
-
attr_accessor :
|
5
|
+
attr_accessor :max_age
|
6
|
+
attr_accessor :logger
|
7
|
+
attr_accessor :deletion_limit
|
8
|
+
attr_accessor :dry_run
|
6
9
|
|
7
10
|
def initialize &block
|
11
|
+
@max_age = 7
|
8
12
|
rake_task &block
|
9
13
|
end
|
10
14
|
|
@@ -19,15 +23,27 @@ module PactBroker
|
|
19
23
|
instance_eval(&block)
|
20
24
|
options = {}
|
21
25
|
|
22
|
-
|
23
|
-
|
24
|
-
|
26
|
+
prefix = dry_run ? "[DRY RUN] " : ""
|
27
|
+
|
28
|
+
if max_age
|
29
|
+
options[:max_age] = max_age
|
30
|
+
output "#{prefix}Deleting overwritten pact publications and verifications older than #{max_age} days"
|
25
31
|
else
|
26
|
-
|
32
|
+
output "#{prefix}Deleting overwritten pact publications and verifications"
|
27
33
|
end
|
28
34
|
|
29
|
-
|
30
|
-
|
35
|
+
options[:limit] = deletion_limit if deletion_limit
|
36
|
+
options[:dry_run] = dry_run
|
37
|
+
|
38
|
+
start_time = Time.now
|
39
|
+
results = PactBroker::DB::DeleteOverwrittenData.call(database_connection, options)
|
40
|
+
end_time = Time.now
|
41
|
+
elapsed_seconds = (end_time - start_time).to_i
|
42
|
+
output "Results (#{elapsed_seconds} seconds)", results
|
43
|
+
end
|
44
|
+
|
45
|
+
def output string, payload = {}
|
46
|
+
logger ? logger.info(string, payload: payload) : puts("#{string} #{payload.to_json}")
|
31
47
|
end
|
32
48
|
end
|
33
49
|
end
|