Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

refactor: update cron job frequency for SecretReadActivityPrune to daily

Dimitris Staratzis8674938dc8b5
diff --git a/backend/CLAUDE.md b/backend/CLAUDE.md
index 5eb2daf989..9c4e254a0e 100644
--- a/backend/CLAUDE.md
+++ b/backend/CLAUDE.md
@@ -1097,7 +1097,7 @@ and the events cannot say which folders a recursive read returned. Instead it ke
non-blocking lock), by the `SecretReadActivityFlush` cron every minute into an upsert.
- **Partitioned by month, no foreign keys, no index on `lastReadAt`.** The table is range-partitioned on
`readMonth` (the UTC month of `lastReadAt`, part of the primary key), so a reader has one row per month and
- `findLastReads` folds them into the latest. The hourly `SecretReadActivityPrune` cron creates the current and
+ `findLastReads` folds them into the latest. The daily `SecretReadActivityPrune` cron creates the current and
next three months' partitions and drops a month once all of it is older than the 30-day window, since nothing
reads before it. Never prune with `DELETE`: at this table's size that is a full scan plus vacuum. Partition DDL
takes an exclusive lock on the whole table, so it runs under a short `lock_timeout` and retries next hour.
diff --git a/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts b/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts
index e5c4170a1d..91b37228d5 100644
--- a/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts
+++ b/backend/src/ee/services/secret-read-activity/secret-read-activity-service.ts
@@ -410,12 +410,12 @@ export const secretReadActivityServiceFactory = ({
enabled: !appCfg.isSecondaryInstance,
handler: $consumeReadStream
});
- // Hourly although a month's partition is needed once, so that an instance back from a long outage gets
- // partitions for its reads within the hour.
+ // Daily although a month's partition is needed once: partitions exist months ahead, so a missed run costs
+ // nothing, and an instance back from a longer outage gets them within a day while its reads wait in the stream.
cronJob.register({
name: CronJobName.SecretReadActivityPrune,
- pattern: "15 * * * *",
- runHashTtlS: 24 * 60 * 60,
+ pattern: "15 1 * * *",
+ runHashTtlS: 3 * 24 * 60 * 60,
enabled: !appCfg.isSecondaryInstance,
handler: async () => {
const created = await secretReadActivityDAL.createMonthlyPartitions(