molstar
Version:
A comprehensive macromolecular library.
83 lines • 3.39 kB
JavaScript
/**
* Copyright (c) 2018-2020 mol* contributors, licensed under MIT, See LICENSE file for more info.
*
* @author David Sehnal <david.sehnal@gmail.com>
*/
import { UUID } from '../../../mol-util';
import { getQueryByName } from './api';
import { LinkedList } from '../../../mol-data/generic';
export function JobEntry(definition) {
var queryDefinition = getQueryByName(definition.queryName);
if (!queryDefinition)
throw new Error("Query '" + definition.queryName + "' is not supported.");
var normalizedParams = definition.queryParams;
var sourceId = definition.sourceId || '_local_';
return {
job: void 0,
key: sourceId + "/" + definition.entryId,
sourceId: sourceId,
entryId: definition.entryId,
queryDefinition: queryDefinition,
normalizedParams: normalizedParams,
modelNums: definition.modelNums,
copyAllCategories: !!definition.copyAllCategories,
transform: definition.transform
};
}
export function createJob(definition) {
var _a, _b;
var job = {
id: UUID.create22(),
datetime_utc: "" + new Date().toISOString().replace(/T/, ' ').replace(/\..+/, ''),
entries: definition.entries,
writer: definition.writer,
responseFormat: {
tarball: !!((_a = definition === null || definition === void 0 ? void 0 : definition.options) === null || _a === void 0 ? void 0 : _a.tarball),
encoding: ((_b = definition === null || definition === void 0 ? void 0 : definition.options) === null || _b === void 0 ? void 0 : _b.encoding) ? definition.options.encoding : !!(definition.options && definition.options.binary) ? 'bcif' : 'cif'
},
outputFilename: definition.options && definition.options.outputFilename
};
definition.entries.forEach(function (e) { return e.job = job; });
return job;
}
var _JobQueue = /** @class */ (function () {
function _JobQueue() {
this.list = LinkedList();
}
Object.defineProperty(_JobQueue.prototype, "size", {
get: function () {
return this.list.count;
},
enumerable: false,
configurable: true
});
_JobQueue.prototype.add = function (definition) {
var job = createJob(definition);
this.list.addLast(job);
return job.id;
};
_JobQueue.prototype.hasNext = function () {
return this.list.count > 0;
};
_JobQueue.prototype.getNext = function () {
return this.list.removeFirst();
};
/** Sort the job list by key = sourceId/entryId */
_JobQueue.prototype.sort = function () {
if (this.list.count === 0)
return;
var jobs = [];
for (var j = this.list.first; !!j; j = j.next) {
jobs[jobs.length] = j.value;
}
jobs.sort(function (a, b) { var _a, _b; return ((_a = a.entries[0]) === null || _a === void 0 ? void 0 : _a.key) < ((_b = b.entries[0]) === null || _b === void 0 ? void 0 : _b.key) ? -1 : 1; });
this.list = LinkedList();
for (var _i = 0, jobs_1 = jobs; _i < jobs_1.length; _i++) {
var j = jobs_1[_i];
this.list.addLast(j);
}
};
return _JobQueue;
}());
export var JobManager = new _JobQueue();
//# sourceMappingURL=jobs.js.map