link-stack/apps/bridge-worker/index.ts

38 lines
1.1 KiB
TypeScript
Raw Normal View History

2024-05-14 15:31:44 +02:00
import { run } from "graphile-worker";
import { createLogger } from "@link-stack/logger";
2024-05-14 15:31:44 +02:00
import * as path from "path";
import { fileURLToPath } from "url";
const logger = createLogger('bridge-worker');
2024-05-14 15:31:44 +02:00
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const startWorker = async () => {
logger.info("Starting worker...");
2024-05-14 15:31:44 +02:00
await run({
connectionString: process.env.DATABASE_URL,
noHandleSignals: false,
concurrency: process.env.BRIDGE_WORKER_CONCURRENCY
? parseInt(process.env.BRIDGE_WORKER_CONCURRENCY, 10)
: 10,
maxPoolSize: process.env.BRIDGE_WORKER_POOL_SIZE
? parseInt(process.env.BRIDGE_WORKER_POOL_SIZE, 10)
: 10,
pollInterval: process.env.BRIDGE_WORKER_POLL_INTERVAL
? parseInt(process.env.BRIDGE_WORKER_POLL_INTERVAL, 10)
: 1000,
2024-05-14 15:31:44 +02:00
taskDirectory: `${__dirname}/tasks`,
2024-06-28 07:49:39 +02:00
crontabFile: `${__dirname}/crontab`,
2024-05-14 15:31:44 +02:00
});
};
const main = async () => {
await startWorker();
};
main().catch((err) => {
logger.error({ error: err }, 'Worker failed to start');
2024-05-14 15:31:44 +02:00
process.exit(1);
});