fix: better worker system

This commit is contained in:
Andras Bacsai
2022-08-26 06:29:06 +00:00
parent 71c15e0ff5
commit ee4360de3a
6 changed files with 307 additions and 676 deletions

View File

@@ -14,17 +14,19 @@ import * as buildpacks from '../lib/buildPacks';
if (message === 'error') throw new Error('oops');
if (message === 'cancel') {
parentPort.postMessage('cancelled');
await prisma.$disconnect()
process.exit(0);
}
});
try {
const pThrottle = await import('p-throttle')
const throttle = pThrottle.default({
limit: 1,
interval: 2000
});
const pThrottle = await import('p-throttle')
const throttle = pThrottle.default({
limit: 1,
interval: 2000
});
const th = throttle(async () => {
const th = throttle(async () => {
try {
const queuedBuilds = await prisma.build.findMany({ where: { status: 'queued' }, orderBy: { createdAt: 'asc' } });
const { concurrentBuilds } = await prisma.setting.findFirst({})
if (queuedBuilds.length > 0) {
@@ -356,14 +358,13 @@ import * as buildpacks from '../lib/buildPacks';
}
await pAll.default(actions, { concurrency })
}
})
while (true) {
await th()
} catch (error) {
} finally {
}
})
} catch (error) {
} finally {
await prisma.$disconnect()
while (true) {
await th()
}