fix: auth scheduler env vars, concurrency and browser stability

This commit is contained in:
Giancarmine Salucci
2025-12-21 02:15:22 +01:00
parent 9357bd483a
commit 342a8eb259
9 changed files with 420 additions and 79 deletions

View File

@@ -0,0 +1,20 @@
# Outcome - Fix Auth Scheduler Env Vars
## Summary
Successfully fixed the environment variable loading issue in the authentication scheduler and updated the frequency configuration to support minutes.
## Changes
- **Refactored Scheduler Logic:**
- Updated `src/lib/server/scheduler.ts` to use `$env/dynamic/private` for reliable environment variable access.
- Changed configuration from `intervalHours` to `intervalMinutes`.
- Updated `startScheduler` to calculate interval in milliseconds based on minutes.
- **Updated Documentation:**
- Updated `src/hooks.server.ts` JSDoc to reflect the new configuration.
- **Updated Configuration:**
- Updated `.env.local` to set `AUTH_SCHEDULER_INTERVAL_MINUTES=5`.
- **Verified Tests:**
- Updated `src/tests/scheduler.spec.ts` to mock `$env/dynamic/private` and verify the new logic.
- All tests passed.
## Feature Branch
`feature/FixAuthSchedulerEnvVars`

View File

@@ -0,0 +1,21 @@
# Outcome - Fix Scheduler Concurrency and Browser Stability
## Summary
Successfully implemented fixes for the scheduler concurrency issues and browser instability.
## Changes
- **Scheduler Configuration Validation:**
- Updated `src/lib/server/scheduler.ts` to validate `intervalMinutes`.
- Added a check for `NaN` and a minimum interval of 15 minutes.
- Defaults to 720 minutes if the configuration is invalid.
- **Resource Cleanup:**
- Refactored `renewInstagramAuth` in `src/lib/server/scheduler.ts` to use a `finally` block for closing `page` and `context`.
- Ensures resources are released even if an error occurs during renewal.
- **Robust Browser Management:**
- Updated `src/lib/server/browser.ts` to check `browser.isConnected()`.
- Automatically re-initializes the browser if it is disconnected or crashed.
## Verification
- The scheduler will now default to a safe interval if misconfigured, preventing console spam.
- Browser crashes will be automatically recovered from on the next scheduler run.
- Resource leaks from failed renewal attempts are prevented.