Skip to content

Commit

Permalink
continue execution when task failed (#97)
Browse files Browse the repository at this point in the history
SAAS-5961
  • Loading branch information
oren-codefresh authored Feb 27, 2020
1 parent cc0331d commit f777009
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 4 deletions.
4 changes: 3 additions & 1 deletion jobs/TaskPullerJob/TaskPuller.job.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ class TaskPullerJob extends Base {
taskUid: new Chance().guid()
});
const task = new Task(this.codefreshAPI, this.kubernetesAPI, logger);
return task.exec(taskSpec);
return task.exec(taskSpec).catch((err) => {
this.logger.info(err);
});
};
}

Expand Down
37 changes: 36 additions & 1 deletion jobs/TaskPullerJob/__tests__/TaskPuller.job.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('TaskPullerJob unit tests', () => {
it('Should map all results to tasks by types and execute them', () => {
CreatePodTask.mockImplementationOnce(() => {
return {
exec: jest.fn(() => {
exec: jest.fn(async () => {
return {
status: 'ok'
};
Expand Down Expand Up @@ -86,6 +86,41 @@ describe('TaskPullerJob unit tests', () => {
return expect(task.exec()).resolves.toEqual([]);
});

it('Should not fail when a task failed', () => {
const tasks = [
{
type: 'DeletePod',
},
{
type: 'CreatePod',
}
];
DeletePodTask.mockImplementationOnce(() => ({
exec: jest.fn(async () => Promise.reject('error'))
}));
CreatePodTask.mockImplementationOnce(() => ({
exec: jest.fn(async () => Promise.resolve('value'))
}));
const logger = createLogger();
const task = new TaskPullerJob({
pullTasks: jest.fn().mockResolvedValue(tasks),
}, _.noop(), logger);
return expect(task.exec()).resolves.toEqual(['value', undefined]);
});

it('Should not fail when task failed', () => {
const tasks = [
{
prop: 'a'
},
];
const logger = createLogger();
const task = new TaskPullerJob({
pullTasks: jest.fn().mockResolvedValue(tasks),
}, _.noop(), logger);
return expect(task.exec()).resolves.toEqual([]);
});

it('Should always execute and resolve the HIGH priority task first', async () => {
const tasks = [
{
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "venona",
"version": "0.30.3",
"version": "0.30.4",
"description": "Codefresh agent to run on Codefresh's runtime environment and execute pipeline",
"main": "index.js",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion venonactl/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.30.3
0.30.4

0 comments on commit f777009

Please sign in to comment.