From de10068fe54410463fc4b4efc3a81515549fe068 Mon Sep 17 00:00:00 2001 From: David Beck Date: Sat, 25 Apr 2020 11:41:29 -0700 Subject: [PATCH] Code cleanup --- __tests__/runner.test.ts | 4 +--- src/config.ts | 5 ----- src/lib.ts | 9 +++++++-- src/runner.ts | 8 ++------ 4 files changed, 10 insertions(+), 16 deletions(-) delete mode 100644 src/config.ts diff --git a/__tests__/runner.test.ts b/__tests__/runner.test.ts index 06ca49e..ca0bcbd 100644 --- a/__tests__/runner.test.ts +++ b/__tests__/runner.test.ts @@ -17,9 +17,7 @@ describe("runner", () => { it("queues upcoming jobs", () => withPgPool(async pgPool => { - const { escapedWorkerSchema, escapedSchedulerSchema } = processOptions( - {} - ); + const { escapedWorkerSchema, escapedSchedulerSchema } = processOptions(); await reset({}, pgPool); await pgPool.query(` diff --git a/src/config.ts b/src/config.ts deleted file mode 100644 index 6d7a20a..0000000 --- a/src/config.ts +++ /dev/null @@ -1,5 +0,0 @@ -export const defaults = { - workerSchema: process.env.GRAPHILE_WORKER_SCHEMA ?? "graphile_worker", - schedulerSchema: - process.env.GRAPHILE_SCHEDULER_SCHEMA ?? "graphile_scheduler", -}; diff --git a/src/lib.ts b/src/lib.ts index 7fb59da..decb840 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,4 +1,3 @@ -import { defaults } from "./config"; import { RunnerOptions } from "./runner"; import { Client } from "pg"; @@ -7,7 +6,13 @@ export interface CompiledOptions extends RunnerOptions { escapedWorkerSchema: string; } -export function processOptions(options: RunnerOptions) { +const defaults = { + workerSchema: process.env.GRAPHILE_WORKER_SCHEMA ?? "graphile_worker", + schedulerSchema: + process.env.GRAPHILE_SCHEDULER_SCHEMA ?? "graphile_scheduler", +}; + +export function processOptions(options: RunnerOptions = {}) { return { ...defaults, ...options, diff --git a/src/runner.ts b/src/runner.ts index c655915..f6f14e0 100644 --- a/src/runner.ts +++ b/src/runner.ts @@ -2,7 +2,6 @@ import * as assert from "assert"; import * as moment from "moment"; import { Pool } from "pg"; import { migrate } from "./migrate"; -import { defaults } from "./config"; import { Task, RunnerOptions as WorkerRunnerOptions, @@ -49,10 +48,7 @@ export class Runner { interval: NodeJS.Timeout | null; workerRunner: WorkerRunner | null; - constructor(options: RunnerOptions = defaults) { - options.schedulerSchema = - options.schedulerSchema ?? defaults.schedulerSchema; - options.workerSchema = options.workerSchema ?? defaults.workerSchema; + constructor(options: RunnerOptions = {}) { const { schedules, pgPool, @@ -60,7 +56,7 @@ export class Runner { checkInterval, leadTime, maxAge, - workerSchema = defaults.workerSchema, + workerSchema, ...workerOptions } = options; this.options = options;