Skip to content

Commit

Permalink
Merge pull request #591 from nasa/harmony-1787
Browse files Browse the repository at this point in the history
HARMONY-1787: Remove variables from operation before sending work-item update
indiejames authored Jun 7, 2024
2 parents b070f63 + 413928b commit b432c21
Showing 2 changed files with 45 additions and 12 deletions.
6 changes: 6 additions & 0 deletions services/service-runner/app/workers/pull-worker.ts
Original file line number Diff line number Diff line change
@@ -222,6 +222,12 @@ async function _pullAndDoWork(repeat = true): Promise<void> {
workItem.duration = Date.now() - startTime;
// call back to Harmony to mark the work unit as complete or failed
workItemLogger.debug(`Sending response to Harmony for results of work item with id ${workItem.id} for job id ${workItem.jobID}`);

// don't need to send variables back
for (const source of workItem.operation.sources) {
source.variables = [];
}

try {
await axiosUpdateWork.put(`${workUrl}/${workItem.id}`, workItem);
} catch (e) {
51 changes: 39 additions & 12 deletions services/service-runner/test/pull-worker.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import MockAdapter from 'axios-mock-adapter';
import { expect } from 'chai';
import { describe, it } from 'mocha';
import * as sinon from 'sinon';
@@ -10,6 +9,8 @@ import * as pullWorker from '../app/workers/pull-worker';
import PullWorker from '../app/workers/pull-worker';
import * as serviceRunner from '../app/service/service-runner';
import { existsSync, writeFileSync, mkdirSync } from 'fs';
import { WorkItemRecord } from '../../harmony/app/models/work-item-interface';
import { buildOperation } from '../../harmony/test/helpers/data-operation';

const {
_pullWork,
@@ -209,8 +210,32 @@ describe('Pull Worker', async function () {
describe('when _pullWork runs', async function () {
let pullStub: SinonStub;
let doWorkStub: SinonStub;
const mock = new MockAdapter(axiosUpdateWork);
let axiosStub: SinonStub;
const dir = `${env.workingDir}/abc123`;
const fakeOperation = buildOperation('foo');
fakeOperation.sources = [
{
collection: 'fubar',
shortName: 'fubar',
versionId: '1',
coordinateVariables: [],
granules: [],
variables: [{ id: 'foo', name: 'foo', fullPath: '' }, { id: 'bar', name: 'bar', fullPath: '' }],
},
];

const fakeWorkItemRecord: WorkItemRecord = {
id: 1,
jobID: 'foo',
serviceID: 'bar',
workflowStepIndex: 1,
retryCount: 0,
duration: 0,
updatedAt: new Date(),
createdAt: new Date(),
sortIndex: 1,
operation: fakeOperation,
};
beforeEach(function () {
if (!existsSync(dir)) {
mkdirSync(dir);
@@ -219,16 +244,24 @@ describe('Pull Worker', async function () {
if (!existsSync(file)) {
writeFileSync(file, '1');
}
pullStub = sinon.stub(pullWorker.exportedForTesting, '_pullWork').callsFake(async function () { return {}; });
pullStub = sinon.stub(pullWorker.exportedForTesting, '_pullWork').callsFake(async function () { return { item: fakeWorkItemRecord }; });
doWorkStub = sinon.stub(pullWorker.exportedForTesting, '_doWork').callsFake(async function (): Promise<WorkItem> {
return new WorkItem({});
return new WorkItem(fakeWorkItemRecord);
});
axiosStub = sinon.stub(axiosUpdateWork, 'put').callsFake(async function (_url, _item) {
return [200, 'OK'];
});
mock.onPut().reply(200, 'OK');
});
this.afterEach(function () {
pullStub.restore();
doWorkStub.restore();
mock.restore();
axiosStub.restore();
});

it('removes the variables from the operation before updating the work-item', async function () {
await _pullAndDoWork(false);
const update = axiosStub.getCall(0).args[1];
expect(update.operation.sources[0].variables).to.eql([]);
});

it('cleans the working directory', async function () {
@@ -246,20 +279,17 @@ describe('Pull Worker', async function () {
describe('when _pullWork throws an exception', async function () {
let pullStub: SinonStub;
let doWorkStub: SinonStub;
const mock = new MockAdapter(axiosUpdateWork);
beforeEach(function () {
pullStub = sinon.stub(pullWorker.exportedForTesting, '_pullWork').callsFake(async function () {
throw new Error('something bad happened');
});
doWorkStub = sinon.stub(pullWorker.exportedForTesting, '_doWork').callsFake(async function (): Promise<WorkItem> {
return new WorkItem({});
});
mock.onPut().reply(200, 'OK');
});
this.afterEach(function () {
pullStub.restore();
doWorkStub.restore();
mock.restore();
});

it('deletes the WORKING lock file', async function () {
@@ -276,7 +306,6 @@ describe('Pull Worker', async function () {
describe('when _doWork throws an exception', async function () {
let pullStub: SinonStub;
let doWorkStub: SinonStub;
const mock = new MockAdapter(axiosUpdateWork);
beforeEach(function () {
pullStub = sinon.stub(pullWorker.exportedForTesting, '_pullWork').callsFake(async function (): Promise<{ item?: WorkItem; status?: number; error?: string }> {
return {};
@@ -285,12 +314,10 @@ describe('Pull Worker', async function () {
throw new Error('something bad happened');
});

mock.onPut().reply(200, 'OK');
});
this.afterEach(function () {
pullStub.restore();
doWorkStub.restore();
mock.restore();
});

it('deletes the WORKING lock file', async function () {

0 comments on commit b432c21

Please sign in to comment.