Skip to content

Commit

Permalink
bug: NERC Execution (#19)
Browse files Browse the repository at this point in the history
* Ensure sim files are made
* Make errors easier to follow
  • Loading branch information
cbolles committed Nov 22, 2024
1 parent a048dc8 commit c4cfb54
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 21 deletions.
3 changes: 2 additions & 1 deletion packages/backend/src/job/job.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ export class JobService {
{ name: 'REDIS_PORT', value: this.configService.getOrThrow<string>('redis.jobPort') },
{ name: 'REDIS_PASSWORD', value: this.configService.get<string>('redis.jobPassword') },
{ name: 'COMETS_GLOP', value: './lib/comets_glop' }
]
],
imagePullPolicy: 'Always'
});
this.jobTemplate.spec.template.spec.restartPolicy = 'Never';
this.jobTemplate.spec.backoffLimit = 0;
Expand Down
39 changes: 19 additions & 20 deletions packages/backend/src/simulation/simulation.consumer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,14 @@ export class SimulationRequestConsumer extends WorkerHost {
async process(job: Job<SimulationRequest, any, string>): Promise<any> {
const request = job.data;
// Start the COMETs job
try {
const jobName = await this.jobService.triggerJob(request);
// Wait for the job to complete
const status = await this.awaitCompletion(jobName);
// If the status is error, collect and send error data
if (status == JobStatus.FAILURE) {
await this.handleError(request, jobName);
} else {
await this.handleSuccess(request, jobName);
}
} catch (e) {
console.error(e);
throw e;
const jobName = await this.jobService.triggerJob(request);
// Wait for the job to complete
const status = await this.awaitCompletion(jobName);
// If the status is error, collect and send error data
if (status == JobStatus.FAILURE) {
await this.handleError(request, jobName);
} else {
await this.handleSuccess(request, jobName);
}
}

Expand All @@ -50,14 +45,18 @@ export class SimulationRequestConsumer extends WorkerHost {
* Keep checking the status of the job once a second
*/
private async awaitCompletion(jobName: string): Promise<JobStatus> {
return new Promise(async (resolve, _reject) => {
return new Promise(async (resolve, reject) => {
const checkOperations = async () => {
const status = await this.jobService.getJobStatus(jobName);
if (status == JobStatus.RUNNING) {
setTimeout(checkOperations, 1000);
return;
} else {
resolve(status);
try {
const status = await this.jobService.getJobStatus(jobName);
if (status == JobStatus.RUNNING) {
setTimeout(checkOperations, 1000);
return;
} else {
resolve(status);
}
} catch (e) {
reject(e);
}
};
await checkOperations();
Expand Down
2 changes: 2 additions & 0 deletions packages/runner/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,6 @@ ENV PYTHONUNBUFFERED=1

RUN pip3 install --no-cache-dir -r requirements.txt

RUN mkdir sim_files/

ENTRYPOINT ["python3", "main.py"]

0 comments on commit c4cfb54

Please sign in to comment.