Files
tubestation/taskcluster/docker/index-task/insert-indexes.js
Jonas Finnemann Jensen f34da84969 Bug 1333255: Task for indexing other tasks. r=jonasfj
This introduces a new docker image: `index-task`,
which given a taskId and a set of namespaces will
index the given taskId under said namespaces.

Modified to include a script with a descriptive name that curious users can
find in the source code.

MozReview-Commit-ID: KPHVT0XPfsb
2017-03-14 15:25:57 +00:00

45 lines
1.2 KiB
JavaScript

let taskcluster = require('taskcluster-client');
// Create instance of index client
let index = new taskcluster.Index({
delayFactor: 750, // Good solid delay for background process
retries: 8, // A few extra retries for robustness
baseUrl: 'taskcluster/index/v1',
});
// Create queue instance for fetching taskId
let queue = new taskcluster.Queue();
// Load input
let taskId = process.env.TARGET_TASKID;
let namespaces = process.argv.slice(2);
// Validate input
if (!taskId) {
console.log('Expected target task as environment variable: TARGET_TASKID');
process.exit(1);
}
// Fetch task definition to get expiration and then insert into index
queue.task(taskId).then(task => task.expires).then(expires => {
return Promise.all(namespaces.map(namespace => {
console.log('Inserting %s into index under: %s', taskId, namespace);
return index.insertTask(namespace, {
taskId,
rank: 0,
data: {},
expires,
});
}));
}).then(() => {
console.log('indexing successfully completed.');
process.exit(0);
}).catch(err => {
console.log('Error:\n%s', err);
if (err.stack) {
console.log('Stack:\n%s', err.stack());
}
console.log('Properties:\n%j', err);
throw err;
}).catch(() => process.exit(1));