Skip to content

Instantly share code, notes, and snippets.

@gregarndt
Created June 24, 2015 05:34
Show Gist options
  • Save gregarndt/7866f813f415682210ee to your computer and use it in GitHub Desktop.
Save gregarndt/7866f813f415682210ee 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: 'jonsafj@mozilla.com',
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);
console.log(stat.size);
let file = fs.createReadStream(filePath);
let req = request.put(artifact.putUrl).set({
'Content-Type': 'text/plain',
'Content-Length': stat.size
});
file.pipe(req);
await new Promise((accept, reject) => {
req.on('end', accept)
})
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