-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.js
68 lines (57 loc) · 1.26 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
'use strict'
const path = require('path')
const async = require('async')
const Lokue = require('lokue')
const Base = require('bfx-facs-base')
class LokueFacility extends Base {
constructor (caller, opts, ctx) {
super(caller, opts, ctx)
this.name = 'lokue'
this.init()
}
init () {
super.init()
const cal = this.caller
const {
dbPathAbsolute,
label,
persist
} = this.opts
const baseName = `${this.name}_${this.opts.name}_${label}.db.json`
const name = (
typeof dbPathAbsolute === 'string' &&
path.isAbsolute(dbPathAbsolute)
)
? path.join(dbPathAbsolute, baseName)
: path.join(cal.ctx.root, 'db', baseName)
this.q = new Lokue({
name,
persist
})
}
_start (cb) {
async.series([
next => { super._start(next) },
next => {
this.q.init(next)
},
next => {
this._clearItv = setInterval(() => {
if (!this.q.isReady()) return
this.q.clearCompletedJobs()
this.q.clearErrorJobs()
}, 60000)
next()
}
], cb)
}
_stop (cb) {
async.series([
next => { super._stop(next) },
next => {
this.q.stop(next)
}
], cb)
}
}
module.exports = LokueFacility