Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ If you have exactly one Pact Broker container running at a time, you can configu
* `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`.
* `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)
* `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).
* `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"]}]`.
* `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.
* `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.

### Running the clean task from an external source
Expand Down
9 changes: 9 additions & 0 deletions pact_broker/Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ PactBroker::DB::CleanTask.new do | task |
task.version_deletion_limit = env('PACT_BROKER_DATABASE_CLEAN_DELETION_LIMIT').to_i
end

if env('PACT_BROKER_DATABASE_CLEAN_KEEP_BRANCH_SELECTORS')
require 'json'
task.keep_branch_selectors = JSON.parse(env('PACT_BROKER_DATABASE_CLEAN_KEEP_BRANCH_SELECTORS'))
end

if env('PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT')
task.branch_deletion_limit = env('PACT_BROKER_DATABASE_CLEAN_BRANCH_DELETION_LIMIT').to_i
end

if env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN')
task.dry_run = env('PACT_BROKER_DATABASE_CLEAN_DRY_RUN') == 'true'
end
Expand Down