Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions src/server/utils/queue/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ const runQueue = async () => {
// 1. Delete instances
queue.deleteInstances(),

// 2. Restart failed builds (re-add them to build queue)
queue.restartFailedBuilds(),

// 3. Build instances
// 2. Build instances
queue.buildInstances(),
]).catch((e) => {
getNodeKit().ctx.logError('QUEUE::runQueue', wrapInternalError(e));
Expand Down
30 changes: 1 addition & 29 deletions src/server/utils/queue/queue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,17 @@ import * as db from '../../utils/db';
import {wrapInternalError} from '../common';

import {BUILDS_LIMIT} from './constants';
import {
deleteInstance,
generateInstance,
getInstancesToRestart,
restartFailedBuilds,
} from './utils';
import {deleteInstance, generateInstance} from './utils';

export class Queue {
declare private locker: {
deleteInstances: boolean;
restartFailedBuilds: boolean;
buildInstances: boolean;
};

constructor() {
this.locker = {
deleteInstances: false,
restartFailedBuilds: false,
buildInstances: false,
};
}
Expand All @@ -46,27 +39,6 @@ export class Queue {
}
};

restartFailedBuilds = async () => {
if (this.locker.restartFailedBuilds) {
return;
}

try {
this.locker.restartFailedBuilds = true;
const instancesToRestart = await getInstancesToRestart();

if (instancesToRestart.length > 0) {
restartFailedBuilds(instancesToRestart).catch((e) => {
getNodeKit().ctx.logError('QUEUE::restartFailedBuilds', wrapInternalError(e));
});
}
} catch (e) {
getNodeKit().ctx.logError('QUEUE::restartFailedBuilds', wrapInternalError(e));
} finally {
this.locker.restartFailedBuilds = false;
}
};

buildInstances = async () => {
if (this.locker.buildInstances) {
return;
Expand Down
21 changes: 0 additions & 21 deletions src/server/utils/queue/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import type {GenerateInstanceData, InstanceObservableEmitValue} from '../../mode
import * as db from '../../utils/db';
import {formatError} from '../common';
import {fetchProjectConfig} from '../farmJsonConfig';
import {addInstanceToGenerateQueue} from '../instance';
import type {Stats} from '../stats';
import {sendStats} from '../stats';

Expand Down Expand Up @@ -176,23 +175,3 @@ export const deleteInstance = async (instance: Instance) => {
await getFarmProvider().deleteInstance(instance.hash);
await db.clearInstanceData(instance.hash);
};

export const getInstancesToRestart = async () => {
const generatingInstances = await db.getInstancesByStatus({status: 'generating'});
const instances = await getFarmProvider().getInstances();

const instancesToRestart: Instance[] = [];
generatingInstances.forEach((instance) => {
const item = instances.find((p) => p.hash === instance.hash);
// Provider creates new process right before starting the app, so we need to restart only errored instances here.
if (item?.status === 'errored') {
instancesToRestart.push(instance);
}
});

return instancesToRestart;
};

export const restartFailedBuilds = async (instances: Instance[]) => {
await Promise.all(instances.map((instance) => addInstanceToGenerateQueue(instance)));
};