Skip to content
This repository has been archived by the owner on Mar 5, 2018. It is now read-only.

Commit

Permalink
check in the build
Browse files Browse the repository at this point in the history
  • Loading branch information
w33ble committed Mar 1, 2017
1 parent 283731d commit 6038b0a
Show file tree
Hide file tree
Showing 14 changed files with 1,018 additions and 0 deletions.
12 changes: 12 additions & 0 deletions lib/constants/default_settings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
DEFAULT_SETTING_TIMEOUT: 10000,
DEFAULT_SETTING_DATE_SEPARATOR: '-',
DEFAULT_SETTING_INTERVAL: 'week',
DEFAULT_SETTING_DOCTYPE: 'esqueue'
};
module.exports = exports['default'];
20 changes: 20 additions & 0 deletions lib/constants/events.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
EVENT_QUEUE_ERROR: 'queue:error',
EVENT_JOB_ERROR: 'job:error',
EVENT_JOB_CREATED: 'job:created',
EVENT_JOB_CREATE_ERROR: 'job:creation error',
EVENT_WORKER_COMPLETE: 'worker:job complete',
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: 'worker:job timeout'
};
module.exports = exports['default'];
22 changes: 22 additions & 0 deletions lib/constants/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _events = require('./events');

var _events2 = _interopRequireDefault(_events);

var _statuses = require('./statuses');

var _statuses2 = _interopRequireDefault(_statuses);

var _default_settings = require('./default_settings');

var _default_settings2 = _interopRequireDefault(_default_settings);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

exports.default = Object.assign({}, _events2.default, _statuses2.default, _default_settings2.default);
module.exports = exports['default'];
13 changes: 13 additions & 0 deletions lib/constants/statuses.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
JOB_STATUS_PENDING: 'pending',
JOB_STATUS_PROCESSING: 'processing',
JOB_STATUS_COMPLETED: 'completed',
JOB_STATUS_FAILED: 'failed',
JOB_STATUS_CANCELLED: 'cancelled'
};
module.exports = exports['default'];
30 changes: 30 additions & 0 deletions lib/helpers/create_client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createClient;
exports.isClient = isClient;

var _elasticsearch = require('elasticsearch');

var _elasticsearch2 = _interopRequireDefault(_elasticsearch);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function createClient(options) {
var client = void 0;

if (isClient(options)) {
client = options;
} else {
client = new _elasticsearch2.default.Client(options);
}

return client;
};

function isClient(client) {
// if there's a transport property, assume it's a client instance
return !!client.transport;
}
55 changes: 55 additions & 0 deletions lib/helpers/create_index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = createIndex;

var _constants = require('../constants');

var schema = {
jobtype: { type: 'keyword' },
payload: { type: 'object', enabled: false },
priority: { type: 'byte' },
timeout: { type: 'long' },
process_expiration: { type: 'date' },
created_by: { type: 'keyword' },
created_at: { type: 'date' },
started_at: { type: 'date' },
completed_at: { type: 'date' },
attempts: { type: 'short' },
max_attempts: { type: 'short' },
status: { type: 'keyword' },
output: {
type: 'object',
properties: {
content_type: { type: 'keyword', index: false },
content: { type: 'object', enabled: false }
}
}
};

function createIndex(client, indexName) {
var doctype = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : _constants.DEFAULT_SETTING_DOCTYPE;
var settings = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};

var indexBody = { mappings: {} };
indexBody.mappings[doctype] = { properties: schema };

var body = Object.assign({}, { settings: settings }, indexBody);

return client.indices.exists({
index: indexName
}).then(function (exists) {
if (!exists) {
return client.indices.create({
index: indexName,
body: body
}).then(function () {
return true;
});
}
return exists;
});
}
module.exports = exports['default'];
29 changes: 29 additions & 0 deletions lib/helpers/errors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.WorkerTimeoutError = WorkerTimeoutError;
exports.UnspecifiedWorkerError = UnspecifiedWorkerError;
function WorkerTimeoutError(message) {
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

this.name = 'WorkerTimeoutError';
this.message = message;
this.timeout = props.timeout;
this.jobId = props.jobId;

if ("captureStackTrace" in Error) Error.captureStackTrace(this, WorkerTimeoutError);else this.stack = new Error().stack;
}
WorkerTimeoutError.prototype = Object.create(Error.prototype);

function UnspecifiedWorkerError(message) {
var props = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};

this.name = 'UnspecifiedWorkerError';
this.message = message;
this.jobId = props.jobId;

if ("captureStackTrace" in Error) Error.captureStackTrace(this, UnspecifiedWorkerError);else this.stack = new Error().stack;
}
UnspecifiedWorkerError.prototype = Object.create(Error.prototype);
47 changes: 47 additions & 0 deletions lib/helpers/index_timestamp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.intervals = undefined;
exports.default = indexTimestamp;

var _moment = require('moment');

var _moment2 = _interopRequireDefault(_moment);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var intervals = exports.intervals = ['year', 'month', 'week', 'day', 'hour', 'minute'];

function indexTimestamp(intervalStr) {
var separator = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '-';

if (separator.match(/[a-z]/i)) throw new Error('Interval separator can not be a letter');

var index = intervals.indexOf(intervalStr);
if (index === -1) throw new Error('Invalid index interval: ', intervalStr);

var m = (0, _moment2.default)();
m.startOf(intervalStr);

var dateString = void 0;
switch (intervalStr) {
case 'year':
dateString = 'YYYY';
break;
case 'month':
dateString = 'YYYY' + separator + 'MM';
break;
case 'hour':
dateString = 'YYYY' + separator + 'MM' + separator + 'DD' + separator + 'HH';
break;
case 'minute':
dateString = 'YYYY' + separator + 'MM' + separator + 'DD' + separator + 'HH' + separator + 'mm';
break;
default:
dateString = 'YYYY' + separator + 'MM' + separator + 'DD';
}

return m.format(dateString);
}
13 changes: 13 additions & 0 deletions lib/helpers/is_plain_object.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };

exports.default = function (obj) {
return (typeof obj === 'undefined' ? 'undefined' : _typeof(obj)) === 'object' && !Array.isArray(obj) && obj !== null;
};

module.exports = exports['default'];
17 changes: 17 additions & 0 deletions lib/helpers/logger.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = logger;

var _debug = require('debug');

var _debug2 = _interopRequireDefault(_debug);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function logger(type) {
return (0, _debug2.default)(type);
}
module.exports = exports['default'];
25 changes: 25 additions & 0 deletions lib/helpers/object_omit.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

exports.default = function (obj, props) {
if (!(0, _is_plain_object2.default)(obj)) return obj;
if (!Array.isArray(props)) props = [props];

var newObj = Object.assign({}, obj);

props.forEach(function (prop) {
return delete newObj[prop];
});
return newObj;
};

var _is_plain_object = require('./is_plain_object');

var _is_plain_object2 = _interopRequireDefault(_is_plain_object);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

module.exports = exports['default'];
Loading

0 comments on commit 6038b0a

Please sign in to comment.