Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 11 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -162,20 +162,22 @@ See `/tests/README.md` for detailed testing documentation.

## Scheduled sync

The cron endpoints (`/api/cron/*`) upload pending QSOs to LoTW and download
confirmations on a schedule. They require a `CRON_SECRET` environment variable
and reject every request that does not carry it — if the secret is unset the
endpoints fail closed with a 500.
The `/api/cron/sync` endpoint runs the full sync cycle — QRZ upload sweep,
LoTW upload, QRZ confirmation download, LoTW confirmation download — for every
eligible station. It requires a `CRON_SECRET` environment variable and rejects
every request that does not carry it — if the secret is unset the endpoint
fails closed with a 500. All legs are incremental and idempotent, so any
cadence is safe.

- **Vercel**: set `CRON_SECRET` in the project's environment variables. Vercel
automatically attaches `Authorization: Bearer $CRON_SECRET` to the cron
invocations defined in `vercel.json`; no other setup is needed.
- **Self-hosted**: set `CRON_SECRET` in your environment and call the
endpoints from your scheduler, e.g. a crontab entry:
invocation defined in `vercel.json` (hourly by default); no other setup is
needed.
- **Self-hosted**: set `CRON_SECRET` in your environment and call the endpoint
from your scheduler, e.g. a crontab entry:

```cron
0 * * * * curl -fsS -H "Authorization: Bearer $CRON_SECRET" https://your-host/api/cron/lotw-upload
30 * * * * curl -fsS -H "Authorization: Bearer $CRON_SECRET" https://your-host/api/cron/lotw-download
0 * * * * curl -fsS -H "Authorization: Bearer $CRON_SECRET" https://your-host/api/cron/sync
```

## Cloudlog API Compatibility
Expand Down
25 changes: 25 additions & 0 deletions drizzle/migrations/0005_add_sync_logs.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
CREATE TABLE "sync_logs" (
"id" serial PRIMARY KEY NOT NULL,
"user_id" integer NOT NULL,
"station_id" integer,
"service" varchar(10) NOT NULL,
"direction" varchar(10) NOT NULL,
"trigger" varchar(10) NOT NULL,
"status" varchar(12) NOT NULL,
"started_at" timestamp DEFAULT CURRENT_TIMESTAMP NOT NULL,
"completed_at" timestamp,
"qso_count" integer DEFAULT 0,
"success_count" integer DEFAULT 0,
"matched_count" integer DEFAULT 0,
"error_message" text,
"details" jsonb,
CONSTRAINT "sync_logs_service_check" CHECK ((service)::text = ANY ((ARRAY['qrz'::character varying, 'lotw'::character varying, 'eqsl'::character varying])::text[])),
CONSTRAINT "sync_logs_direction_check" CHECK ((direction)::text = ANY ((ARRAY['upload'::character varying, 'download'::character varying])::text[])),
CONSTRAINT "sync_logs_trigger_check" CHECK ((trigger)::text = ANY ((ARRAY['manual'::character varying, 'auto'::character varying, 'cron'::character varying])::text[])),
CONSTRAINT "sync_logs_status_check" CHECK ((status)::text = ANY ((ARRAY['completed'::character varying, 'failed'::character varying])::text[]))
);
--> statement-breakpoint
ALTER TABLE "sync_logs" ADD CONSTRAINT "sync_logs_user_id_fkey" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
ALTER TABLE "sync_logs" ADD CONSTRAINT "sync_logs_station_id_fkey" FOREIGN KEY ("station_id") REFERENCES "public"."stations"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
CREATE INDEX "idx_sync_logs_user_started" ON "sync_logs" USING btree ("user_id" int4_ops,"started_at" timestamp_ops);--> statement-breakpoint
CREATE INDEX "idx_sync_logs_station_id" ON "sync_logs" USING btree ("station_id" int4_ops);
Loading
Loading