wip
This commit is contained in:
@@ -105,9 +105,9 @@ file_size_limit = "50MiB"
|
||||
enabled = true
|
||||
# The base URL of your website. Used as an allow-list for redirects and for constructing URLs used
|
||||
# in emails.
|
||||
site_url = "http://127.0.0.1:3000"
|
||||
site_url = "http://localhost:3000"
|
||||
# A list of *exact* URLs that auth providers are permitted to redirect to post authentication.
|
||||
additional_redirect_urls = ["https://127.0.0.1:3000","http://localhost:3000/auth/callback", "http://localhost:3000/update-password"]
|
||||
additional_redirect_urls = ["https://127.0.0.1:3000","http://127.0.0.1:3000","http://localhost:3000","http://localhost:3000/auth/callback", "http://localhost:3000/update-password"]
|
||||
# How long tokens are valid for, in seconds. Defaults to 3600 (1 hour), maximum 604,800 (1 week).
|
||||
jwt_expiry = 3600
|
||||
# If disabled, the refresh token will never expire.
|
||||
@@ -269,6 +269,14 @@ url = ""
|
||||
# If enabled, the nonce check will be skipped. Required for local sign in with Google auth.
|
||||
skip_nonce_check = false
|
||||
|
||||
[auth.external.keycloak]
|
||||
enabled = true
|
||||
client_id = "env(SUPABASE_AUTH_CLIENT_ID)"
|
||||
secret = "env(SUPABASE_AUTH_KEYCLOAK_SECRET)"
|
||||
redirect_uri = "env(SUPABASE_AUTH_KEYCLOAK_CALLBACK_URL)"
|
||||
url = "env(SUPABASE_AUTH_KEYCLOAK_URL)"
|
||||
skip_nonce_check = true
|
||||
|
||||
# Use Firebase Auth as a third-party provider alongside Supabase Auth.
|
||||
[auth.third_party.firebase]
|
||||
enabled = false
|
||||
|
||||
64
supabase/sql/setup-cron-job.sql
Normal file
64
supabase/sql/setup-cron-job.sql
Normal file
@@ -0,0 +1,64 @@
|
||||
-- Enable required extensions for cron jobs and HTTP requests
|
||||
create extension if not exists pg_cron;
|
||||
create extension if not exists pg_net;
|
||||
|
||||
-- Enable the cron extension to be used in all databases
|
||||
-- This needs to be run with superuser privileges or via Supabase Dashboard
|
||||
grant usage on schema cron to postgres;
|
||||
grant all privileges on all tables in schema cron to postgres;
|
||||
|
||||
-- Function to safely schedule the cron job with environment variables
|
||||
-- This approach allows for easier management and avoids hardcoding sensitive values
|
||||
create or replace function schedule_sync_analysis_results_cron(
|
||||
api_url text,
|
||||
api_token text
|
||||
) returns text as $$
|
||||
declare
|
||||
job_exists boolean;
|
||||
begin
|
||||
-- Check if job already exists
|
||||
select exists(
|
||||
select 1 from cron.job
|
||||
where jobname = 'sync-analysis-results-every-15-minutes'
|
||||
) into job_exists;
|
||||
|
||||
-- If job exists, unschedule it first
|
||||
if job_exists then
|
||||
perform cron.unschedule('sync-analysis-results-every-15-minutes');
|
||||
end if;
|
||||
|
||||
-- Schedule the new job
|
||||
perform cron.schedule(
|
||||
'sync-analysis-results-every-15-minutes',
|
||||
'*/15 * * * *', -- Every 15 minutes
|
||||
format(
|
||||
'select net.http_post(url := ''%s/api/job/sync-analysis-results'', headers := jsonb_build_object(''Content-Type'', ''application/json'', ''x-jobs-api-key'', ''%s''), body := jsonb_build_object(''triggered_by'', ''supabase_cron'', ''timestamp'', now())) as request_id;',
|
||||
api_url, api_token
|
||||
)
|
||||
);
|
||||
|
||||
return 'Cron job scheduled successfully';
|
||||
end;
|
||||
$$ language plpgsql;
|
||||
|
||||
-- Example usage (replace with your actual values):
|
||||
-- select schedule_sync_analysis_results_cron(
|
||||
-- 'https://your-domain.com',
|
||||
-- 'your-jobs-api-token-here'
|
||||
-- );
|
||||
|
||||
-- Utility queries for managing the cron job:
|
||||
|
||||
-- 1. Check if the job is scheduled
|
||||
-- select * from cron.job where jobname = 'sync-analysis-results-every-15-minutes';
|
||||
|
||||
-- 2. View job execution history
|
||||
-- select * from cron.job_run_details
|
||||
-- where jobid = (select jobid from cron.job where jobname = 'sync-analysis-results-every-15-minutes')
|
||||
-- order by start_time desc limit 10;
|
||||
|
||||
-- 3. Unschedule the job if needed
|
||||
-- select cron.unschedule('sync-analysis-results-every-15-minutes');
|
||||
|
||||
-- 4. Check all scheduled jobs
|
||||
-- select jobid, schedule, active, jobname from cron.job;
|
||||
122
supabase/sql/supabase-cron-setup.md
Normal file
122
supabase/sql/supabase-cron-setup.md
Normal file
@@ -0,0 +1,122 @@
|
||||
# Supabase Cron Job Setup for sync-analysis-results
|
||||
|
||||
This document explains how to set up a Supabase cron job to automatically call the `sync-analysis-results` API endpoint every 15 minutes.
|
||||
|
||||
## Prerequisites
|
||||
|
||||
1. Supabase project with database access
|
||||
2. Your application deployed and accessible via a public URL
|
||||
3. `JOBS_API_TOKEN` environment variable configured
|
||||
|
||||
## Setup Steps
|
||||
|
||||
### 1. Enable Required Extensions
|
||||
|
||||
First, enable the required PostgreSQL extensions in your Supabase project:
|
||||
|
||||
```sql
|
||||
create extension if not exists pg_cron;
|
||||
create extension if not exists pg_net;
|
||||
```
|
||||
|
||||
You can run this either:
|
||||
- In the Supabase Dashboard → Database → SQL Editor
|
||||
- Or deploy the migration file: `supabase/migrations/setup_sync_analysis_results_cron.sql`
|
||||
|
||||
### 2. Schedule the Cron Job
|
||||
|
||||
Use the helper function to schedule the cron job with your specific configuration:
|
||||
|
||||
```sql
|
||||
select schedule_sync_analysis_results_cron(
|
||||
'https://your-actual-domain.com', -- Replace with your API URL
|
||||
'your-actual-jobs-api-token' -- Replace with your JOBS_API_TOKEN
|
||||
);
|
||||
```
|
||||
|
||||
### 3. Verify the Setup
|
||||
|
||||
Check if the job was scheduled successfully:
|
||||
|
||||
```sql
|
||||
select * from cron.job where jobname = 'sync-analysis-results-every-15-minutes';
|
||||
```
|
||||
|
||||
## Management Commands
|
||||
|
||||
### View Job Execution History
|
||||
|
||||
```sql
|
||||
select * from cron.job_run_details
|
||||
where jobid = (select jobid from cron.job where jobname = 'sync-analysis-results-every-15-minutes')
|
||||
order by start_time desc limit 10;
|
||||
```
|
||||
|
||||
### Check All Scheduled Jobs
|
||||
|
||||
```sql
|
||||
select jobid, schedule, active, jobname from cron.job;
|
||||
```
|
||||
|
||||
### Unschedule the Job
|
||||
|
||||
```sql
|
||||
select cron.unschedule('sync-analysis-results-every-15-minutes');
|
||||
```
|
||||
|
||||
## Configuration Details
|
||||
|
||||
- **Schedule**: `*/15 * * * *` (every 15 minutes)
|
||||
- **HTTP Method**: POST
|
||||
- **Headers**:
|
||||
- `Content-Type: application/json`
|
||||
- `x-jobs-api-key: YOUR_JOBS_API_TOKEN`
|
||||
- **Body**: JSON with metadata about the cron trigger
|
||||
|
||||
## Security Considerations
|
||||
|
||||
1. **API Token**: Store your `JOBS_API_TOKEN` securely and never commit it to version control
|
||||
2. **Network Access**: Ensure your Supabase instance can reach your deployed application
|
||||
3. **Rate Limiting**: The 15-minute interval should be appropriate for your use case
|
||||
|
||||
## Troubleshooting
|
||||
|
||||
### Job Not Running
|
||||
|
||||
1. Check if extensions are enabled:
|
||||
```sql
|
||||
select * from pg_extension where extname in ('pg_cron', 'pg_net');
|
||||
```
|
||||
|
||||
2. Verify job is active:
|
||||
```sql
|
||||
select * from cron.job where jobname = 'sync-analysis-results-every-15-minutes';
|
||||
```
|
||||
|
||||
3. Check for execution errors:
|
||||
```sql
|
||||
select * from cron.job_run_details
|
||||
where jobid = (select jobid from cron.job where jobname = 'sync-analysis-results-every-15-minutes')
|
||||
and status = 'failed'
|
||||
order by start_time desc;
|
||||
```
|
||||
|
||||
### API Authentication Issues
|
||||
|
||||
1. Verify your `JOBS_API_TOKEN` is correct
|
||||
2. Test the API endpoint manually:
|
||||
```bash
|
||||
curl -X POST https://your-domain.com/api/job/sync-analysis-results \
|
||||
-H "Content-Type: application/json" \
|
||||
-H "x-jobs-api-key: YOUR_JOBS_API_TOKEN"
|
||||
```
|
||||
|
||||
## Alternative: Using Supabase Edge Functions
|
||||
|
||||
If you prefer using Supabase Edge Functions instead of pg_cron, you can:
|
||||
|
||||
1. Create an Edge Function that calls your API
|
||||
2. Use Supabase's built-in cron triggers for Edge Functions
|
||||
3. This approach provides better logging and error handling
|
||||
|
||||
Contact your team lead for assistance with Edge Functions setup if needed.
|
||||
Reference in New Issue
Block a user