import { run } from "graphile-worker";
import * as path from "path";
import { fileURLToPath } from "url";

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const startWorker = async () => {
  console.log("Starting worker...");
  console.log(process.env);
  await run({
    connectionString: process.env.DATABASE_URL,
    concurrency: 10,
    noHandleSignals: false,
    pollInterval: 1000,
    taskDirectory: `${__dirname}/tasks`,
    crontabFile: `${__dirname}/crontab`,
  });
};

const main = async () => {
  await startWorker();
};

main().catch((err) => {
  console.error(err);
  process.exit(1);
});
