Skip to content

Commit 219431b

Browse files
authored
Merge pull request #87 from highcharts/develop
Develop
2 parents 2e024a6 + bbfc659 commit 219431b

File tree

2 files changed

+67
-8
lines changed

2 files changed

+67
-8
lines changed

.github/workflows/test.yml

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
name: Run Tests
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- master
7+
- develop
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout code
15+
uses: actions/checkout@v4
16+
17+
- name: Setup Node.js
18+
uses: actions/setup-node@v4
19+
with:
20+
node-version: '20'
21+
cache: 'npm'
22+
23+
- name: Install dependencies
24+
run: npm install
25+
26+
- name: Check TypeScript compilation is up to date
27+
run: |
28+
npm run tsc
29+
if [ -n "$(git status --porcelain)" ]; then
30+
echo "Error: Files have changed after running 'npm run tsc'. Please run 'npm run tsc' locally and commit the changes."
31+
git status
32+
git diff
33+
exit 1
34+
fi
35+
36+
- name: Setup config.json
37+
run: echo '{"token":"","port":"90","repo":"highcharts/highcharts"}' > config.json
38+
39+
- name: Run tests
40+
run: npm test

app/server.js

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
logErrors,
1717
setConnectionAborted
1818
} = require('./middleware.js')
19+
const { JobQueue } = require('./JobQueue')
1920
const router = require('./router.js')
2021
const { formatDate, log, compileTypeScript, compileTypeScriptProject } = require('./utilities.js')
2122
const { shouldUseWebpack } = require('./utils.js')
@@ -36,6 +37,18 @@ const state = {
3637
assembles: {}
3738
}
3839

40+
const jobQueue = new JobQueue()
41+
42+
function hasActiveJobs () {
43+
const activeTypescriptJobs = Object.keys(state.typescriptJobs).length > 0
44+
const activeAssemblyJobs = Object.keys(state.assembles).length > 0
45+
const activeQueues =
46+
jobQueue.getJobs('download').length > 0 ||
47+
jobQueue.getJobs('compile').length > 0
48+
49+
return activeTypescriptJobs || activeAssemblyJobs || activeQueues
50+
}
51+
3952
/**
4053
* Adds the compilation of the branch to the job registry
4154
* Returns the promise
@@ -176,18 +189,24 @@ APP.listen(PORT)
176189

177190
// Clean up the tmp folder every now and then
178191
setInterval(async () => {
179-
// Clean only after a certain amount of branches and when there are no jobs running
180-
if (await shouldClean()) {
181-
log(0, 'Cleaning up...')
182-
await cleanUp().catch(error => {
183-
console.log('Cleanup failed', error)
184-
})
192+
if (hasActiveJobs()) {
193+
log(1, 'Skipping cleanup while jobs are active')
194+
return
185195
}
196+
197+
if (!(await shouldClean())) {
198+
return
199+
}
200+
201+
log(0, 'Cleaning up...')
202+
await cleanUp().catch(error => {
203+
log(2, `Cleanup failed: ${error.message}`)
204+
})
186205
}, config.cleanInterval || 2 * 60 * 1000)
187206

188207
// Do a cleanup when restarting the server
189-
cleanUp().catch(() => {
190-
log(0, 'Cleanup failed. Likely nothing to cleanup')
208+
cleanUp().catch(error => {
209+
log(2, `Cleanup failed on startup: ${error.message}`)
191210
})
192211

193212
module.exports = {

0 commit comments

Comments
 (0)