Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
davbeck committed Apr 25, 2020
1 parent 3a754f9 commit de10068
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 16 deletions.
4 changes: 1 addition & 3 deletions __tests__/runner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(`
Expand Down
5 changes: 0 additions & 5 deletions src/config.ts

This file was deleted.

9 changes: 7 additions & 2 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { defaults } from "./config";
import { RunnerOptions } from "./runner";
import { Client } from "pg";

Expand All @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions src/runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -49,18 +48,15 @@ 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,
connectionString,
checkInterval,
leadTime,
maxAge,
workerSchema = defaults.workerSchema,
workerSchema,
...workerOptions
} = options;
this.options = options;
Expand Down

0 comments on commit de10068

Please sign in to comment.