From c0542900be8f02a9ad618e814d126ad7c5ab5d0a Mon Sep 17 00:00:00 2001 From: andrewlalis Date: Tue, 30 Jun 2026 15:32:44 -0400 Subject: [PATCH] Added initial no-op scheduled task for creating drafts from recurring transactions. --- finnow-api/dub.json | 1 + finnow-api/dub.selections.json | 1 + finnow-api/source/scheduled_jobs.d | 28 ++++++++++++++++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/finnow-api/dub.json b/finnow-api/dub.json index fd42f97..be65806 100644 --- a/finnow-api/dub.json +++ b/finnow-api/dub.json @@ -4,6 +4,7 @@ ], "copyright": "Copyright © 2024, Andrew Lalis", "dependencies": { + "cronexp": ">=0.1.0-beta3 <0.2.0-0", "d2sqlite3": "~>1.0", "handy-http-starter": "~>1.6", "jwt4d": "~>0.0.2", diff --git a/finnow-api/dub.selections.json b/finnow-api/dub.selections.json index c8b98c1..39aac10 100644 --- a/finnow-api/dub.selections.json +++ b/finnow-api/dub.selections.json @@ -2,6 +2,7 @@ "fileVersion": 1, "versions": { "asdf": "0.8.0", + "cronexp": "0.1.0-beta3", "d2sqlite3": "1.0.0", "dxml": "0.4.5", "handy-http-data": "1.3.2", diff --git a/finnow-api/source/scheduled_jobs.d b/finnow-api/source/scheduled_jobs.d index adb5c40..cac7741 100644 --- a/finnow-api/source/scheduled_jobs.d +++ b/finnow-api/source/scheduled_jobs.d @@ -11,6 +11,7 @@ void startScheduledJobs() { ); JobScheduler jobScheduler = new TaskPoolScheduler(); + jobScheduler.addJob(() { // Clear old analytics data from profiles. import profile.data; @@ -38,5 +39,32 @@ void startScheduledJobs() { ); }, analyticsSchedule); + + // Add a scheduled job to regularly check for and create recurring transaction drafts. + jobScheduler.addJob(() { + import profile.data; + import profile.data_impl_sqlite; + import profile.model; + import transaction.dto; + import transaction.data; + import util.pagination; + import std.stdio; + import std.datetime; + import cronexp; + FileSystemProfileRepository.doForAllUserProfiles((Profile profile, ProfileRepository profileRepo) { + writefln!"Recurring transaction check: %s / %s"(profile.username, profile.name); + ProfileDataSource ds = profileRepo.getDataSource(profile); + RecurringTransactionRepository rtRepo = ds.getRecurringTransactionRepository(); + Page!(RecurringTransactionResponse) result = rtRepo.findAll(PageRequest.unpaged()); + foreach (rt; result.items) { + writeln(rt.scheduleExpr); + DateTime now = cast(DateTime) Clock.currTime(); + auto cron = CronExpr(rt.scheduleExpr); + writefln!"scheduleExpr = %s -> %s"(rt.scheduleExpr, cron.getNext(now)); + // TODO: Figure out how to actually create the transactions! + } + }); + }, new FixedIntervalSchedule(minutes(1), Clock.currTime(UTC()))); + jobScheduler.start(); } \ No newline at end of file