Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/common/compute/backends/ComputeClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ define([], function() {
this._events = {};
}

async startJob (/*hash, metadata*/) {
unimplemented(this.logger, 'startJob');
}

async cancelJob (/*job*/) {
unimplemented(this.logger, 'cancelJob');
}

async startJob (/*hash, metadata*/) {
unimplemented(this.logger, 'startJob');
async purgeJob (/*jobInfo*/) {
}

async getStatus (/*jobInfo*/) {
Expand Down
13 changes: 13 additions & 0 deletions src/common/compute/backends/local/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ define([
return JSON.parse(resultsTxt);
}

async purge (job) {
const {hash} = job;
if (hash === this.currentJob) {
throw new Error('Cannot purge running job.');
} else if (this.jobQueue.includes(hash)) {
const index = this.jobQueue.indexOf(hash);
this.jobQueue.splice(index, 1);
} else {
const workingDir = this._getWorkingDir(hash);
await rm_rf(workingDir);
}
}

async _getJobFile (hash, name, notFoundMsg) {
const filename = path.join(this._getWorkingDir(hash), name);
try {
Expand Down
28 changes: 28 additions & 0 deletions test/unit/common/compute/backends/local/Client.spec.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
describe('local compute', function() {
const fsp = require('fs').promises;
const assert = require('assert');
const testFixture = require('../../../../../globals');
const GeneratedFiles = testFixture.requirejs('deepforge/plugin/GeneratedFiles');
Expand Down Expand Up @@ -35,6 +36,33 @@ describe('local compute', function() {
});
});

describe('purgeJob', function() {
let jobInfo;
before(async () => {
const jobHash = await getJobHash('sleep', '0.1');
const deferred = utils.defer();
client.on('update', (hash, status) => {
if (hash === jobHash && status === client.RUNNING) {
deferred.resolve();
}
});

const computeJob = new ComputeJob(jobHash);
jobInfo = await client.startJob(computeJob);
await deferred.promise;
});

it('should throw an error when accessing status on purged job', async () => {
const {hash} = jobInfo;
await assert.rejects(() => client.getStatus(hash));
});

it('should remove tmp directory', async function() {
const dir = client._getWorkingDir();
await assert.rejects(() => fsp.lstat(dir));
});
});

async function getJobHash(cmd) {
const config = {
cmd, args: Array.prototype.slice.call(arguments, 1),
Expand Down