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 = {
|
||||
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
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 = {
|
||||
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 };
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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();
|
||||
|
||||
2
test/fixtures/elasticsearch.js
vendored
2
test/fixtures/elasticsearch.js
vendored
@@ -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 = {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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', {
|
||||
|
||||
@@ -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 = {
|
||||
|
||||
Reference in New Issue
Block a user