Skip to content

Commit

Permalink
Fix rule picking, job executor cancel bug (#58)
Browse files Browse the repository at this point in the history
* fix #57, fix rule selection bug

* fix #56, when vertex manager is not started, _job may not set
  • Loading branch information
EverettSummer authored Jul 29, 2023
1 parent ccd4478 commit 36fa4cc
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/JobManager/JobManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class JobManager {
this._job.status = JobStatus.Canceled;
this._job.jobExecutorId = null;
this._job = await jobRepo.save(this._job) as Job;
await this._vm.cancelVertices();
await this._vm.stop(this._job.id);
this._jobLogger.warn('job canceled');
this._jobLogger.info(LOG_END_FLAG);
}
Expand All @@ -156,7 +156,7 @@ export class JobManager {
const jobRepo = this._databaseService.getJobRepository();
this._job.status = JobStatus.Pause;
this._job = await jobRepo.save(this._job) as Job;
await this._vm.cancelVertices();
await this._vm.stop(this._job.id);
this._jobLogger.info('job paused.');
this._jobLogger.info(LOG_END_FLAG);
}
Expand Down
6 changes: 3 additions & 3 deletions src/JobManager/VertexManager.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 IROHA LAB
* Copyright 2023 IROHA LAB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -22,8 +22,8 @@ export interface VertexManager {
createAllVertices(job: Job): Promise<void>;
recreateCanceledVertices(job: Job): Promise<void>;
start(job: Job, jobLogPath: string): Promise<void>;
stop(): Promise<void>;
cancelVertices(): Promise<void>;
stop(jobId?: string): Promise<void>;
cancelVertices(jobId: string): Promise<void>;
}

export const EVENT_VERTEX_FAIL = 'vertex_fail';
Expand Down
15 changes: 9 additions & 6 deletions src/JobManager/VertexManagerImpl.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022 IROHA LAB
* Copyright 2023 IROHA LAB
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -71,10 +71,13 @@ export class VertexManagerImpl implements VertexManager {
await this.checkAndExecuteVertexFromQueue();
}

public async stop(): Promise<void> {
public async stop(jobId: string = null): Promise<void> {
clearTimeout(this._checkQueueTimer);
if (this._job) {
await this.cancelVertices();
if (jobId) {
await this.cancelVertices(jobId);
} else if (this._job) {
// job not started yet
await this.cancelVertices(this._job.id);
}
}

Expand Down Expand Up @@ -173,9 +176,9 @@ export class VertexManagerImpl implements VertexManager {
* cancel all running vertices, save each vertex status to VertexStatus.Canceled.
* waiting until all vertices canceled.
*/
public async cancelVertices(): Promise<void> {
public async cancelVertices(jobId: string): Promise<void> {
const vertexRepo = this._databaseService.getVertexRepository();
const vertexMap = await vertexRepo.getVertexMap(this._job.id);
const vertexMap = await vertexRepo.getVertexMap(jobId);
const allPromise = [];
Object.keys(vertexMap).forEach(vertexId => {
const vertex = vertexMap[vertexId];
Expand Down
5 changes: 4 additions & 1 deletion src/JobScheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,11 @@ export class JobScheduler implements JobApplication {
}
}
if (!appliedRule) {
// check all bangumi wide rule, we need to exclude video file specified rules
// since checkConditionMatch will return true for any rule.condition is none
// see: https://github.com/irohalab/mira-video-manager/issues/57
for (const rule of rules) {
if (await this.checkConditionMatch(rule.condition, msg)) {
if (!rule.videoFileId && await this.checkConditionMatch(rule.condition, msg)) {
appliedRule = rule;
break;
}
Expand Down

0 comments on commit 36fa4cc

Please sign in to comment.