node-resque
Advanced tools
Comparing version 7.0.4 to 7.0.5
"use strict"; | ||
/// <reference path="./../../node_modules/@types/ioredis/index.d.ts" /> | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Connection = void 0; | ||
const events_1 = require("events"); | ||
@@ -5,0 +6,0 @@ const IORedis = require("ioredis"); |
/// <reference types="node" /> | ||
import { EventEmitter } from "events"; | ||
import { Worker } from "./worker"; | ||
import { Connection } from "./connection"; | ||
import { MultiWorkerOptions } from "../types/options"; | ||
@@ -19,3 +18,2 @@ import { Jobs } from "../types/jobs"; | ||
stopInProcess: boolean; | ||
connection: Connection; | ||
checkTimer: NodeJS.Timeout; | ||
@@ -40,3 +38,3 @@ on(event: "start" | "end", cb: (workerId: number) => void): this; | ||
private cleanupWorker; | ||
private checkWraper; | ||
private checkWrapper; | ||
start(): void; | ||
@@ -43,0 +41,0 @@ stop(): Promise<void>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.MultiWorker = void 0; | ||
const events_1 = require("events"); | ||
@@ -103,6 +104,3 @@ const os = require("os"); | ||
}); | ||
this.working = false; | ||
if (workingCount > 0) { | ||
this.working = true; | ||
} | ||
this.working = workingCount > 0; | ||
if (this.running === false && this.workers.length > 0) { | ||
@@ -187,3 +185,3 @@ verb = "--"; | ||
} | ||
async checkWraper() { | ||
async checkWrapper() { | ||
clearTimeout(this.checkTimer); | ||
@@ -193,3 +191,3 @@ const { verb, eventLoopDelay } = await this.checkWorkers(); | ||
this.checkTimer = setTimeout(() => { | ||
this.checkWraper(); | ||
this.checkWrapper(); | ||
}, this.options.checkTimeout); | ||
@@ -199,3 +197,3 @@ } | ||
this.running = true; | ||
this.checkWraper(); | ||
this.checkWrapper(); | ||
} | ||
@@ -202,0 +200,0 @@ async stop() { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Plugin = void 0; | ||
class Plugin { | ||
@@ -4,0 +5,0 @@ constructor(worker, func, queue, job, args, options) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.RunPlugin = exports.RunPlugins = void 0; | ||
async function RunPlugins(self, type, func, queue, job, args, pluginCounter) { | ||
@@ -4,0 +5,0 @@ if (!pluginCounter) { |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Queue = void 0; | ||
const events_1 = require("events"); | ||
@@ -4,0 +5,0 @@ const os = require("os"); |
@@ -5,2 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Scheduler = void 0; | ||
const events_1 = require("events"); | ||
@@ -7,0 +8,0 @@ const os = require("os"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Worker = void 0; | ||
const events_1 = require("events"); | ||
@@ -4,0 +5,0 @@ const os = require("os"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var connection_1 = require("./core/connection"); | ||
exports.Connection = connection_1.Connection; | ||
Object.defineProperty(exports, "Connection", { enumerable: true, get: function () { return connection_1.Connection; } }); | ||
var queue_1 = require("./core/queue"); | ||
exports.Queue = queue_1.Queue; | ||
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_1.Queue; } }); | ||
var scheduler_1 = require("./core/scheduler"); | ||
exports.Scheduler = scheduler_1.Scheduler; | ||
Object.defineProperty(exports, "Scheduler", { enumerable: true, get: function () { return scheduler_1.Scheduler; } }); | ||
var worker_1 = require("./core/worker"); | ||
exports.Worker = worker_1.Worker; | ||
Object.defineProperty(exports, "Worker", { enumerable: true, get: function () { return worker_1.Worker; } }); | ||
var multiWorker_1 = require("./core/multiWorker"); | ||
exports.MultiWorker = multiWorker_1.MultiWorker; | ||
Object.defineProperty(exports, "MultiWorker", { enumerable: true, get: function () { return multiWorker_1.MultiWorker; } }); | ||
var plugin_1 = require("./core/plugin"); | ||
exports.Plugin = plugin_1.Plugin; | ||
Object.defineProperty(exports, "Plugin", { enumerable: true, get: function () { return plugin_1.Plugin; } }); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.JobLock = void 0; | ||
// If a job with the same name, queue, and args is already running, put this job back in the queue and try later | ||
@@ -4,0 +5,0 @@ const index_1 = require("./../index"); |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Noop = void 0; | ||
const index_1 = require("./../index"); | ||
@@ -4,0 +5,0 @@ class Noop extends index_1.Plugin { |
"use strict"; | ||
// If a job with the same name, queue, and args is already in the queue, do not enqueue it again | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.QueueLock = void 0; | ||
const index_1 = require("./../index"); | ||
@@ -5,0 +6,0 @@ class QueueLock extends index_1.Plugin { |
@@ -5,2 +5,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Retry = void 0; | ||
const os = require("os"); | ||
@@ -35,5 +36,5 @@ const index_1 = require("./../index"); | ||
} | ||
const remaning = await this.attemptUp(); | ||
const remaining = await this.attemptUp(); | ||
await this.saveLastError(); | ||
if (remaning <= 0) { | ||
if (remaining <= 0) { | ||
await this.cleanup(); | ||
@@ -44,3 +45,3 @@ throw this.worker.error; | ||
if (Array.isArray(this.options.backoffStrategy)) { | ||
let index = this.options.retryLimit - remaning - 1; | ||
let index = this.options.retryLimit - remaining - 1; | ||
if (index > this.options.backoffStrategy.length - 1) { | ||
@@ -55,3 +56,4 @@ index = this.options.backoffStrategy.length - 1; | ||
delay: nextTryDelay, | ||
remaningAttempts: remaning, | ||
remaningAttempts: remaining, | ||
remainingAttempts: remaining, | ||
err: this.worker.error, | ||
@@ -105,4 +107,3 @@ }); | ||
await this.redis().expire(key, this.maxDelay()); | ||
const remaning = this.options.retryLimit - retryCount - 1; | ||
return remaning; | ||
return this.options.retryLimit - retryCount - 1; | ||
} | ||
@@ -109,0 +110,0 @@ async saveLastError() { |
"use strict"; | ||
// inspired by https://github.com/tj/node-blocked | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.EventLoopDelay = void 0; | ||
function EventLoopDelay(limit, interval, fn) { | ||
@@ -5,0 +6,0 @@ let start = process.hrtime(); |
@@ -19,6 +19,6 @@ #!/usr/bin/env ts-node | ||
// OR | ||
// Or, to share a single connection connection | ||
// var ioredis = require('ioredis'); | ||
// connectionDetails = { redis: new ioredis() }; | ||
// const connectionDetails = { redis: new ioredis() }; | ||
@@ -139,3 +139,3 @@ async function boot() { | ||
console.log( | ||
`worker[${workerId}] error #{queue} ${JSON.stringify(job)} >> ${error}` | ||
`worker[${workerId}] error ${queue} ${JSON.stringify(job)} >> ${error}` | ||
); | ||
@@ -142,0 +142,0 @@ }); |
@@ -6,3 +6,3 @@ { | ||
"license": "Apache-2.0", | ||
"version": "7.0.4", | ||
"version": "7.0.5", | ||
"homepage": "http://github.com/actionhero/node-resque", | ||
@@ -34,4 +34,4 @@ "repository": { | ||
"@types/ioredis": "^4.14.9", | ||
"@types/jest": "^25.2.1", | ||
"@types/node": "^13.11.0", | ||
"@types/jest": "^26.0.0", | ||
"@types/node": "^14.0.1", | ||
"jest": "^25.2.7", | ||
@@ -56,4 +56,4 @@ "node-schedule": "^1.3.2", | ||
"pretest": "npm run lint", | ||
"lint": "prettier --check src __tests__ examples", | ||
"pretty": "prettier --write src __tests__ examples", | ||
"lint": "prettier --check src __tests__ examples \"*.md\"", | ||
"pretty": "prettier --write src __tests__ examples \"**/*.md\"", | ||
"test": "jest", | ||
@@ -60,0 +60,0 @@ "build": "tsc --declaration", |
@@ -17,3 +17,3 @@ # node-resque: The best background jobs in node. | ||
- ‼️ Version 6+ of Node Resque uses Tyepscript. We will still include javascrtipt transpiled code in NPM releases, but they will be generated from the Typescript source. Functinality between node-resque v5 and v6 should be the same. | ||
- ‼️ Version 6+ of Node Resque uses TypeScript. We will still include JavaScript transpiled code in NPM releases, but they will be generated from the TypeScript source. Functinality between node-resque v5 and v6 should be the same. | ||
- ‼️ Version 5+ of Node Resque uses async/await. There is no upgrade path from previous versions. Node v8.0.0+ is required. | ||
@@ -38,3 +38,3 @@ | ||
port: 6379, | ||
database: 0 | ||
database: 0, | ||
// namespace: 'resque', | ||
@@ -55,6 +55,6 @@ // looping: true, | ||
pluginOptions: { | ||
JobLock: {} | ||
JobLock: {}, | ||
}, | ||
perform: async (a, b) => { | ||
await new Promise(resolve => { | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 1000); | ||
@@ -67,3 +67,3 @@ }); | ||
return answer; | ||
} | ||
}, | ||
}, | ||
@@ -77,4 +77,4 @@ subtract: { | ||
return answer; | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
@@ -85,3 +85,3 @@ | ||
if (jobsToComplete === 0) { | ||
await new Promise(resolve => { | ||
await new Promise((resolve) => { | ||
setTimeout(resolve, 500); | ||
@@ -127,6 +127,6 @@ }); | ||
}); | ||
worker.on("poll", queue => { | ||
worker.on("poll", (queue) => { | ||
console.log(`worker polling ${queue}`); | ||
}); | ||
worker.on("ping", time => { | ||
worker.on("ping", (time) => { | ||
console.log(`worker check in @ ${time}`); | ||
@@ -171,3 +171,3 @@ }); | ||
}); | ||
scheduler.on("error", error => { | ||
scheduler.on("error", (error) => { | ||
console.log(`scheduler error >> ${error}`); | ||
@@ -180,3 +180,3 @@ }); | ||
}); | ||
scheduler.on("workingTimestamp", timestamp => { | ||
scheduler.on("workingTimestamp", (timestamp) => { | ||
console.log(`scheduler working timestamp ${timestamp}`); | ||
@@ -193,3 +193,3 @@ }); | ||
const queue = new Queue({ connection: connectionDetails }, jobs); | ||
queue.on("error", function(error) { | ||
queue.on("error", function (error) { | ||
console.log(error); | ||
@@ -224,3 +224,3 @@ }); | ||
queues: "*", | ||
name: os.hostname() + ":" + process.pid | ||
name: os.hostname() + ":" + process.pid, | ||
}; | ||
@@ -238,3 +238,3 @@ ``` | ||
database: 0, | ||
namespace: "resque" // Also allow array of strings | ||
namespace: "resque", // Also allow array of strings | ||
}; | ||
@@ -247,3 +247,3 @@ | ||
worker.on("error", error => { | ||
worker.on("error", (error) => { | ||
// handler errors | ||
@@ -262,3 +262,3 @@ }); | ||
```javascript | ||
// assume you already initialize redis client before | ||
// assume you already initialized redis client before | ||
@@ -273,3 +273,3 @@ var redisClient = new Redis(); | ||
worker.on("error", error => { | ||
worker.on("error", (error) => { | ||
// handler errors | ||
@@ -341,4 +341,13 @@ }); | ||
We use a try/catch pattern to catch errors in your jobs. If any job throws an uncaught exception, it will be caught, and the job's payload moved to the error queue for inspection. Do not use `domains`, `process.onExit`, or any other method of "catching" a process crash. The error payload looks like: | ||
We use a try/catch pattern to catch errors in your jobs. If any job throws an | ||
uncaught exception, it will be caught, and the job's payload moved to the error | ||
queue for inspection. | ||
Do not use [domain], [process.on("exit")][process.onexit], or any other method | ||
of "catching" a process crash. | ||
[domain]: https://nodejs.org/api/domain.html | ||
[process.onexit]: https://nodejs.org/api/process.html#process_event_exit | ||
The error payload looks like: | ||
```javascript | ||
@@ -398,3 +407,2 @@ { worker: 'busted-worker-3', | ||
Assuming you are running node-resque across multiple machines, you will need to ensure that only one of your processes is actually scheduling the jobs. To help you with this, you can inspect which of the scheduler processes is currently acting as leader, and flag only the master scheduler process to run the schedule. A full example can be found at [/examples/scheduledJobs.ts](https://github.com/actionhero/node-resque/blob/master/examples/scheduledJobs.ts), but the relevant section is: | ||
@@ -462,3 +470,3 @@ | ||
pluginOptions: { | ||
MyPlugin: { thing: "stuff" } | ||
MyPlugin: { thing: "stuff" }, | ||
}, | ||
@@ -468,4 +476,4 @@ perform: (a, b) => { | ||
return answer; | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
@@ -485,3 +493,3 @@ ``` | ||
pluginOptions: { | ||
MyPlugin: { thing: "stuff" } | ||
MyPlugin: { thing: "stuff" }, | ||
}, | ||
@@ -491,4 +499,4 @@ perform: (a, b) => { | ||
return answer; | ||
} | ||
} | ||
}, | ||
}, | ||
}; | ||
@@ -518,3 +526,3 @@ ``` | ||
host: "127.0.0.1", | ||
password: "" | ||
password: "", | ||
}; | ||
@@ -529,3 +537,3 @@ | ||
checkTimeout: 1000, | ||
maxEventLoopDelay: 10 | ||
maxEventLoopDelay: 10, | ||
}, | ||
@@ -536,6 +544,6 @@ jobs | ||
// normal worker emitters | ||
multiWorker.on("start", workerId => { | ||
multiWorker.on("start", (workerId) => { | ||
console.log("worker[" + workerId + "] started"); | ||
}); | ||
multiWorker.on("end", workerId => { | ||
multiWorker.on("end", (workerId) => { | ||
console.log("worker[" + workerId + "] ended"); | ||
@@ -605,3 +613,3 @@ }); | ||
}); | ||
multiWorker.on("pause", workerId => { | ||
multiWorker.on("pause", (workerId) => { | ||
console.log("worker[" + workerId + "] paused"); | ||
@@ -611,3 +619,3 @@ }); | ||
// multiWorker emitters | ||
multiWorker.on("internalError", error => { | ||
multiWorker.on("internalError", (error) => { | ||
console.log(error); | ||
@@ -614,0 +622,0 @@ }); |
# Ruby Resque UI | ||
This directory contains a small ruby project which will run the resque web server. This is contained within the node-resque project so that we can test and confirm that node-resque is interoperable with ruby-resque. | ||
This directory contains a small ruby project which will run the resque web server. This is contained within the node-resque project so that we can test and confirm that node-resque is interoperable with ruby-resque. | ||
1) **install ruby** | ||
1. **install ruby** | ||
Ensure that you have ruby installed on your system. You can confirm this with `ruby --version`. You can get ruby from [ruby-lang.org](https://www.ruby-lang.org) if you don't have it. OSX comes with ruby, and most linux distributions have a top-level package (i.e.: `apt-get install ruby`) | ||
Ensure that you have ruby installed on your system. You can confirm this with `ruby --version`. You can get ruby from [ruby-lang.org](https://www.ruby-lang.org) if you don't have it. OSX comes with ruby, and most linux distributions have a top-level package (i.e.: `apt-get install ruby`) | ||
2) **install bundler** | ||
2. **install bundler** | ||
Bundler is the ruby package manager (think NPM). Ruby uses "gems" (packages), and bundler is a tool that can manage dependencies of a project. A `Gemfile` contains a list of dependancies and a `Gemfile.lock` is like a `npm shinkwrap` output, formally defining gem versions. | ||
Bundler is the ruby package manager (think NPM). Ruby uses "gems" (packages), and bundler is a tool that can manage dependencies of a project. A `Gemfile` contains a list of dependancies and a `Gemfile.lock` is like a `npm shinkwrap` output, formally defining gem versions. | ||
Install bundler with `gem install bundler` (the `gem` application is included with ruby) | ||
3) **install the packages** | ||
3. **install the packages** | ||
From within this directory, run `bundle install`. This equivalent to `npm install` | ||
From within this directory, run `bundle install`. This equivalent to `npm install` | ||
4) **run the application** | ||
4. **run the application** | ||
The ruby-resque package includes a web interface which can be "mounted" within a number of common ruby web frameworks, like sintatra, ruby-on-rails, etc. I have included the smallest possible application which is a [`rack`](http://rack.github.io/) application. To run this application, type `bundle exec rackup`. Running this command will boot the server on port `9292` (and the CLI will inform you if this changed). | ||
The ruby-resque package includes a web interface which can be "mounted" within a number of common ruby web frameworks, like sintatra, ruby-on-rails, etc. I have included the smallest possible application which is a [`rack`](http://rack.github.io/) application. To run this application, type `bundle exec rackup`. Running this command will boot the server on port `9292` (and the CLI will inform you if this changed). | ||
@@ -23,0 +23,0 @@ This should only be used in development, as there is no security around this web interface, and you can delete everything. |
import { EventEmitter } from "events"; | ||
import * as os from "os"; | ||
import { Worker } from "./worker"; | ||
import { Connection } from "./connection"; | ||
import { EventLoopDelay } from "./../utils/eventLoopDelay"; | ||
@@ -21,3 +20,2 @@ import { MultiWorkerOptions } from "../types/options"; | ||
stopInProcess: boolean; | ||
connection: Connection; | ||
checkTimer: NodeJS.Timeout; | ||
@@ -203,6 +201,3 @@ | ||
this.working = false; | ||
if (workingCount > 0) { | ||
this.working = true; | ||
} | ||
this.working = workingCount > 0; | ||
@@ -302,3 +297,3 @@ if (this.running === false && this.workers.length > 0) { | ||
private async checkWraper() { | ||
private async checkWrapper() { | ||
clearTimeout(this.checkTimer); | ||
@@ -308,3 +303,3 @@ const { verb, eventLoopDelay } = await this.checkWorkers(); | ||
this.checkTimer = setTimeout(() => { | ||
this.checkWraper(); | ||
this.checkWrapper(); | ||
}, this.options.checkTimeout); | ||
@@ -315,3 +310,3 @@ } | ||
this.running = true; | ||
this.checkWraper(); | ||
this.checkWrapper(); | ||
} | ||
@@ -318,0 +313,0 @@ |
@@ -40,6 +40,6 @@ // If a job fails, retry it N times before finally placing it into the failed queue | ||
const remaning = await this.attemptUp(); | ||
const remaining = await this.attemptUp(); | ||
await this.saveLastError(); | ||
if (remaning <= 0) { | ||
if (remaining <= 0) { | ||
await this.cleanup(); | ||
@@ -51,3 +51,3 @@ throw this.worker.error; | ||
if (Array.isArray(this.options.backoffStrategy)) { | ||
let index = this.options.retryLimit - remaning - 1; | ||
let index = this.options.retryLimit - remaining - 1; | ||
if (index > this.options.backoffStrategy.length - 1) { | ||
@@ -69,3 +69,4 @@ index = this.options.backoffStrategy.length - 1; | ||
delay: nextTryDelay, | ||
remaningAttempts: remaning, | ||
remaningAttempts: remaining, // @deprecated | ||
remainingAttempts: remaining, | ||
err: this.worker.error, | ||
@@ -135,4 +136,4 @@ }); | ||
await this.redis().expire(key, this.maxDelay()); | ||
const remaning = this.options.retryLimit - retryCount - 1; | ||
return remaning; | ||
return this.options.retryLimit - retryCount - 1; | ||
} | ||
@@ -139,0 +140,0 @@ |
Sorry, the diff of this file is not supported yet
654599
7875
630