47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
|
|
import type { RunnerOptions, GraphileConfig } from 'graphile-worker'
|
|
import { run } from 'graphile-worker'
|
|
import { join, dirname } from 'node:path'
|
|
import { fileURLToPath } from 'url'
|
|
import { configs } from './config.ts'
|
|
|
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
|
|
|
|
async function setupGraphileWorker() {
|
|
try {
|
|
const preset: GraphileConfig.Preset = {
|
|
worker: {
|
|
connectionString: configs.connectionString,
|
|
concurrentJobs: 3,
|
|
fileExtensions: [".js", ".ts"],
|
|
taskDirectory: join(__dirname, 'tasks')
|
|
},
|
|
};
|
|
// console.log('worker preset as follows')
|
|
// console.log(preset)
|
|
const runnerOptions: RunnerOptions = {
|
|
preset
|
|
}
|
|
|
|
const runner = await run(runnerOptions)
|
|
if (!runner) throw new Error('failed to initialize graphile worker');
|
|
await runner.promise
|
|
} catch (e) {
|
|
console.error('error caught during setupGraphileWorker')
|
|
console.error(e)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
async function main() {
|
|
await setupGraphileWorker()
|
|
}
|
|
|
|
main().catch((e) => {
|
|
console.error("error during main() function")
|
|
console.error(e)
|
|
process.exit(3)
|
|
}) |