move constants to lib root
This commit is contained in:
5
src/constants/default_settings.js
Normal file
5
src/constants/default_settings.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
export default {
|
||||||
|
DEFAULT_SETTING_TIMEOUT: 10000,
|
||||||
|
DEFAULT_SETTING_INTERVAL: 'week',
|
||||||
|
DEFAULT_SETTING_DOCTYPE: 'esqueue',
|
||||||
|
};
|
||||||
@@ -1,18 +1,4 @@
|
|||||||
export const jobStatuses = {
|
export default {
|
||||||
JOB_STATUS_PENDING: 'pending',
|
|
||||||
JOB_STATUS_PROCESSING: 'processing',
|
|
||||||
JOB_STATUS_COMPLETED: 'completed',
|
|
||||||
JOB_STATUS_FAILED: 'failed',
|
|
||||||
JOB_STATUS_CANCELLED: 'cancelled',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const defaultSettings = {
|
|
||||||
DEFAULT_SETTING_TIMEOUT: 10000,
|
|
||||||
DEFAULT_SETTING_INTERVAL: 'week',
|
|
||||||
DEFAULT_SETTING_DOCTYPE: 'esqueue',
|
|
||||||
};
|
|
||||||
|
|
||||||
export const events = {
|
|
||||||
EVENT_QUEUE_ERROR: 'error',
|
EVENT_QUEUE_ERROR: 'error',
|
||||||
EVENT_JOB_CREATED: 'job:created',
|
EVENT_JOB_CREATED: 'job:created',
|
||||||
EVENT_JOB_ERROR: 'job:error',
|
EVENT_JOB_ERROR: 'job:error',
|
||||||
@@ -21,9 +7,8 @@ export const events = {
|
|||||||
EVENT_WORKER_JOB_CLAIM_ERROR: 'worker:claim job error',
|
EVENT_WORKER_JOB_CLAIM_ERROR: 'worker:claim job error',
|
||||||
EVENT_WORKER_JOB_SEARCH_ERROR: 'worker:pending jobs error',
|
EVENT_WORKER_JOB_SEARCH_ERROR: 'worker:pending jobs error',
|
||||||
EVENT_WORKER_JOB_UPDATE_ERROR: 'worker:update job error',
|
EVENT_WORKER_JOB_UPDATE_ERROR: 'worker:update job error',
|
||||||
|
EVENT_WORKER_JOB_FAIL: 'worker:job failed',
|
||||||
EVENT_WORKER_JOB_FAIL_ERROR: 'worker:failed job update error',
|
EVENT_WORKER_JOB_FAIL_ERROR: 'worker:failed job update error',
|
||||||
EVENT_WORKER_JOB_EXECUTION_ERROR: 'worker:job execution error',
|
EVENT_WORKER_JOB_EXECUTION_ERROR: 'worker:job execution error',
|
||||||
EVENT_WORKER_JOB_TIMEOUT_ERROR: 'worker:job timeout',
|
EVENT_WORKER_JOB_TIMEOUT_ERROR: 'worker:job timeout',
|
||||||
};
|
};
|
||||||
|
|
||||||
export default Object.assign({}, jobStatuses, defaultSettings, events);
|
|
||||||
5
src/constants/index.js
Normal file
5
src/constants/index.js
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import events from './events';
|
||||||
|
import statuses from './statuses';
|
||||||
|
import defaultSettings from './default_settings';
|
||||||
|
|
||||||
|
export default Object.assign({}, events, statuses, defaultSettings);
|
||||||
7
src/constants/statuses.js
Normal file
7
src/constants/statuses.js
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
export default {
|
||||||
|
JOB_STATUS_PENDING: 'pending',
|
||||||
|
JOB_STATUS_PROCESSING: 'processing',
|
||||||
|
JOB_STATUS_COMPLETED: 'completed',
|
||||||
|
JOB_STATUS_FAILED: 'failed',
|
||||||
|
JOB_STATUS_CANCELLED: 'cancelled',
|
||||||
|
};
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
import { defaultSettings } from './constants';
|
import { DEFAULT_SETTING_DOCTYPE } from '../constants';
|
||||||
|
|
||||||
const schema = {
|
const schema = {
|
||||||
jobtype: { type: 'string', index: 'not_analyzed' },
|
jobtype: { type: 'string', index: 'not_analyzed' },
|
||||||
@@ -22,7 +22,7 @@ const schema = {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function createIndex(client, indexName, doctype = defaultSettings.DEFAULT_SETTING_DOCTYPE, settings = {}) {
|
export default function createIndex(client, indexName, doctype = DEFAULT_SETTING_DOCTYPE, settings = {}) {
|
||||||
const indexBody = { mappings : {} };
|
const indexBody = { mappings : {} };
|
||||||
indexBody.mappings[doctype] = { properties: schema };
|
indexBody.mappings[doctype] = { properties: schema };
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import events from 'events';
|
import events from 'events';
|
||||||
|
import omit from 'lodash.omit';
|
||||||
|
import Job from './job.js';
|
||||||
|
import Worker from './worker.js';
|
||||||
|
import constants from './constants';
|
||||||
import createClient from './helpers/es_client';
|
import createClient from './helpers/es_client';
|
||||||
import indexTimestamp from './helpers/index_timestamp';
|
import indexTimestamp from './helpers/index_timestamp';
|
||||||
import logger from './helpers/logger';
|
import logger from './helpers/logger';
|
||||||
import constants from './helpers/constants';
|
|
||||||
import Job from './job.js';
|
|
||||||
import Worker from './worker.js';
|
|
||||||
import omit from 'lodash.omit';
|
|
||||||
|
|
||||||
const debug = logger('esqueue:queue');
|
const debug = logger('esqueue:queue');
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import events from 'events';
|
import events from 'events';
|
||||||
import isPlainObject from 'lodash.isplainobject';
|
import isPlainObject from 'lodash.isplainobject';
|
||||||
import Puid from 'puid';
|
import Puid from 'puid';
|
||||||
|
import contstants from './constants';
|
||||||
import logger from './helpers/logger';
|
import logger from './helpers/logger';
|
||||||
import contstants from './helpers/constants';
|
|
||||||
import createIndex from './helpers/create_index';
|
import createIndex from './helpers/create_index';
|
||||||
|
|
||||||
const debug = logger('esqueue:job');
|
const debug = logger('esqueue:job');
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import events from 'events';
|
import events from 'events';
|
||||||
import Puid from 'puid';
|
import Puid from 'puid';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
|
import constants from './constants';
|
||||||
import logger from './helpers/logger';
|
import logger from './helpers/logger';
|
||||||
import constants from './helpers/constants';
|
|
||||||
import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors';
|
import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors';
|
||||||
|
|
||||||
const puid = new Puid();
|
const puid = new Puid();
|
||||||
|
|||||||
2
test/fixtures/elasticsearch.js
vendored
2
test/fixtures/elasticsearch.js
vendored
@@ -1,6 +1,6 @@
|
|||||||
import { uniqueId, times, random } from 'lodash';
|
import { uniqueId, times, random } from 'lodash';
|
||||||
import elasticsearch from 'elasticsearch';
|
import elasticsearch from 'elasticsearch';
|
||||||
import constants from '../../lib/helpers/constants';
|
import constants from '../../lib/constants';
|
||||||
|
|
||||||
function Client() {
|
function Client() {
|
||||||
this.indices = {
|
this.indices = {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import expect from 'expect.js';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import createIndex from '../../../lib/helpers/create_index';
|
import createIndex from '../../../lib/helpers/create_index';
|
||||||
import elasticsearchMock from '../../fixtures/elasticsearch';
|
import elasticsearchMock from '../../fixtures/elasticsearch';
|
||||||
import { defaultSettings } from '../../../lib/helpers/constants';
|
import { DEFAULT_SETTING_DOCTYPE } from '../../../lib/constants';
|
||||||
|
|
||||||
describe('Create Index', function () {
|
describe('Create Index', function () {
|
||||||
|
|
||||||
@@ -36,7 +36,7 @@ describe('Create Index', function () {
|
|||||||
|
|
||||||
it('should create the type mappings', function () {
|
it('should create the type mappings', function () {
|
||||||
const indexName = 'test-index';
|
const indexName = 'test-index';
|
||||||
const docType = defaultSettings.DEFAULT_SETTING_DOCTYPE;
|
const docType = DEFAULT_SETTING_DOCTYPE;
|
||||||
const result = createIndex(client, indexName);
|
const result = createIndex(client, indexName);
|
||||||
|
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import expect from 'expect.js';
|
|||||||
import sinon from 'sinon';
|
import sinon from 'sinon';
|
||||||
import proxyquire from 'proxyquire';
|
import proxyquire from 'proxyquire';
|
||||||
import elasticsearchMock from '../fixtures/elasticsearch';
|
import elasticsearchMock from '../fixtures/elasticsearch';
|
||||||
import contstants from '../../lib/helpers/constants';
|
import contstants from '../../lib/constants';
|
||||||
|
|
||||||
const createIndexMock = sinon.stub().returns(Promise.resolve('mock'));
|
const createIndexMock = sinon.stub().returns(Promise.resolve('mock'));
|
||||||
const module = proxyquire.noPreserveCache()('../../lib/job', {
|
const module = proxyquire.noPreserveCache()('../../lib/job', {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import { noop, random, get, find } from 'lodash';
|
|||||||
import elasticsearchMock from '../fixtures/elasticsearch';
|
import elasticsearchMock from '../fixtures/elasticsearch';
|
||||||
import QueueMock from '../fixtures/queue';
|
import QueueMock from '../fixtures/queue';
|
||||||
import Worker from '../../lib/worker';
|
import Worker from '../../lib/worker';
|
||||||
import constants from '../../lib/helpers/constants';
|
import constants from '../../lib/constants';
|
||||||
|
|
||||||
const anchor = '2016-04-02T01:02:03.456'; // saturday
|
const anchor = '2016-04-02T01:02:03.456'; // saturday
|
||||||
const defaults = {
|
const defaults = {
|
||||||
|
|||||||
Reference in New Issue
Block a user