use contants for defaults, use a common doctype

add tests, update readme
This commit is contained in:
2016-05-12 11:47:05 -07:00
parent fa784393e5
commit 0020050f3f
6 changed files with 48 additions and 20 deletions

View File

@@ -2,7 +2,7 @@ import events from 'events';
import isPlainObject from 'lodash.isplainobject';
import Puid from 'puid';
import logger from './helpers/logger';
import { jobStatuses } from './helpers/constants';
import contstants from './helpers/constants';
import createIndex from './helpers/create_index';
const debug = logger('esqueue:job');
@@ -23,10 +23,11 @@ export default class Job extends events.EventEmitter {
this.timeout = options.timeout || 10000;
this.maxAttempts = options.max_attempts || 3;
this.priority = Math.max(Math.min(options.priority || 10, 20), -20);
this.doctype = options.doctype || contstants.DEFAULT_SETTING_DOCTYPE;
this.debug = (...msg) => debug(...msg, `id: ${this.id}`);
this.ready = createIndex(client, index)
this.ready = createIndex(client, index, this.doctype)
.then(() => {
return this.client.index({
index: this.index,
@@ -40,7 +41,7 @@ export default class Job extends events.EventEmitter {
created_at: new Date(),
attempts: 0,
max_attempts: this.maxAttempts,
status: jobStatuses.JOB_STATUS_PENDING,
status: contstants.JOB_STATUS_PENDING,
}
})
.then((doc) => {