import "dotenv/config"; import { sdkLogger as logger } from "../../../services/reporting-service/logger.js"; import { getEnvString } from "../../../utils/env.js"; import { createConnectorFromPath } from "../../../utils/connector-factory.js"; import { summarizeError } from "../../../utils/error-utils.js"; import { signalBreeJobComplete } from "../utils/bree-worker-complete.js"; // Configure the logger with the correct log level logger.level = getEnvString("LOG_LEVEL", "info"); const main = async () => { try { logger.info( "==========Starting retry-failed-labor-tickets job cycle==========" ); // Get the connector path from the environment variable const connectorPath = process.env.CONNECTOR_PATH; if (!connectorPath) { throw new Error("Connector path not provided in environment variables"); } // Create a new connector instance for this job const connector = await createConnectorFromPath(connectorPath); await connector.retryFailedLaborTickets(); await connector.retryFailedLaborTicketsCompleted(); logger.info( "==========Completed retry-failed-labor-tickets job cycle==========" ); } catch (error) { logger.error('Worker for job "retry-failed-labor-tickets" had an error', { error: summarizeError(error), }); throw error; // Rethrow so Bree can handle it properly } }; // Cross-platform module detection fix for Bree compatibility // Windows: process.argv[1] uses backslashes, import.meta.url uses forward slashes // Linux/Mac: both use forward slashes, so this normalization is safe const normalizedArgv1 = process.argv[1].replace(/\\/g, '/'); const fileUrl = normalizedArgv1.startsWith('/') ? `file://${normalizedArgv1}` : // Unix: file:// + /path = file:///path `file:///${normalizedArgv1}`; // Windows: file:/// + C:/path = file:///C:/path const isMainModule = import.meta.url === fileUrl; if (isMainModule) { // This is called when Bree runs this file as a worker main() .then(() => { signalBreeJobComplete(); }) .catch(() => { process.exit(1); }); } export default main;