Repository navigation
Backlog
Labels
refactoringCode smell / architectural cleanup
Description
Section: TBD — either a new lightweight Humans.Jobs section (/Jobs/Admin) or Shell scheduler + /Debug/Jobs.
Why
Humans is a single-server app with 34 recurring cron jobs (across 23 sections via ISectionJobs) and 6 non-recurring Enqueue/Schedule call sites. Almost every job already owns its own state and retry/backoff logic in its section's tables (Email, Expenses, Google), and standing policy D13 forbids relying on Hangfire storage continuity across restarts.
Keeping Hangfire costs far more than it gives:
Hangfire.Corereferenced in 19 section.csprojfiles almost purely for[DisableConcurrentExecution](including an unused ref inHumans.Gate.csproj).- Unowned
hangfire.*Postgres tables + a second connection pool (docker-entrypoint.sh), outside section DB ownership. - Stale distributed-lock workarounds on a single-server app (
/Debug/Maintenance/ClearHangfireLocks, rawDELETE FROM hangfire.lock, 30-minDistributedLockTimeoutinProgram.cs), whileExpenseReportBackgroundProcessorstill carries its ownSemaphoreSlim. - Expression-tree reflection + stale-schedule sweeper in
RecurringJobExtensions.cs,JobStorage.Currentstatic leakage in tests, 5 NuGet packages (LGPL-3.0 + lockstep Dependabot pinning), and an off-brand/hangfireUI.
Plan
1. Remove the one durable Hangfire queue dependency (Humans.Tickets + Humans.Google)
TicketDeliveryService.SendJoinInvitationAsync(currentlyjobs.Schedule(..., TimeSpan.FromDays(2)), the only multi-day persisted Hangfire timer in the app): replace with a DB-driven recurring sweep over valid non-child tickets whereIssuedAt <= now - 2dand no invitation has been sent yet.TicketDeliveryHandOff:TicketDeliveryService.SendAsyncmakes no external network calls (it only renders and writes toemail_outbox). Dispatch through the in-process work queue and haveTicketCheckoutReconcileJob(already every 5 min) backstop any paid order missing aTicketsEmailedtimeline event.GoogleGroupSyncService15-min scoped retry: switch to an in-process delayed trigger (hourlyteams-system-sync/ dailygoogle-resource-reconciliationalready heal restarts) or route throughgoogle_sync_outbox.
2. In-process scheduler (BackgroundService + Cronos) + fire-and-forget queue
- Consume existing
ISectionJobs/RecurringJobDescriptor(Id, JobType, Cron)directly — optionally adding a lock-group key for shared exclusion (holded-api,tickets-vendor-sync). - Arm the scheduler in
IHostedService.StartAsync(after the migration barrier). - Run each job in a fresh DI scope with the host's
stoppingToken, guarded by a per-job/lock-groupSemaphoreSlim(1, 1)(skip if already running — zero stale DB locks). - Centralize
IHumansMetrics.RecordJobRun(...)and keep a bounded in-memory run history (last run, duration, status, recent errors — same pattern asInMemoryLogSink/ClientStatsTracker). - Expose
TryTrigger(string jobId)for immediate nudges (ProcessEmailOutboxJob,HoldedMirrorCatchUp,TicketSyncJob, and the admin UI). - Add a small
Channel-backedIBackgroundWorkQueuefor parameterized off-request runs (DemoWorldJob,GoogleGroupSync,GoogleDriveSync).
3. Humans-native Jobs UI
- Render a page (Admin + read-only Board, matching
/hangfire's current access) listing every registered job, cron expression, next run, last run/duration/status, recent errors, and a "Run now" POST button. - Replace the Hangfire nav link and
AspNetCore.HealthChecks.Hangfirecheck.
4. Remove Hangfire
- Remove
Hangfire.Coreand[DisableConcurrentExecution]from all 19 section projects. - Remove
Hangfire.Core,Hangfire.AspNetCore,Hangfire.PostgreSql,Hangfire.InMemory, andAspNetCore.HealthChecks.HangfirefromDirectory.Packages.props,.github/dependabot.yml,Program.cs,RecurringJobExtensions.cs,HangfireAuthorizationFilter.cs,ClearHangfireLocks(/Debug/Maintenance), and test stubs. - Update
Views/About/Index.cshtml(remove LGPL-3.0 Hangfire entries, add MITCronos),docs/features/global/background-jobs.md,docker-entrypoint.sh,memory/architecture/cancellation-token-propagation.md, and the public-surface analyzer wording forJobs/(HUM0034). - Follow-up (requires explicit approval per destructive-drop policy): drop the orphaned
hangfireschema in Postgres once the new scheduler is live in production.
Open decisions for implementation
- Home for the scheduler & UI: new
Humans.Jobssection (/Jobs/Admin) vs. Shell +Humans.Debug(/Debug/Jobs). - Run history: purely in-memory (matching
/Debug/Logsand/Debug/HttpErrors) vs. persisted last-run rows.
Metadata
Metadata
Assignees
Labels
refactoringCode smell / architectural cleanup
Activity
Add the Cron section and move notifications-cleanup to it (#2882)