Skip to content

Commit

Permalink
Code style fixes (#338)
Browse files Browse the repository at this point in the history
* Fix minor spelling in allDelayed comments

* Simplify instanceof Array expressions

* Remove duplicate declaration

* Update imports in examples to short form

Use unified style, and comment block for easier comment removal

* Simplify import of internal modules
  • Loading branch information
glensc committed Apr 4, 2020
1 parent 5b62b33 commit e2fb0d3
Show file tree
Hide file tree
Showing 24 changed files with 57 additions and 34 deletions.
2 changes: 1 addition & 1 deletion __tests__/core/connection.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as Ioredis from "ioredis";
import { Connection } from "../../src/index";
import { Connection } from "../../src";
import specHelper from "../utils/specHelper";

describe("connection", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/core/multiWorker.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { MultiWorker, Queue } from "../../src/index";
import { MultiWorker, Queue } from "../../src";

let queue;
let multiWorker;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/core/queue.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue, Worker } from "../../src/index";
import { Queue, Worker } from "../../src";
import specHelper from "../utils/specHelper";
let queue;

Expand Down
2 changes: 1 addition & 1 deletion __tests__/core/scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue, Scheduler, Worker } from "../../src/index";
import { Queue, Scheduler, Worker } from "../../src";
import specHelper from "../utils/specHelper";

let scheduler;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/core/worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Queue, Worker } from "../../src/index";
import { Queue, Worker } from "../../src";
import specHelper from "../utils/specHelper";

const jobs = {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/custom_plugins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { Queue } from "../../src/index";
import { Queue } from "../../src";
import { CustomPlugin } from "../utils/custom-plugin";

describe("plugins", () => {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/delayedQueueLock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { Plugin, Queue, Worker } from "../../src/index";
import { Plugin, Queue, Worker } from "../../src";

let queue;
const jobDelay = 100;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/jobLock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { Queue, Worker } from "../../src/index";
import { Queue, Worker } from "../../src";

let queue;
const jobDelay = 1000;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/noop.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { Scheduler, Queue, Worker } from "../../src/index";
import { Scheduler, Queue, Worker } from "../../src";

let queue;
let scheduler;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/queueLock.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { Plugin, Queue, Worker } from "../../src/index";
import { Plugin, Queue, Worker } from "../../src";

let queue;

Expand Down
2 changes: 1 addition & 1 deletion __tests__/plugins/retry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import specHelper from "../utils/specHelper";
import { Scheduler, Queue, Worker } from "../../src/index";
import { Scheduler, Queue, Worker } from "../../src";

let queue;
let scheduler;
Expand Down
2 changes: 1 addition & 1 deletion __tests__/utils/custom-plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Simple plugin to prevent all jobs
import { Plugin } from "./../../src/index";
import { Plugin } from "../../src";

export class CustomPlugin extends Plugin {
async beforeEnqueue() {
Expand Down
6 changes: 4 additions & 2 deletions examples/customPluginExample.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { Plugin, Worker, Queue } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { Plugin, Worker, Queue } from "../src";
/* In your projects:
import { Worker, Scheduler, Queue } from "node-resque";
*/

// ////////////////////////
// SET UP THE CONNECTION //
Expand Down
6 changes: 5 additions & 1 deletion examples/docker/producer/producer.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
const { Queue } = require("node-resque");
import { Queue } from "../../../src";
/* In your projects:
import { Queue } from require("node-resque");
*/

let queue;

async function boot() {
Expand Down
3 changes: 3 additions & 0 deletions examples/docker/worker/worker.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import { Worker, Scheduler } from "../../../src";
/* In your projects:
const { Worker, Scheduler } = require("node-resque");
*/

let worker;
let scheduler;
Expand Down
6 changes: 4 additions & 2 deletions examples/errorExample.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { Queue, Worker } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { Queue, Worker } from "../src";
/* In your projects:
import { Queue, Worker } from "node-resque";
*/

// ////////////////////////
// SET UP THE CONNECTION //
Expand Down
6 changes: 4 additions & 2 deletions examples/example.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { Queue, Scheduler, Worker } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { Queue, Scheduler, Worker } from "../src";
/* In your projects:
import { Queue, Scheduler, Worker } from "node-resque";
*/

async function boot() {
// ////////////////////////
Expand Down
6 changes: 4 additions & 2 deletions examples/multiWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { MultiWorker, Queue } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { MultiWorker, Queue } from "../src";
/* In your projects:
import { MultiWorker, Queue } from "node-resque";
*/

const connectionDetails = {
pkg: "ioredis",
Expand Down
6 changes: 4 additions & 2 deletions examples/performInline.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { Worker } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { Worker } from "../src";
/* In your projects:
import { Worker } from "node-resque";
*/

// ////////////////////////
// SET UP THE CONNECTION //
Expand Down
6 changes: 4 additions & 2 deletions examples/retry.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { Queue, Scheduler, Worker } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { Queue, Scheduler, Worker } from "../src";
/* In your projects:
import { Queue, Scheduler, Worker } from "node-resque";
*/

// ////////////////////////
// SET UP THE CONNECTION //
Expand Down
8 changes: 5 additions & 3 deletions examples/scheduledJobs.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
#!/usr/bin/env ts-node

// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
// We'll use https://github.com/tejasmanohar/node-schedule for this example,
// but there are many other excelent node scheduling projects
// but there are many other excellent node scheduling projects
import * as schedule from "node-schedule";
import { Queue, Scheduler, Worker } from "./../src/index";
import { Queue, Scheduler, Worker } from "../src";
/* In your projects:
import { Queue, Scheduler, Worker } from "node-resque";
*/

// ////////////////////////
// SET UP THE CONNECTION //
Expand Down
6 changes: 4 additions & 2 deletions examples/stuckWorker.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#!/usr/bin/env ts-node

import { Queue, Scheduler, Worker } from "./../src/index";
// In your projects: import { Worker, Scheduler, Queue } from "node-resque";
import { Queue, Scheduler, Worker } from "../src";
/* In your projects:
import { Queue, Scheduler, Worker } from "node-resque";
*/

async function boot() {
// ////////////////////////
Expand Down
2 changes: 1 addition & 1 deletion src/core/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ export class Queue extends EventEmitter {
}

/**
* - jobsHash is an object with its keys being timestamps, and the vales are arrays of jobs at each time.
* - jobsHash is an object with its keys being timestamps, and the values are arrays of jobs at each time.
* - note that this operation can be very slow and very ram-heavy
*/
async allDelayed() {
Expand Down
6 changes: 3 additions & 3 deletions src/core/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export declare interface Worker {
once(event: "ping", cb: (time: number) => void): this;
once(
event: "job",
cb: (queue: string, job: Job<any> | Job<any> | JobEmit) => void
cb: (queue: string, job: Job<any> | JobEmit) => void
): this;
once(
event: "reEnqueue",
Expand Down Expand Up @@ -276,7 +276,7 @@ export class Worker extends EventEmitter {
}

let callableArgs = [job.args];
if (job.args === undefined || job.args instanceof Array === true) {
if (job.args === undefined || job.args instanceof Array) {
callableArgs = job.args;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ export class Worker extends EventEmitter {
if (!args) {
args = [];
}
if (args !== undefined && args !== null && args instanceof Array !== true) {
if (!(args instanceof Array)) {
args = [args];
}

Expand Down

0 comments on commit e2fb0d3

Please sign in to comment.