Skip to content

Commit

Permalink
Fix logs for action
Browse files Browse the repository at this point in the history
  • Loading branch information
ggodlewski committed Sep 24, 2023
1 parent 518dcf6 commit 5852a7d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/containers/action/ActionRunnerContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class ActionRunnerContainer extends Container {
private generatedFileService: FileContentService;
private userConfigService: UserConfigService;
private tempFileService: FileContentService;
private isErr = false;

async init(engine: ContainerEngine): Promise<void> {
await super.init(engine);
Expand Down Expand Up @@ -238,6 +239,8 @@ export class ActionRunnerContainer extends Container {

const ownerRepo = await gitScanner.getOwnerRepo();

this.isErr = false;

const actionDefs = await this.convertActionYaml(config.actions_yaml);
for (const actionDef of actionDefs) {
if (actionDef.on !== this.params['trigger']) {
Expand Down Expand Up @@ -282,6 +285,7 @@ export class ActionRunnerContainer extends Container {
break;
}
if (0 !== lastCode) {
this.isErr = true;
break;
}
}
Expand Down Expand Up @@ -310,4 +314,8 @@ export class ActionRunnerContainer extends Container {
}
return additionalEnv;
}

public failed() {
return this.isErr;
}
}
22 changes: 17 additions & 5 deletions src/containers/job/JobManagerContainer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -580,6 +580,7 @@ export class JobManagerContainer extends Container {
await this.engine.registerContainer(runActionContainer);
try {
await runActionContainer.run(folderId);
return runActionContainer.failed();
} finally {
fs.rmSync(tempPath, { recursive: true, force: true });
await this.engine.unregisterContainer(runActionContainer.params.name);
Expand Down Expand Up @@ -808,13 +809,24 @@ export class JobManagerContainer extends Container {
break;
case 'run_action':
try {
await this.runAction(driveId, currentJob.id, currentJob.trigger, currentJob.payload, currentJob.user);
const isFailed = await this.runAction(driveId, currentJob.id, currentJob.trigger, currentJob.payload, currentJob.user);
await this.clearGitCache(driveId);

this.engine.emit(driveId, 'toasts:added', {
title: 'Action done',
type: 'run_action:done',
});
if (isFailed) {
this.engine.emit(driveId, 'toasts:added', {
title: 'Action failed',
type: 'run_action:failed',
err: 'One on action steps has failed',
links: {
'#drive_logs': 'View logs'
}
});
} else {
this.engine.emit(driveId, 'toasts:added', {
title: 'Action done',
type: 'run_action:done',
});
}
} catch (err) {
this.engine.emit(driveId, 'toasts:added', {
title: 'Action failed',
Expand Down

0 comments on commit 5852a7d

Please sign in to comment.