Skip to content

feat(plumber): retention policy worker#717

Merged
skipi merged 15 commits intomainfrom
mk/plumber/retention-policies
Dec 17, 2025
Merged

feat(plumber): retention policy worker#717
skipi merged 15 commits intomainfrom
mk/plumber/retention-policies

Conversation

@skipi
Copy link
Copy Markdown
Collaborator

@skipi skipi commented Nov 18, 2025

📝 Description

This PR implements retention policy support in plumber. When the usage service applies a retention policy, plumber marks pipeline records for expiration with a configurable grace period, allowing corrections before data is deleted.

  • Added expires_at column to pipeline_requests table to track when records should be deleted
  • Created PolicyConsumer to receive retention policy events from usage service via RabbitMQ
  • Created PolicyApplier to mark/unmark pipeline records based on the cutoff date
  • Records older than cutoff are marked with expires_at = now + grace_period (default 15 days)
  • Records newer than the cutoff have expires_at cleared, allowing policy corrections to "save" mistakenly marked records
  • Grace period is configurable via RETENTION_GRACE_PERIOD_DAYS env var (min: 7 days)
  • Record Deleter Worker - Added a GenServer that periodically deletes expired records in batches

✅ Checklist

  • I have tested this change
  • This change requires documentation update

@github-project-automation github-project-automation Bot moved this to Backlog in Roadmap Nov 18, 2025
@skipi skipi force-pushed the mk/plumber/retention-policies branch 4 times, most recently from 7e03b42 to 3b83c30 Compare December 4, 2025 08:19
@skipi skipi marked this pull request as ready for review December 4, 2025 08:19
@skipi skipi force-pushed the mk/plumber/retention-policies branch from dd35670 to 18191c5 Compare December 4, 2025 09:27
@skipi
Copy link
Copy Markdown
Collaborator Author

skipi commented Dec 4, 2025

@codex review

@skipi skipi self-assigned this Dec 4, 2025
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plumber/ppl/lib/ppl/retention/record_deleter_queries.ex Outdated
@skipi
Copy link
Copy Markdown
Collaborator Author

skipi commented Dec 4, 2025

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread plumber/ppl/config/config.exs Outdated
@skipi skipi force-pushed the mk/plumber/retention-policies branch from aaac102 to af9fec5 Compare December 4, 2025 11:23
loadez
loadez previously approved these changes Dec 4, 2025
Comment thread plumber/ppl/lib/ppl/retention/record_deleter_queries.ex Outdated
Comment thread plumber/ppl/lib/ppl/retention/policy_applier.ex Outdated
Comment thread plumber/ppl/lib/ppl/retention/policy_applier.ex Outdated
@skipi skipi force-pushed the mk/plumber/retention-policies branch from af9fec5 to 0d49ae0 Compare December 9, 2025 08:51
@skipi skipi force-pushed the mk/plumber/retention-policies branch 2 times, most recently from 45b6883 to fd8d40d Compare December 11, 2025 09:17
@skipi skipi requested a review from radwo December 11, 2025 09:23
@skipi
Copy link
Copy Markdown
Collaborator Author

skipi commented Dec 11, 2025

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.

@skipi skipi force-pushed the mk/plumber/retention-policies branch from 5e4a69a to 1b87569 Compare December 11, 2025 10:02
Comment thread plumber/ppl/lib/ppl/retention/policy_applier.ex Outdated
@skipi skipi force-pushed the mk/plumber/retention-policies branch from 1e97afc to 8f27f9c Compare December 12, 2025 09:03
@skipi skipi requested a review from loadez December 12, 2025 09:04
Comment thread plumber/ppl/lib/ppl/retention/record_deleter_queries.ex Outdated
Comment thread plumber/ppl/test/retention/record_deleter_queries_test.exs
@skipi skipi force-pushed the mk/plumber/retention-policies branch from 04aaf0c to 21a9590 Compare December 12, 2025 13:43
radwo
radwo previously approved these changes Dec 15, 2025
skipi added 14 commits December 16, 2025 09:35
[db] Add expires_at column to pipeline_requests table
[db] Add idx_pipeline_requests_retention_marking index (org_id, inserted_at WHERE expires_at IS NULL)
[db] Add idx_pipeline_requests_retention_deletion index (expires_at WHERE expires_at IS NOT NULL)
[db] Split migrations into 3 files for safer deployment
[worker] Add PolicyApplier module with batched mark/unmark operations (default 10k batch size)
[worker] Add PolicyConsumer to handle RabbitMQ retention policy events
[config] Add RETENTION_GRACE_PERIOD_DAYS env var (default 15, min 7)
[config] Add RETENTION_APPLIER_BATCH_SIZE env var (default 10000)
[docs] Add commit format guidelines to AGENTS.md
[worker] Move retention worker startup to Application
[config] Add RETENTION_CONSUMER_ENABLED env var (default false)
[worker] Combine SELECT and UPDATE into single query
[config] Move retention worker config to runtime.exs
[config] Add default exchange (usage_internal_api)
[config] Add default routing_key (usage.apply_organization_policy)
[worker] Fix record_deleter to use id instead of ppl_artefact_id
[test] Add integration test for retention deletion
@skipi skipi dismissed stale reviews from DamjanBecirovic and radwo via d3ab56f December 16, 2025 08:42
@skipi skipi force-pushed the mk/plumber/retention-policies branch from 21a9590 to d3ab56f Compare December 16, 2025 08:42
@skipi skipi force-pushed the mk/plumber/retention-policies branch from d3ab56f to 1e6a60a Compare December 16, 2025 08:47
@skipi skipi merged commit 115e83b into main Dec 17, 2025
2 checks passed
@skipi skipi deleted the mk/plumber/retention-policies branch December 17, 2025 08:11
marco2216 pushed a commit to marco2216/semaphore that referenced this pull request Dec 30, 2025
## 📝 Description

This PR implements retention policy support in plumber. When the usage
service applies a retention policy, plumber marks pipeline records for
expiration with a configurable grace period, allowing corrections before
data is deleted.

- Added `expires_at` column to `pipeline_requests` table to track when
records should be deleted
- Created `PolicyConsumer` to receive retention policy events from usage
service via RabbitMQ
- Created `PolicyApplier` to mark/unmark pipeline records based on the
cutoff date
- Records older than cutoff are marked with `expires_at = now +
grace_period` (default 15 days)
- Records newer than the cutoff have `expires_at` cleared, allowing
policy corrections to "save" mistakenly marked records
- Grace period is configurable via `RETENTION_GRACE_PERIOD_DAYS` env var
(min: 7 days)
- Record Deleter Worker - Added a GenServer that periodically deletes
expired records in batches

## ✅ Checklist
- [x] I have tested this change
- [ ] This change requires documentation update
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Backlog

Development

Successfully merging this pull request may close these issues.

4 participants