Skip to content

feat: recurring expenses API and scheduler - #56

Merged
ame180 merged 7 commits into
mainfrom
feat/recurring-expenses-api
Nov 27, 2026
Merged

ame180 merged 7 commits into
mainfrom
feat/recurring-expenses-api

Conversation

@ame180

@ame180 ame180 commented Nov 26, 2026

Copy link
Copy Markdown
Owner
  • Let expenses repeat weekly, every 2 weeks, monthly or yearly. POST/PUT /api/expenses take repeat: {unit: week|month|year, every} or null (only those four frequencies are accepted for now). A new recurring_series row holds the schedule (anchor date, next run, active); the expense gets a nullable series_id. The series' latest expense, by creation order, is what the next one copies. ExpenseResponse adds repeat {unit, every, nextOn, active} and series {latestId, isLatest}; activity items add recurring.
  • Schedule rules: monthly and yearly keep the anchor day, clamping to the month end and returning (31 Jan, 28 Feb, 31 Mar). No backfill: setting a repeat starts from the first schedule date after both the expense's date and today. The anchor stays while the latest's date is one of its schedule dates and the frequency is unchanged; otherwise it moves to the latest's date. Editing the latest changes the future, setting it to no repeat stops the series, and turning it back on restarts the same series. An older member can't set a repeat (422) but can be edited on its own. Deleting the latest stops the series and leaves the previous one as the latest; deleting the only member removes the series.
  • Create due expenses with app:recurring:run, also run hourly through symfony/scheduler. Each run creates every occurrence that's due, including ones missed while nothing ran, each on its own date, copying payee, title, amount, currency, category, split and description (not comments). Each series runs in its own transaction with a row lock, so overlapping runs create nothing twice; a series that fails is logged and retried on the next run.
  • Add a scheduler service on the php image to deploy/compose.yaml and the dev compose.yaml. It skips the migrating entrypoint, waits for php to be healthy, runs the job once on start, then consumes the schedule. The dev php service gets the same healthcheck as the deploy. The default bus pings the DB connection before handling, since the worker idles between ticks. DEPLOYMENT.md covers the service, a host-cron alternative and rolling back to v0.1.0.

Proved with unit tests for the schedule, integration tests for the runner (catch-up, idempotency, stopped and failing series) and API tests, plus the dev stack: a monthly expense dated 10 Aug came back with next 10 Dec, and after rewinding its next run to 10 Sep the scheduler container created the 10 Sep, 10 Oct and 10 Nov copies. The prod image's scheduler entrypoint ran against the dev DB without errors.

@ame180
ame180 merged commit d97cc7c into main Nov 27, 2026
4 checks passed
@ame180
ame180 deleted the feat/recurring-expenses-api branch November 27, 2026 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant