Files
insta-recipe/docs/plans/FixAuthSchedulerEnvVars.md
Giancarmine Salucci 9357bd483a fix
2025-12-21 02:03:05 +01:00

2.5 KiB

Execution Plan - Fix Auth Scheduler Env Vars

The goal of this plan is to fix the issue where the authentication scheduler fails to read environment variables in the SvelteKit application and to increase the scheduler frequency to every 5 minutes.

User Stories

Story 1: Fix Environment Variable Access and Update Frequency Logic

As a developer I want the scheduler to use SvelteKit's idiomatic environment variable handling and support minute-level intervals So that the configuration is correctly loaded and I can set a more frequent schedule.

Acceptance Criteria:

  • src/lib/server/scheduler.ts imports env from $env/dynamic/private.
  • getConfig() uses env.AUTH_SCHEDULER_ENABLED and env.AUTH_SCHEDULER_INTERVAL_MINUTES.
  • SchedulerConfig interface uses intervalMinutes instead of intervalHours.
  • startScheduler() calculates the interval in milliseconds based on minutes.
  • src/hooks.server.ts comments are updated to reflect the new environment variable names.

Technical Notes:

  • SvelteKit does not automatically populate process.env with .env file values in all contexts. Using $env/dynamic/private ensures access to runtime environment variables.
  • Default intervalMinutes should be set to a reasonable value (e.g., 720 for 12 hours) if not provided, but the user specifically requested 5 minutes configuration.

Story 2: Update Configuration

As a user I want my local environment configuration to reflect the new frequency settings So that the scheduler runs every 5 minutes as desired.

Acceptance Criteria:

  • .env.local is updated to include AUTH_SCHEDULER_INTERVAL_MINUTES=5.
  • .env.local no longer contains AUTH_SCHEDULER_INTERVAL_HOURS.

Implementation Steps

Step 1: Refactor Scheduler Logic

  • File: src/lib/server/scheduler.ts
  • Action:
    • Import env from $env/dynamic/private.
    • Update getConfig function to read from env.
    • Rename intervalHours to intervalMinutes in SchedulerConfig and getConfig.
    • Update startScheduler to use intervalMinutes * 60 * 1000.
    • Update log messages to display "min" instead of "h".

Step 2: Update Hooks Documentation

  • File: src/hooks.server.ts
  • Action: Update the JSDoc comment for init to document AUTH_SCHEDULER_INTERVAL_MINUTES.

Step 3: Update Local Configuration

  • File: .env.local
  • Action:
    • Replace AUTH_SCHEDULER_INTERVAL_HOURS=1 (or whatever value) with AUTH_SCHEDULER_INTERVAL_MINUTES=5.