Skip to content

Commit 0498f01

Browse files
mefellowsclaude
andcommitted
feat: expose branch clean env vars in Rakefile and docs
Wires in three new environment variables for the stale branch cleanup feature introduced in pact-foundation/pact_broker#912 and #933: - PACT_BROKER_DATABASE_CLEAN_KEEP_BRANCH_SELECTORS - PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT Also documents both vars in README alongside the existing clean settings. Note: PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT requires pact-foundation/pact_broker#938 to be merged and released before it has any effect at runtime. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 5749f3f commit 0498f01

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ If you have exactly one Pact Broker container running at a time, you can configu
144144
* `PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT`: The maximum number of records to delete at a time for each of the categories listed in the [Categories of removable data](https://docs.pact.io/pact_broker/administration/maintenance#categories-of-removable-data). Defaults to `500`.
145145
* `PACT_BROKER_DATABASE_CLEAN_OVERWRITTEN_DATA_MAX_AGE`: The maximum number of days to keep "overwritten" data as described in the [Categories of removable data](https://docs.pact.io/pact_broker/administration/maintenance#categories-of-removable-data)
146146
* `PACT_BROKER_DATABASE_CLEAN_KEEP_VERSION_SELECTORS`: a JSON string containing a list of the "keep" selectors described in [Configuring the keep selectors](https://docs.pact.io/pact_broker/administration/maintenance#configuring-the-keep-selectors) e.g `[{"latest": true, "branch": true}, { "max_age": 90 }, { "deployed" : true }, { "released" : true }]` (remember to escape the quotes if necessary in your configuration files/console).
147+
* `PACT_BROKER_DATABASE_CLEAN_KEEP_BRANCH_SELECTORS`: a JSON string containing a list of selectors that identify branches to keep. Branches not matching any selector (and not the pacticipant's `main_branch`) will be deleted. Each selector supports `max_age` (integer, days — keep branches active within that many days) and/or `branch` (string or array of strings — always keep these named branches). Defaults to `[{"max_age": 90}]` (keep branches active in the last 90 days). Set to `[]` to disable stale branch cleanup entirely. e.g. `[{"max_age": 90}, {"branch": ["main", "develop"]}]`.
148+
* `PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT`: The maximum number of stale branches to delete in a single clean run. Defaults to the value of `PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT`. Set this to a lower value if branch deletion is causing performance issues.
147149
* `PACT_BROKER_DATABASE_CLEAN_DRY_RUN`: defaults to `false`. Set to `true` to see the output of what *would* have been deleted if the task had run. This is helpful when experimenting with or fine tuning the clean feature. As nothing is deleted when in dry-run mode, the same output will be printed in the logs each time the task runs.
148150

149151
### Running the clean task from an external source

pact_broker/Rakefile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,15 @@ PactBroker::DB::CleanTask.new do | task |
3333
task.version_deletion_limit = env('PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT').to_i
3434
end
3535

36+
if env('PACT_BROKER_DATABASE_CLEAN_KEEP_BRANCH_SELECTORS')
37+
require 'json'
38+
task.keep_branch_selectors = JSON.parse(env('PACT_BROKER_DATABASE_CLEAN_KEEP_BRANCH_SELECTORS'))
39+
end
40+
41+
if env('PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT')
42+
task.branch_deletion_limit = env('PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT').to_i
43+
end
44+
3645
if env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN')
3746
task.dry_run = env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN') == 'true'
3847
end

0 commit comments

Comments
 (0)