chore: rename module to elastiq
This commit is contained in:
@@ -4,6 +4,7 @@ Notable changes to the esqueue project. Pay attention to `[BREAKING]` changes wh
|
|||||||
|
|
||||||
## v3.0.0
|
## v3.0.0
|
||||||
|
|
||||||
|
- rename to elastiq
|
||||||
- support for node v4 or earlier is no longer tested
|
- support for node v4 or earlier is no longer tested
|
||||||
- update several dependencies
|
- update several dependencies
|
||||||
- fix issue where job poller would not wait for ES response
|
- fix issue where job poller would not wait for ES response
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "esqueue",
|
"name": "elastiq",
|
||||||
"version": "2.0.2",
|
"version": "3.0.0",
|
||||||
"description": "Job queue, powered by Elasticsearch",
|
"description": "Job queue, powered by Elasticsearch",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
@@ -10,7 +10,7 @@
|
|||||||
"test": "retire -n -p package.json && npm run build && npm run unit",
|
"test": "retire -n -p package.json && npm run build && npm run unit",
|
||||||
"unit": "nyc --require babel-core/register mocha test/src/**"
|
"unit": "nyc --require babel-core/register mocha test/src/**"
|
||||||
},
|
},
|
||||||
"author": "Elastic (https://github.com/elastic)",
|
"author": "Joe Fleming (https://github.com/w33ble)",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"job",
|
"job",
|
||||||
"queue",
|
"queue",
|
||||||
@@ -19,7 +19,7 @@
|
|||||||
],
|
],
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "https://github.com/elastic/esqueue.git"
|
"url": "https://github.com/w33ble/elastiq.git"
|
||||||
},
|
},
|
||||||
"license": "Apache-2.0",
|
"license": "Apache-2.0",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
33
readme.md
33
readme.md
@@ -1,10 +1,12 @@
|
|||||||
[](https://travis-ci.org/w33ble/esqueue)
|
[](https://travis-ci.org/w33ble/elastiq)
|
||||||
[](https://raw.githubusercontent.com/w33ble/esqueue/master/LICENSE)
|
[](https://raw.githubusercontent.com/w33ble/elastiq/master/LICENSE)
|
||||||
[](https://github.com/w33ble/esqueue#project-status)
|
[](https://github.com/w33ble/elastiq#project-status)
|
||||||
|
|
||||||
# esqueue
|
# elastiq
|
||||||
|
|
||||||
`esqueue` is an Elasticsearch-powered job queue. This is not supported by Elastic.
|
`elastiq` is an Elasticsearch-powered job queue.
|
||||||
|
|
||||||
|
Pronounced Elasti-queue. This is not supported by Elastic.
|
||||||
|
|
||||||
## Project Status
|
## Project Status
|
||||||
|
|
||||||
@@ -14,20 +16,17 @@ While it's believed to be pretty stable, this library isn't really being used an
|
|||||||
|
|
||||||
Version | Elasticsearch Version
|
Version | Elasticsearch Version
|
||||||
------- | ---------------------
|
------- | ---------------------
|
||||||
2.x + | 5.x +
|
3.x + | 5.x +
|
||||||
0.x-1.x | 2.x-4.x
|
|
||||||
|
|
||||||
`npm install esqueue`
|
`npm install elastiq`
|
||||||
|
|
||||||
If you are working with an older version of Elasticsearch, you need it to work with an older version of esqueue. For example:
|
If you are working with an older version of Elasticsearch, consider using `esqueue`.
|
||||||
|
|
||||||
`npm install esqueue@^1.0.0`
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
Simply include the module in your application.
|
Simply include the module in your application.
|
||||||
|
|
||||||
`var Esqueue = require('esqueue');`
|
`var elastiq = require('elastiq');`
|
||||||
|
|
||||||
### Creating a queue
|
### Creating a queue
|
||||||
|
|
||||||
@@ -37,7 +36,7 @@ The first step is to create a new Queue instance. This is your point of entry, i
|
|||||||
var index = 'my-index';
|
var index = 'my-index';
|
||||||
var options = {};
|
var options = {};
|
||||||
|
|
||||||
var queue = new Esqueue(index, options);
|
var queue = new Elastiq(index, options);
|
||||||
```
|
```
|
||||||
|
|
||||||
The queue instance is an event emitter, so you can listen for `error` events as you would any other event emitter.
|
The queue instance is an event emitter, so you can listen for `error` events as you would any other event emitter.
|
||||||
@@ -49,7 +48,7 @@ Option | Default | Description
|
|||||||
interval | `week` | Valid choices are `year`, `month`, `week`, `day`, `hour`, and even `minute`. | `week`
|
interval | `week` | Valid choices are `year`, `month`, `week`, `day`, `hour`, and even `minute`. | `week`
|
||||||
dateSeparator | `-` | Separator for the formatted date, *YYYY-MM-DD* for example, in the index pattern.
|
dateSeparator | `-` | Separator for the formatted date, *YYYY-MM-DD* for example, in the index pattern.
|
||||||
timeout | `10000` | The default job timeout, in `ms`. If workers take longer than this, the job is re-queued for another worker to complete it.
|
timeout | `10000` | The default job timeout, in `ms`. If workers take longer than this, the job is re-queued for another worker to complete it.
|
||||||
doctype | `esqueue` | The doctype to use in Elasticsearch
|
doctype | `elastiq` | The doctype to use in Elasticsearch
|
||||||
indexSettings | | Specify which `settings` to pass on index creation. See the [Elasticsearch index creation docs](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/indices-create-index.html) for more info.
|
indexSettings | | Specify which `settings` to pass on index creation. See the [Elasticsearch index creation docs](https://www.elastic.co/guide/en/elasticsearch/reference/2.3/indices-create-index.html) for more info.
|
||||||
client | | Options to use when creating a new client instance - see [the elasticsearch-js docs](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html). If you rather use your own client instance, just pass it in here instead.
|
client | | Options to use when creating a new client instance - see [the elasticsearch-js docs](https://www.elastic.co/guide/en/elasticsearch/client/javascript-api/current/configuration.html). If you rather use your own client instance, just pass it in here instead.
|
||||||
|
|
||||||
@@ -159,15 +158,15 @@ All of the above are valid. `workerFn2` and `asyncWorker` are likely to be more
|
|||||||
|
|
||||||
## Queue events
|
## Queue events
|
||||||
|
|
||||||
`esqueue` components, namely the Queue, Job, and Worker instances, are also event emitters. Each instance will emit events to help your application know when certain things happen in the queue, like when a job is created, or a worker is done running, or when it times out.
|
`elastiq` components, namely the Queue, Job, and Worker instances, are also event emitters. Each instance will emit events to help your application know when certain things happen in the queue, like when a job is created, or a worker is done running, or when it times out.
|
||||||
|
|
||||||
It's important to note that all events emitted from the Job and Worker instances are also emitted on the Queue instance. This means that your application should be able to react to changes by only keeping track of that instance.
|
It's important to note that all events emitted from the Job and Worker instances are also emitted on the Queue instance. This means that your application should be able to react to changes by only keeping track of that instance.
|
||||||
|
|
||||||
Available events can be found in `lib/constants/events.js`, and you're encouraged to import and use those constant values in your application. Here's an example:
|
Available events can be found in `lib/constants/events.js`, and you're encouraged to import and use those constant values in your application. Here's an example:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
var Queue = require('esqueue');
|
var Queue = require('elastiq');
|
||||||
var queueEvents = require('esqueue/lib/constants/events');
|
var queueEvents = require('elastiq/lib/constants/events');
|
||||||
|
|
||||||
var jobQueue = new Queue('my-index');
|
var jobQueue = new Queue('my-index');
|
||||||
|
|
||||||
|
|||||||
@@ -2,5 +2,5 @@ export default {
|
|||||||
DEFAULT_SETTING_TIMEOUT: 10000,
|
DEFAULT_SETTING_TIMEOUT: 10000,
|
||||||
DEFAULT_SETTING_DATE_SEPARATOR: '-',
|
DEFAULT_SETTING_DATE_SEPARATOR: '-',
|
||||||
DEFAULT_SETTING_INTERVAL: 'week',
|
DEFAULT_SETTING_INTERVAL: 'week',
|
||||||
DEFAULT_SETTING_DOCTYPE: 'esqueue',
|
DEFAULT_SETTING_DOCTYPE: 'elastiq',
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -7,9 +7,9 @@ import indexTimestamp from './helpers/index_timestamp';
|
|||||||
import objectOmit from './helpers/object_omit';
|
import objectOmit from './helpers/object_omit';
|
||||||
import logger from './helpers/logger';
|
import logger from './helpers/logger';
|
||||||
|
|
||||||
const debug = logger('esqueue:queue');
|
const debug = logger('elastiq:queue');
|
||||||
|
|
||||||
export default class Esqueue extends events.EventEmitter {
|
export default class Elastiq extends events.EventEmitter {
|
||||||
constructor(index, options = {}) {
|
constructor(index, options = {}) {
|
||||||
if (!index) throw new Error('Must specify an index to write to');
|
if (!index) throw new Error('Must specify an index to write to');
|
||||||
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import logger from './helpers/logger';
|
|||||||
import createIndex from './helpers/create_index';
|
import createIndex from './helpers/create_index';
|
||||||
import isPlainObject from './helpers/is_plain_object';
|
import isPlainObject from './helpers/is_plain_object';
|
||||||
|
|
||||||
const debug = logger('esqueue:job');
|
const debug = logger('elastiq:job');
|
||||||
const puid = new Puid();
|
const puid = new Puid();
|
||||||
|
|
||||||
export default class Job extends events.EventEmitter {
|
export default class Job extends events.EventEmitter {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import logger from './helpers/logger';
|
|||||||
import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors';
|
import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors';
|
||||||
|
|
||||||
const puid = new Puid();
|
const puid = new Puid();
|
||||||
const debug = logger('esqueue:worker');
|
const debug = logger('elastiq:worker');
|
||||||
|
|
||||||
function formatJobObject(job) {
|
function formatJobObject(job) {
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import elasticsearchMock from '../fixtures/elasticsearch';
|
|||||||
import jobMock from '../fixtures/job';
|
import jobMock from '../fixtures/job';
|
||||||
import workerMock from '../fixtures/worker';
|
import workerMock from '../fixtures/worker';
|
||||||
|
|
||||||
const Esqueue = proxyquire.noPreserveCache()('../../lib/index', {
|
const Queue = proxyquire.noPreserveCache()('../../lib/index', {
|
||||||
'./job.js': jobMock,
|
'./job.js': jobMock,
|
||||||
'./worker.js': workerMock,
|
'./worker.js': workerMock,
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Esqueue class', function () {
|
describe('Elastiq class', function () {
|
||||||
let client;
|
let client;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
@@ -21,18 +21,18 @@ describe('Esqueue class', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should be an event emitter', function () {
|
it('should be an event emitter', function () {
|
||||||
const queue = new Esqueue('esqueue', { client });
|
const queue = new Queue('elastiq', { client });
|
||||||
expect(queue).to.be.an(events.EventEmitter);
|
expect(queue).to.be.an(events.EventEmitter);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Option validation', function () {
|
describe('Option validation', function () {
|
||||||
it('should throw without an index', function () {
|
it('should throw without an index', function () {
|
||||||
const init = () => new Esqueue();
|
const init = () => new Queue();
|
||||||
expect(init).to.throwException(/must.+specify.+index/i);
|
expect(init).to.throwException(/must.+specify.+index/i);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw with an invalid host', function () {
|
it('should throw with an invalid host', function () {
|
||||||
const init = () => new Esqueue('esqueue', {
|
const init = () => new Queue('elastiq', {
|
||||||
client: { host: 'nope://nope' }
|
client: { host: 'nope://nope' }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ describe('Esqueue class', function () {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('should throw with invalid hosts', function () {
|
it('should throw with invalid hosts', function () {
|
||||||
const init = () => new Esqueue('esqueue', {
|
const init = () => new Queue('elastiq', {
|
||||||
client: { hosts: [{ host: 'localhost', protocol: 'nope' }] }
|
client: { hosts: [{ host: 'localhost', protocol: 'nope' }] }
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -51,7 +51,7 @@ describe('Esqueue class', function () {
|
|||||||
describe('Queue construction', function () {
|
describe('Queue construction', function () {
|
||||||
it('should ping the ES server', function () {
|
it('should ping the ES server', function () {
|
||||||
const pingSpy = sinon.spy(client, 'ping');
|
const pingSpy = sinon.spy(client, 'ping');
|
||||||
new Esqueue('esqueue', { client });
|
new Queue('elastiq', { client });
|
||||||
sinon.assert.calledOnce(pingSpy);
|
sinon.assert.calledOnce(pingSpy);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -63,14 +63,14 @@ describe('Esqueue class', function () {
|
|||||||
let queue;
|
let queue;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
indexName = 'esqueue-index';
|
indexName = 'elastiq-index';
|
||||||
jobType = 'test-test';
|
jobType = 'test-test';
|
||||||
payload = { payload: true };
|
payload = { payload: true };
|
||||||
queue = new Esqueue(indexName, { client });
|
queue = new Queue(indexName, { client });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should throw with invalid dateSeparator setting', function () {
|
it('should throw with invalid dateSeparator setting', function () {
|
||||||
queue = new Esqueue(indexName, { client, dateSeparator: 'a' });
|
queue = new Queue(indexName, { client, dateSeparator: 'a' });
|
||||||
const fn = () => queue.addJob(jobType, payload);
|
const fn = () => queue.addJob(jobType, payload);
|
||||||
expect(fn).to.throwException();
|
expect(fn).to.throwException();
|
||||||
});
|
});
|
||||||
@@ -97,7 +97,7 @@ describe('Esqueue class', function () {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
queue = new Esqueue(indexName, { client, indexSettings });
|
queue = new Queue(indexName, { client, indexSettings });
|
||||||
const job = queue.addJob(jobType, payload);
|
const job = queue.addJob(jobType, payload);
|
||||||
expect(job.getProp('options')).to.have.property('indexSettings', indexSettings);
|
expect(job.getProp('options')).to.have.property('indexSettings', indexSettings);
|
||||||
});
|
});
|
||||||
@@ -117,7 +117,7 @@ describe('Esqueue class', function () {
|
|||||||
let queue;
|
let queue;
|
||||||
|
|
||||||
beforeEach(function () {
|
beforeEach(function () {
|
||||||
queue = new Esqueue('esqueue', { client });
|
queue = new Queue('elastiq', { client });
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should keep track of workers', function () {
|
it('should keep track of workers', function () {
|
||||||
@@ -146,7 +146,7 @@ describe('Esqueue class', function () {
|
|||||||
doctype: 'tests'
|
doctype: 'tests'
|
||||||
};
|
};
|
||||||
|
|
||||||
queue = new Esqueue('esqueue', { client });
|
queue = new Queue('elastiq', { client });
|
||||||
const worker = queue.registerWorker('type', noop, workerOptions);
|
const worker = queue.registerWorker('type', noop, workerOptions);
|
||||||
expect(worker.getProp('options')).to.equal(workerOptions);
|
expect(worker.getProp('options')).to.equal(workerOptions);
|
||||||
});
|
});
|
||||||
@@ -154,7 +154,7 @@ describe('Esqueue class', function () {
|
|||||||
|
|
||||||
describe('Destroy', function () {
|
describe('Destroy', function () {
|
||||||
it('should destroy workers', function () {
|
it('should destroy workers', function () {
|
||||||
const queue = new Esqueue('esqueue', { client });
|
const queue = new Queue('elastiq', { client });
|
||||||
const stubs = times(3, () => { return { destroy: sinon.stub() }; });
|
const stubs = times(3, () => { return { destroy: sinon.stub() }; });
|
||||||
stubs.forEach((stub) => queue._workers.push(stub));
|
stubs.forEach((stub) => queue._workers.push(stub));
|
||||||
expect(queue.getWorkers()).to.have.length(3);
|
expect(queue.getWorkers()).to.have.length(3);
|
||||||
|
|||||||
Reference in New Issue
Block a user