-
Notifications
You must be signed in to change notification settings - Fork 8
/
phase.js
56 lines (42 loc) · 1.72 KB
/
phase.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
const common = require("./common.js")
const fs = require("fs")
const logService = require("../services/logService.js")
class Phase {
constructor(phaseName) {
this.phaseName = phaseName
this.logger = logService(phaseName)
}
async parseInput() {
this.logger.debug(`Phase ${this.phaseName} has no parseInput implementation`)
}
async runPrePlaybookTasks() {
this.logger.debug(`Phase ${this.phaseName} has no runPrePlaybookTasks implementation`)
}
async executePlaybook() {
// check all dependencies
const ready = await common.checkFiles(this.playbookPath, this.varPath)
if (!ready) { throw `Mandatory files for ${this.phaseName} playbook do not exist.` }
const phase = this // as "this" is something else below
return new Promise(resolve => {
fs.unlink(this.playbookLogPath, function(err) {
// err can be ignored, if it did not exist -> fine
phase.playbook.on("playlog", function(data) {
phase.logger.silly(data)
fs.appendFile(phase.playbookLogPath, data, { "flag": "a+" }, (err) => { if (err) throw err})
})
phase.playbook.on("done", function(data) {
phase.logger.info(`${phase.phaseName} done, exit code is: ${data}`)
resolve()
})
phase.playbook.start()
})
})
}
async runPostPlaybookTasks() {
this.logger.debug(`Phase ${this.phaseName} has no runPostPlaybookTasks implementation`)
}
async cleanUp() {
this.logger.debug(`Phase ${this.phaseName} has no cleanUp implementation`)
}
}
module.exports = Phase