Replace the per-tour import UI with a fire-and-forget background job: - Add `import_batches` DB table tracking status, found/imported/duplicate counts - Add `runKomootBulkImport` server function that pages all Komoot tours, fetches GPX, creates activities, and deduplicates via sync_imports - Add `komoot-bulk-import` pg-boss job registered at server startup - Add POST /api/sync/komoot/import to enqueue the job - Add GET /api/sync/komoot/import-status to return the latest batch - Replace the Komoot import page with a progress UI that polls every 2s while a batch is running and shows found/imported/skipped counts Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
921 B
TypeScript
27 lines
921 B
TypeScript
import type { JobDefinition } from "@trails-cool/jobs";
|
|
import { logger } from "../lib/logger.server.ts";
|
|
import { runKomootBulkImport } from "../lib/komoot-bulk-import.server.ts";
|
|
|
|
type KomootCreds =
|
|
| { mode: "public"; komootUserId: string }
|
|
| { mode: "authenticated"; email: string; encryptedPassword: string; komootUserId: string };
|
|
|
|
interface KomootBulkImportData extends Record<string, unknown> {
|
|
batchId: string;
|
|
userId: string;
|
|
creds: KomootCreds;
|
|
}
|
|
|
|
export const komootBulkImportJob: JobDefinition<KomootBulkImportData> = {
|
|
name: "komoot-bulk-import",
|
|
retryLimit: 1,
|
|
expireInSeconds: 1800,
|
|
async handler(jobs) {
|
|
const batch = Array.isArray(jobs) ? jobs : [jobs];
|
|
for (const job of batch) {
|
|
const { batchId, userId, creds } = job.data;
|
|
logger.info({ batchId, userId }, "komoot bulk import job started");
|
|
await runKomootBulkImport(batchId, userId, creds);
|
|
}
|
|
},
|
|
};
|