-
-
Notifications
You must be signed in to change notification settings - Fork 229
/
Copy pathstartDeployQueueServer.ts
38 lines (32 loc) · 1.29 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
// This should be imported as early as possible so the global error handler is
// set up before any errors are thrown.
import "../serverUtils/instrument.js"
import fs from "fs-extra"
import { DEPLOY_QUEUE_FILE_PATH } 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.knexReadonlyTransaction(
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)
}
// 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)
})
void runDeployIfQueueIsNotEmpty()
}
void main()