Skip to content

Instantly share code, notes, and snippets.

@gregarndt
Created June 24, 2015 05:25
Show Gist options
  • Save gregarndt/8ecc9ab1f0431706bcc7 to your computer and use it in GitHub Desktop.
Save gregarndt/8ecc9ab1f0431706bcc7 to your computer and use it in GitHub Desktop.
import request from 'superagent-promise';
import taskcluster from 'taskcluster-client';
import slugid from 'slugid';
import fs from 'mz/fs';
async () => {
let queue = new taskcluster.Queue();
let taskDef = {
provisionerId: 'no-provisioner',
workerType: 'test-worker',
schedulerId: 'my-scheduler',
created: taskcluster.fromNowJSON(),
deadline: taskcluster.fromNowJSON('3 days'),
expires: taskcluster.fromNowJSON('10 days'),
scopes: [],
payload: {},
metadata: {
name: "Unit testing task",
description: "Task created during unit tests",
owner: '[email protected]',
source: 'https://github.com/taskcluster/taskcluster-queue'
},
tags: {
purpose: 'taskcluster-testing'
},
extra: {
myUsefulDetails: {
property: "that is useful by external service!!"
}
}
};
let taskId = slugid.v4();
await queue.createTask(taskId, taskDef);
await queue.claimTask(taskId, 0, {
workerGroup: 'my-worker-group',
workerId: 'my-worker'
});
let artifact = await queue.createArtifact(taskId, 0, 'public/test.html', {
storageType: 's3',
expires: taskcluster.fromNowJSON('1 hour'),
contentType: 'text/plain'
});
let filePath = '/Users/mozilla/test/artifact_uplaod/test.html';
let stat = await fs.stat(filePath);
let file = fs.createReadStream(filePath);
let req = request.put(artifact.putUrl).set({
'Content-Type': 'text/plain',
'Content-Length': stat.size
});
file.pipe(req);
req.end();
await queue.reportCompleted(taskId, 0);
}().catch((err) => { console.log(err); console.log(err.stack) });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment