move constants to lib root

This commit is contained in:
2016-07-11 11:20:44 -07:00
parent 27390fef44
commit c6986e3677
12 changed files with 32 additions and 30 deletions

View File

@@ -0,0 +1,5 @@
export default {
DEFAULT_SETTING_TIMEOUT: 10000,
DEFAULT_SETTING_INTERVAL: 'week',
DEFAULT_SETTING_DOCTYPE: 'esqueue',
};

View File

@@ -1,18 +1,4 @@
export const jobStatuses = {
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 = {
export default {
EVENT_QUEUE_ERROR: 'error',
EVENT_JOB_CREATED: 'job:created',
EVENT_JOB_ERROR: 'job:error',
@@ -21,9 +7,8 @@ export const events = {
EVENT_WORKER_JOB_CLAIM_ERROR: 'worker:claim job error',
EVENT_WORKER_JOB_SEARCH_ERROR: 'worker:pending jobs 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_EXECUTION_ERROR: 'worker:job execution error',
EVENT_WORKER_JOB_TIMEOUT_ERROR: 'worker:job timeout',
};
export default Object.assign({}, jobStatuses, defaultSettings, events);

5
src/constants/index.js Normal file
View 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);

View 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',
};

View File

@@ -1,4 +1,4 @@
import { defaultSettings } from './constants';
import { DEFAULT_SETTING_DOCTYPE } from '../constants';
const schema = {
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 : {} };
indexBody.mappings[doctype] = { properties: schema };

View File

@@ -1,11 +1,11 @@
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 indexTimestamp from './helpers/index_timestamp';
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');

View File

@@ -1,8 +1,8 @@
import events from 'events';
import isPlainObject from 'lodash.isplainobject';
import Puid from 'puid';
import contstants from './constants';
import logger from './helpers/logger';
import contstants from './helpers/constants';
import createIndex from './helpers/create_index';
const debug = logger('esqueue:job');

View File

@@ -1,8 +1,8 @@
import events from 'events';
import Puid from 'puid';
import moment from 'moment';
import constants from './constants';
import logger from './helpers/logger';
import constants from './helpers/constants';
import { WorkerTimeoutError, UnspecifiedWorkerError } from './helpers/errors';
const puid = new Puid();

View File

@@ -1,6 +1,6 @@
import { uniqueId, times, random } from 'lodash';
import elasticsearch from 'elasticsearch';
import constants from '../../lib/helpers/constants';
import constants from '../../lib/constants';
function Client() {
this.indices = {

View File

@@ -2,7 +2,7 @@ import expect from 'expect.js';
import sinon from 'sinon';
import createIndex from '../../../lib/helpers/create_index';
import elasticsearchMock from '../../fixtures/elasticsearch';
import { defaultSettings } from '../../../lib/helpers/constants';
import { DEFAULT_SETTING_DOCTYPE } from '../../../lib/constants';
describe('Create Index', function () {
@@ -36,7 +36,7 @@ describe('Create Index', function () {
it('should create the type mappings', function () {
const indexName = 'test-index';
const docType = defaultSettings.DEFAULT_SETTING_DOCTYPE;
const docType = DEFAULT_SETTING_DOCTYPE;
const result = createIndex(client, indexName);
return result

View File

@@ -3,7 +3,7 @@ import expect from 'expect.js';
import sinon from 'sinon';
import proxyquire from 'proxyquire';
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 module = proxyquire.noPreserveCache()('../../lib/job', {

View File

@@ -5,7 +5,7 @@ import { noop, random, get, find } from 'lodash';
import elasticsearchMock from '../fixtures/elasticsearch';
import QueueMock from '../fixtures/queue';
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 defaults = {