* Configuration class for API. * Controls API-only mode, port settings, and autostart behavior.
| 748 | * Controls API-only mode, port settings, and autostart behavior. |
| 749 | */ |
| 750 | class ApiConfig { |
| 751 | static apiPort: number = 8000; |
| 752 | static autoStart: boolean = true; |
| 753 | static routeSetupFn?: (server: FastifyInstance) => void; |
| 754 | static apiBasePath: string = ""; // Default empty |
| 755 | static routeAliases: Map<Function, string[]> = new Map(); |
| 756 | |
| 757 | // Kubernetes configuration |
| 758 | static nodeRole: NodeRole = 'standalone'; |
| 759 | |
| 760 | /** |
| 761 | * Enables API |
| 762 | * @example |
| 763 | * ApiConfig.enableApi(); |
| 764 | */ |
| 765 | static enableApi(): void { |
| 766 | // @ts-ignore |
| 767 | global.ApiConfig = ApiConfig; |
| 768 | // @ts-ignore |
| 769 | global.startServer = startServer; |
| 770 | // @ts-ignore |
| 771 | global.stopServer = stopServer; |
| 772 | } |
| 773 | |
| 774 | |
| 775 | |
| 776 | /** |
| 777 | * Enables Kubernetes Master-Worker mode. |
| 778 | * |
| 779 | * This method configures the application for distributed task processing: |
| 780 | * - If --master flag is passed: Acts as the master node (task distribution) |
| 781 | * - If --worker flag is passed: Acts as a worker node (task execution) |
| 782 | * - If neither flag is passed: Acts as normal desktop application (default behavior) |
| 783 | * |
| 784 | * @param {string} masterEndpoint - The master node endpoint (e.g., "http://master-srv:3000") |
| 785 | * @param {number | Record<string, number>} taskTimeout - Task timeout in seconds. Ideally set it to 2× your max expected task duration. |
| 786 | * Can be a single number (applies to all scrapers) or an object mapping scraper names/types to timeouts. |
| 787 | * Default: 8 hours (28800 seconds) |
| 788 | * |
| 789 | * @example |
| 790 | * // Simple usage with default timeout |
| 791 | * ApiConfig.enableKubernetes("http://master-srv:3000"); |
| 792 | * |
| 793 | * @example |
| 794 | * // Custom timeout for all scrapers |
| 795 | * ApiConfig.enableKubernetes("http://master-srv:3000", 3600); // 1 hour |
| 796 | * |
| 797 | * @example |
| 798 | * // Different timeouts per scraper |
| 799 | * ApiConfig.enableKubernetes("http://master-srv:3000", { |
| 800 | * "longRunningScraper": 14400, // 4 hours |
| 801 | * "quickScraper": 1800 // 30 minutes |
| 802 | * }); |
| 803 | */ |
| 804 | static async enableKubernetes({ |
| 805 | masterEndpoint, |
| 806 | taskTimeout = DEFAULT_TASK_TIMEOUT |
| 807 | }: { |
nothing calls this directly
no outgoing calls
no test coverage detected