forked from owid/owid-grapher
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstartDeployQueueServer.ts
47 lines (41 loc) · 1.47 KB
/
startDeployQueueServer.ts
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
import fs from "fs-extra"
import Bugsnag from "@bugsnag/js"
import {
DEPLOY_QUEUE_FILE_PATH,
BUGSNAG_NODE_API_KEY,
} from "../settings/serverSettings.js"
import { deployIfQueueIsNotEmpty } from "./DeployUtils.js"
import * as db from "../db/db.js"
// Ensure db is cleaned up on PM2 stop / restart / reload and cmd/ctrl + c
// by registering listeners on SIGINT.
import "../db/cleanup.js"
const runDeployIfQueueIsNotEmpty = async () =>
await db.knexReadWriteTransaction(
deployIfQueueIsNotEmpty,
db.TransactionCloseMode.KeepOpen
)
// TODO: The deploy queue is largely obsolete with buildkite but it's not visible in the admin yet so for now this code is kept
const main = async () => {
if (!fs.existsSync(DEPLOY_QUEUE_FILE_PATH)) {
console.error(
`No deploy queue file found in: ${DEPLOY_QUEUE_FILE_PATH}`
)
process.exit(1)
}
if (BUGSNAG_NODE_API_KEY) {
Bugsnag.start({
apiKey: BUGSNAG_NODE_API_KEY,
context: "deploy-queue",
autoTrackSessions: false,
})
}
// Listen for file changes
fs.watchFile(DEPLOY_QUEUE_FILE_PATH, () => {
// Start deploy after 10 seconds in order to avoid the quick successive
// deploys triggered by Wordpress.
setTimeout(runDeployIfQueueIsNotEmpty, 10 * 1000)
})
// TODO: this transaction is only RW because somewhere inside it we fetch images
void runDeployIfQueueIsNotEmpty()
}
void main()