Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: OptimalBits/bull
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.12.1
Choose a base ref
...
head repository: OptimalBits/bull
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.13.0
Choose a head ref
  • 11 commits
  • 9 files changed
  • 5 contributors

Commits on Dec 11, 2019

  1. Copy the full SHA
    d3c1527 View commit details

Commits on Jan 1, 2020

  1. Copy the full SHA
    5b6a119 View commit details

Commits on Jan 2, 2020

  1. Merge pull request #1601 from tomgrossman/develop

    fix: queue.clean should also clean job logs
    manast authored Jan 2, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    081b37f View commit details

Commits on Jan 22, 2020

  1. Merge pull request #1586 from gabegorelick/wait-multiple-jobs

    fix: whenCurrentJobsFinished should wait for all jobs
    manast authored Jan 22, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    f3f2816 View commit details

Commits on Jan 31, 2020

  1. Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    6991da4 View commit details

Commits on Feb 1, 2020

  1. Merge pull request #1631 from pakhuta/add-option-to-prevent-data-parsing

    feat: add "preventParsingData" option of job to prevent data parsing
    manast authored Feb 1, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    ce5c91d View commit details

Commits on Feb 8, 2020

  1. VERY SMALL TYPO ADJUSTMENTS

    Was reading through docs, thought these changes might be appreciated.
    wi-ski authored Feb 8, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    797aac0 View commit details
  2. Merge pull request #1639 from wi-ski/patch-1

    Cleanup typos in readme
    manast authored Feb 8, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    3079104 View commit details

Commits on Feb 13, 2020

  1. ci: update changelog

    manast committed Feb 13, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    324f136 View commit details
  2. ci: upgrade dependencies

    manast committed Feb 13, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    4a2d6d3 View commit details
  3. 3.13.0

    manast committed Feb 13, 2020

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    2a8f5ec View commit details
Showing with 228 additions and 120 deletions.
  1. +8 −0 CHANGELOG.md
  2. +6 −6 PATTERNS.md
  3. +1 −0 lib/commands/cleanJobsInSet-1.lua
  4. +3 −1 lib/job.js
  5. +3 −2 lib/queue.js
  6. +13 −13 package.json
  7. +23 −0 test/test_job.js
  8. +49 −0 test/test_when_current_jobs_finished.js
  9. +122 −98 yarn.lock
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## v.3.13.0

feat: add "preventParsingData" job option to prevent data parsing
fix: queue.clean clean job logs as well
fix: whenCurrentJobsFinished should wait for all jobs

[Changes](https://github.com/OptimalBits/bull/compare/v3.12.1...v3.13.0)

## v.3.12.1

- fix: catch errors parsing invalid progress data
12 changes: 6 additions & 6 deletions PATTERNS.md
Original file line number Diff line number Diff line change
@@ -95,15 +95,15 @@ var queueQux = new Queue('quxbaz', opts);
Redis cluster
-------------

Bull internals requires atomic operations that spans different keys. This fact breaks Redis'
rules for cluster configurations. However it is still possible to use a cluster environment
Bull internals require atomic operations that span different keys. This behavior breaks Redis's
rules for cluster configurations. However, it is still possible to use a cluster environment
by using the proper bull prefix option as a cluster "hash tag". Hash tags are used to guarantee
that certain keys are placed in the same hash slot, read more about hash tags in the [redis cluster
tutorial](https://redis.io/topics/cluster-tutorial).
tutorial](https://redis.io/topics/cluster-tutorial). A hash tag is defined with brackets. I.e. a key that has a substring inside brackets will use that
substring to determine in which hash slot the key will be placed.

A hash tag is defined with brackets. I.e. a key that has a substring inside brackets will use that
substring to determine in which hash slot the key will be placed. So to make bull compatible with
cluster, just use a queue prefix inside brackets, for example:
In summary, to make bull compatible with Redis cluster, use a queue prefix inside brackets.
For example:

```js
var queue = new Queue('cluster', {
1 change: 1 addition & 0 deletions lib/commands/cleanJobsInSet-1.lua
Original file line number Diff line number Diff line change
@@ -37,6 +37,7 @@ for _, job in ipairs(jobs) do
redis.call("ZREM", KEYS[1], job)
end
redis.call("DEL", jobKey)
redis.call("DEL", jobKey .. ":logs")
deletedCount = deletedCount + 1
table.insert(deleted, job)
end
4 changes: 3 additions & 1 deletion lib/job.js
Original file line number Diff line number Diff line change
@@ -556,8 +556,10 @@ Job.prototype._saveAttempt = function(multi, err) {
};

Job.fromJSON = function(queue, json, jobId) {
const data = JSON.parse(json.data || '{}');
const opts = JSON.parse(json.opts || '{}');
const data = opts.preventParsingData
? json.data
: JSON.parse(json.data || '{}');

const job = new Job(queue, json.name || Job.DEFAULT_JOB_NAME, data, opts);

5 changes: 3 additions & 2 deletions lib/queue.js
Original file line number Diff line number Diff line change
@@ -670,7 +670,8 @@ interface JobOptions
repeat: {
tz?: string,
endDate?: Date | string | number
}
},
preventParsingData: boolean;
}
*/

@@ -1191,7 +1192,7 @@ Queue.prototype.whenCurrentJobsFinished = function() {
return this.bclient.connect();
});

return Promise.all([this.processing[0]]).then(() => {
return Promise.all(this.processing).then(() => {
return forcedReconnection;
});
};
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bull",
"version": "3.12.1",
"version": "3.13.0",
"description": "Job manager",
"engines": {
"node": ">=8"
@@ -22,34 +22,34 @@
"dependencies": {
"cron-parser": "^2.13.0",
"debuglog": "^1.0.0",
"get-port": "^5.0.0",
"get-port": "^5.1.1",
"ioredis": "^4.14.1",
"lodash": "^4.17.15",
"p-timeout": "^3.1.0",
"promise.prototype.finally": "^3.1.1",
"p-timeout": "^3.2.0",
"promise.prototype.finally": "^3.1.2",
"semver": "^6.3.0",
"util.promisify": "^1.0.0",
"uuid": "^3.3.3"
"util.promisify": "^1.0.1",
"uuid": "^3.4.0"
},
"devDependencies": {
"@commitlint/cli": "^7.5.2",
"@commitlint/config-conventional": "^7.5.0",
"@commitlint/cli": "^7.6.1",
"@commitlint/config-conventional": "^7.6.0",
"chai": "^4.2.0",
"coveralls": "^3.0.6",
"coveralls": "^3.0.9",
"delay": "^4.3.0",
"eslint": "^5.12.1",
"eslint": "^5.16.0",
"eslint-plugin-mocha": "^6.2.1",
"eslint-plugin-node": "^8.0.1",
"expect.js": "^0.3.1",
"husky": "^1.3.1",
"istanbul": "^0.4.5",
"lint-staged": "^8.2.1",
"mocha": "^6.2.0",
"mocha": "^6.2.2",
"mocha-lcov-reporter": "^1.3.0",
"moment": "^2.24.0",
"p-reflect": "^1.0.0",
"prettier": "^1.18.2",
"sinon": "^7.4.2"
"prettier": "^1.19.1",
"sinon": "^7.5.0"
},
"scripts": {
"lint": "eslint lib test *.js",
23 changes: 23 additions & 0 deletions test/test_job.js
Original file line number Diff line number Diff line change
@@ -976,4 +976,27 @@ describe('Job', () => {
);
});
});

describe('.fromJSON', () => {
let data;

beforeEach(() => {
data = { foo: 'bar' };
});

it('should parse JSON data by default', async () => {
const job = await Job.create(queue, data, {});
const jobParsed = Job.fromJSON(queue, job.toData());

expect(jobParsed.data).to.eql(data);
});

it('should not parse JSON data if "preventParsingData" option is specified', async () => {
const job = await Job.create(queue, data, { preventParsingData: true });
const jobParsed = Job.fromJSON(queue, job.toData());
const expectedData = JSON.stringify(data);

expect(jobParsed.data).to.be(expectedData);
});
});
});
49 changes: 49 additions & 0 deletions test/test_when_current_jobs_finished.js
Original file line number Diff line number Diff line change
@@ -63,6 +63,55 @@ describe('.whenCurrentJobsFinished', () => {
);
});

it('should wait for all jobs to complete', async () => {
const queue = await utils.newQueue();

// add multiple jobs to queue
await queue.add({});
await queue.add({});

let finishJob1;
let finishJob2;

// wait for all jobs to be active
await new Promise(resolve => {
let callCount = 0;
queue.process(2, () => {
callCount++;
if (callCount === 1) {
return new Promise(resolve => {
finishJob1 = resolve;
});
}

resolve();
return new Promise(resolve => {
finishJob2 = resolve;
});
});
});

let isFulfilled = false;
const finished = queue.whenCurrentJobsFinished().then(() => {
isFulfilled = true;
});

finishJob2();
await delay(100);

expect(isFulfilled).to.equal(
false,
'should not fulfill until all jobs are finished'
);

finishJob1();
await delay(100);
expect(await finished).to.equal(
undefined,
'whenCurrentJobsFinished should resolve once all jobs are finished'
);
});

it('should wait for job to fail', async () => {
const queue = await utils.newQueue();
await queue.add({});
Loading