Commit ee901d4
feat(dashboard-api): supabase auth users sync background runner (#2247)
* feat: supabase auth users sync background runner in dashboard api
* chore: auto-commit generated changes
* feat(db): enhance auth user sync triggers to retain direct operations while enqueuing for processing
* feat(sync): implement user sync queue with enhanced error handling and recovery mechanisms
- Updated the sync runner to use `RunWithRestart` for improved error recovery.
- Introduced a new `UserSyncQueue` model to manage user synchronization tasks.
- Added SQL migration for creating the `user_sync_queue` table with necessary triggers.
- Implemented tests for the processor and supervisor to ensure robust handling of retries and panics.
- Refactored existing queries to target the new `public.user_sync_queue` table.
* feat(sync): add supabase auth user sync configuration and secrets management
- Introduced `supabase_auth_user_sync_enabled` variable to control user synchronization.
- Updated Nomad job configuration to include the new sync setting.
- Added Google Secret Manager resources for managing the sync configuration securely.
- Enhanced the dashboard API to utilize the new sync configuration in processing logic.
- Refactored related components to improve error handling and logging for the sync process.
* chore: remove smoke test
* add: e2e runner test
* chore: change dashboard-api env variable management
* refactor(sync): update user sync logic to utilize new database structure
- Replaced the previous `Store` implementation with a new structure that integrates both authentication and main database queries.
- Updated the `Runner` and `NewRunner` functions to accommodate the new database client structure.
- Removed obsolete SQL queries and migration files related to the `user_sync_queue` table.
- Enhanced the test suite to reflect changes in the runner's initialization and database interactions.
* fix: lint
* test: apply database migrations in end-to-end test setup
- Updated the `TestSupabaseAuthUserSyncRunner_EndToEnd` to apply necessary database migrations before running tests.
- Refactored the `SetupDatabase` function to include a new method `ApplyMigrations` for better migration management.
* feat(sync): enhance user sync processing and acknowledgment
- Introduced a new process outcome `ready_to_ack` to streamline acknowledgment handling.
- Refactored the `process` method to prepare for batch acknowledgment of processed items.
- Added a new `AckBatch` method in the store to handle multiple acknowledgments efficiently.
- Updated the `Runner` to process items in batches and finalize acknowledgments accordingly.
- Removed obsolete SQL query for single item acknowledgment as part of the refactor.
- Enhanced tests to cover new deletion logic and acknowledgment scenarios.
* refactor(gcp): remove auth_db_connection_string resources and update references
- Deleted the `auth_db_connection_string` secret and its version from the GCP configuration.
- Updated references in `main.tf` and `nomad/main.tf` to use the `postgres_connection_string` instead.
- Removed the corresponding variable declaration from `variables.tf` to clean up unused configurations.
* chore(dashboard-api): refactor environment variable management
- Updated the dashboard API module to separate base and extra environment variables.
- Introduced a precondition to prevent conflicts with reserved keys in extra environment variables.
- Modified the HCL job configuration to iterate over environment variables dynamically.
- Adjusted variable declarations to reflect the new structure for extra environment variables.
* refactor: use river for queue worker
* chore: auto-commit generated changes
* chore: auto-commit generated changes
* chore: update pgx dependency to v5.9.1 and golang.org/x/mod to v0.34.0 across multiple packages
* chore: fix lint
* chore: auto-commit generated changes
* improve: retrying for river jobs
* refactor: enhance auth user sync worker and streamline environment variable handling
- Updated the AuthUserSyncWorker to utilize OpenTelemetry metrics for better monitoring.
- Refactored the Makefile to improve environment variable exportation and streamline build/run commands.
- Removed outdated SQL query files related to user sync queue operations to clean up the codebase.
- Adjusted the database migration script to drop the auth_custom schema if it exists, ensuring a cleaner migration process.
* chore: rename config and fix test
* improve: config
* chore: auto-commit generated changes
* fix: correct env var name in template to match Go config
Use AUTH_USER_SYNC_BACKGROUND_WORKER_ENABLED instead of
SUPABASE_AUTH_USER_SYNC_ENABLED to match the actual config
field in packages/dashboard-api/internal/cfg/model.go
Co-authored-by: Ben Fornefeld <ben-fornefeld@users.noreply.github.com>
* fix: update permissions for trigger_user on river_job and sequences in auth_custom schema
- Changed REVOKE statement to specify INSERT permission on river_job.
- Added REVOKE for USAGE and SELECT on all sequences in the auth_custom schema for trigger_user.
* refactor: update environment variable handling and improve auth user sync worker
- Renamed environment variable from AUTH_USER_SYNC_BACKGROUND_WORKER_ENABLED to ENABLE_AUTH_USER_SYNC_BACKGROUND_WORKER for clarity and consistency.
- Streamlined the AuthUserSyncWorker to enhance monitoring and error handling.
- Adjusted the handling of environment variables in the Nomad job configuration to allow for better integration with module defaults.
- Updated test cases to reflect changes in the database client naming convention from AuthDb to AuthDB for consistency across the codebase.
* chore: auto-commit generated changes
* fix: lint
* chore: auto-commit generated changes
* chore: auto-commit generated changes
* refactor(dashboard-api): align auth user sync worker with review feedback
* chore: auto-commit generated changes
* refactor(db): split supabase auth sync source client
* chore(db): address follow-up nits
* fix(dashboard-api): stop river worker gracefully on shutdown
* refactor(dashboard-api): simplify service lifecycle orchestration
* chore: auto-commit generated changes
* refactor(db): drop supabase replica client plumbing
* fix: use write db for supabase db get user read
* chore: fix lint
* fix(dashboard-api): lazy-init supabase worker client
* chore(dashboard-api): reduce supabase worker pool size
* test(dashboard-api): tighten auth user sync coverage
Replace the broad backlog case with smaller tests that cover stale upsert cleanup and same-email trigger behavior. This keeps the worker coverage focused on the branch's critical correctness signals without extra soak-style runtime.
* chore: auto-commit generated changes
* feat(dashboard-api): add supabase db config override
Allow dashboard-api to use a dedicated SUPABASE_DB_CONNECTION_STRING while keeping the existing fallback to POSTGRES_CONNECTION_STRING. Thread the new setting through Terraform so deployments can configure the worker without reusing the auth DB connection string.
* refactor(dashboard-api): narrow infra sync runner changes
Keep dashboard-api specific env wiring explicit, restore NODE_ID and PORT in the Nomad job spec, and remove generic dashboard-api env passthrough. Also trim unrelated lint churn from the branch and scope the remaining test/migration helpers to the auth user sync worker flow.
* chore: auto-commit generated changes
* chore: auto-commit generated changes
* refactor(supabase): drop unused trigger role setup
Remove the copied trigger_user scaffolding from the Supabase River migrations because these SECURITY DEFINER functions never use that role. Keep the test bootstrap aligned with the simplified migration flow.
* refactor(dashboard-api): use shared not-found helper
Replace direct pgx no-rows checks in dashboard-api handlers with dberrors.IsNotFoundError so the package uses the shared database error handling consistently.
* chore: remove env vars artifact
* refactor(dashboard-api): tie river worker to signal context
Start the auth user sync River client with the signal-aware run context so it begins graceful shutdown as soon as SIGINT or SIGTERM arrives, while preserving the explicit coordinated stop path.
---------
Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: Ben Fornefeld <ben-fornefeld@users.noreply.github.com>1 parent 0b946c4 commit ee901d4
56 files changed
Lines changed: 1250 additions & 154 deletions
File tree
- iac
- modules/job-dashboard-api
- jobs
- provider-gcp
- nomad
- packages
- api
- auth
- clickhouse
- client-proxy
- dashboard-api
- internal
- backgroundworker
- cfg
- handlers
- db
- pkg
- supabase
- migrations
- queries
- schema
- sql_queries/users
- testutils
- queries
- users
- docker-reverse-proxy
- envd
- local-dev
- orchestrator
- tests/integration
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
80 | 84 | | |
81 | 85 | | |
82 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
88 | 80 | | |
89 | 81 | | |
90 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
1 | 20 | | |
2 | 21 | | |
3 | 22 | | |
4 | 23 | | |
5 | 24 | | |
6 | | - | |
7 | 25 | | |
8 | 26 | | |
9 | 27 | | |
10 | 28 | | |
11 | 29 | | |
12 | 30 | | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
| 31 | + | |
21 | 32 | | |
22 | 33 | | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | 34 | | |
27 | 35 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
37 | 43 | | |
38 | 44 | | |
39 | 45 | | |
| |||
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
47 | 58 | | |
48 | 59 | | |
49 | 60 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
79 | 81 | | |
80 | 82 | | |
81 | 83 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
275 | 275 | | |
276 | 276 | | |
277 | 277 | | |
278 | | - | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
279 | 281 | | |
280 | 282 | | |
281 | 283 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
130 | 130 | | |
131 | 131 | | |
132 | 132 | | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
140 | | - | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
141 | 143 | | |
142 | 144 | | |
143 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
454 | 454 | | |
455 | 455 | | |
456 | 456 | | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
457 | 468 | | |
458 | 469 | | |
459 | 470 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
233 | 244 | | |
234 | 245 | | |
235 | 246 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| |||
386 | 386 | | |
387 | 387 | | |
388 | 388 | | |
389 | | - | |
| 389 | + | |
390 | 390 | | |
391 | 391 | | |
392 | 392 | | |
| |||
0 commit comments