taskcluster-client
Advanced tools
Comparing version 0.2.0 to 0.3.0-alpha
@@ -15,2 +15,8 @@ /** | ||
/** | ||
Default location where scheduler/graph is. | ||
@constant | ||
*/ | ||
var DEFAULT_TASKCLUSTER_GRAPH = 'http://scheduler.taskcluster.net'; | ||
/** | ||
Default location where task definitions can be fetched from. | ||
@@ -32,3 +38,4 @@ @constant | ||
queueUrl: options.queueUrl || DEFAULT_TASKCLUSTER_QUEUE, | ||
tasksUrl: options.tasksUrl || DEFAULT_TASKCLUSTER_TASK_BUCKET | ||
tasksUrl: options.tasksUrl || DEFAULT_TASKCLUSTER_TASK_BUCKET, | ||
graphUrl: options.graphUrl || DEFAULT_TASKCLUSTER_GRAPH | ||
}; | ||
@@ -35,0 +42,0 @@ } |
@@ -13,3 +13,2 @@ /** | ||
/** | ||
queue messages for pending tasks. | ||
@constant | ||
@@ -20,4 +19,2 @@ */ | ||
/** | ||
queue messages for running tasks. | ||
@type String | ||
@constant | ||
@@ -28,3 +25,2 @@ */ | ||
/** | ||
queue messages for completed tasks. | ||
@constant | ||
@@ -35,3 +31,2 @@ */ | ||
/** | ||
queue messages for failed tasks. | ||
@constant | ||
@@ -42,2 +37,17 @@ */ | ||
/** | ||
@constant | ||
*/ | ||
exports.GRAPH_RUNNING = 'scheduler/v1/task-graph-running'; | ||
/** | ||
@constant | ||
*/ | ||
exports.GRAPH_BLOCKED = 'scheduler/v1/task-graph-blocked'; | ||
/** | ||
@constant | ||
*/ | ||
exports.GRAPH_FINISHED = 'scheduler/v1/task-graph-finished'; | ||
/** | ||
Rollup of all task related exchanges | ||
@@ -93,4 +103,1 @@ | ||
}; | ||
/** | ||
*/ |
@@ -43,3 +43,3 @@ /** | ||
version: '0.2.0', | ||
provisionerId: 'dont-spawn-machines-without-real-value', | ||
provisionerId: 'dont-spawn-machines', | ||
routing: '', | ||
@@ -46,0 +46,0 @@ // workerType: '' |
{ | ||
"name": "taskcluster-client", | ||
"version": "0.2.0", | ||
"version": "0.3.0-alpha", | ||
"description": "mozilla taskcluster client", | ||
@@ -26,3 +26,3 @@ "main": "index.js", | ||
"superagent": "~0.16.0", | ||
"superagent-promise": "0.0.0", | ||
"superagent-promise": "0.1.0", | ||
"url-join": "0.0.1", | ||
@@ -29,0 +29,0 @@ "object-factory": "~0.1.2" |
@@ -7,2 +7,16 @@ suite('queue', function() { | ||
var TestTask = TaskFactory.extend({ | ||
properties: { | ||
workerType: 'not-a-real-worker', | ||
provisionerId: 'fake-provisioner', | ||
metadata: { | ||
name: 'test-task', | ||
source: 'http://localhost', | ||
owner: 'testing@testing.com' | ||
} | ||
} | ||
}); | ||
//nock.recorder.rec(); | ||
suiteSetup(function() { | ||
@@ -30,14 +44,2 @@ nock.disableNetConnect(); | ||
test('#url', function() { | ||
var expected = urlJoin( | ||
subject.options.queueUrl, | ||
Queue.API_VERSION, | ||
'task/1/status' | ||
); | ||
var url = subject.url('task/%d/status', 1); | ||
assert.equal(expected, url); | ||
}); | ||
test('#amqpConnectionString', function() { | ||
@@ -60,3 +62,2 @@ var config = require('./config'); | ||
require('./test/fixtures/nock_task_post_error'); | ||
var task = TaskFactory.create(); | ||
@@ -75,10 +76,4 @@ | ||
require('./test/fixtures/nock_task_post_success'); | ||
var task = TestTask.create(); | ||
var task = TaskFactory.create({ | ||
// use some fake values so we don't run real tasks... | ||
workerType: 'not-a-real-worker', | ||
provisionerId: 'fake-provisioner-dont-do-stuff', | ||
metadata: { owner: 'testing@testing.com' } | ||
}); | ||
return subject.postTask(task).then(function(body) { | ||
@@ -94,12 +89,4 @@ // quick sanity check | ||
require('./test/fixtures/nock_task_get'); | ||
var submitTask = TestTask.create({ tags: { madeFromTest: 'yup' } }); | ||
var submitTask = TaskFactory.create({ | ||
workerType: 'not-a-real-worker', | ||
provisionerId: 'fake-provisioner-dont-do-stuff', | ||
metadata: { owner: 'testing@testing.com' }, | ||
tags: { | ||
madeFromTest: 'yup' | ||
} | ||
}); | ||
return subject.postTask(submitTask).then(function(body) { | ||
@@ -112,2 +99,21 @@ var taskId = body.status.taskId; | ||
}); | ||
suite('#taskStatus', function() { | ||
var task = TestTask.create({ routing: 'task-status-test' }); | ||
var taskId; | ||
setup(function() { | ||
require('./test/fixtures/nock_task_status'); | ||
return subject.postTask(task).then(function(body) { | ||
taskId = body.status.taskId; | ||
}); | ||
}); | ||
test('status', function() { | ||
return subject.taskStatus(taskId).then(function(body) { | ||
var status = body.status; | ||
assert.equal(status.routing, task.routing); | ||
}); | ||
}); | ||
}); | ||
}); |
101
queue.js
@@ -5,18 +5,10 @@ /** | ||
var util = require('util'); | ||
var urlJoin = require('url-join'); | ||
var config = require('./config'); | ||
var request = require('superagent-promise'); | ||
var formatUrl = require('./url'); | ||
var QueueError = require('./queueerror'); | ||
var HttpError = require('./httperror'); | ||
var API_VERSION = 'v1'; | ||
var API_VERSION = '/v1/'; | ||
function handleResponse(promise) { | ||
return promise.then(function(res) { | ||
if (res.error) throw new QueueError(res); | ||
return res.body; | ||
}); | ||
} | ||
/** | ||
@@ -39,43 +31,20 @@ HTTP api for the taskcluster queue. | ||
/** | ||
Build a url for the queue (with the appropriate version). Runs string through | ||
util.format so placeholders can be used... | ||
@param {String} path to use (can use placeholders in string) | ||
@param {Array} [placeholders] | ||
@return {String} complete url for the taskcluster queue. | ||
Fetch the amqp credentials from taskcluster queue and create an amqplib | ||
connection. | ||
@return {Promise<Object>} | ||
*/ | ||
url: function() { | ||
var format = Array.prototype.slice.call(arguments); | ||
return urlJoin( | ||
amqpConnectionString: function() { | ||
var url = formatUrl( | ||
this.options.queueUrl, | ||
API_VERSION, | ||
util.format.apply(util, format) | ||
'/settings/amqp-connection-string', | ||
[] | ||
); | ||
}, | ||
/** | ||
Issue a request to the taskcluster queue. | ||
@param {String} method to issue. | ||
@param {String} url for the queue. | ||
@return {Promise<Object>} | ||
*/ | ||
request: function(method, url) { | ||
// XXX: Add authentication here... | ||
return request(method, url); | ||
return request | ||
.get(url) | ||
.end() | ||
.then(HttpError.responseHandler); | ||
}, | ||
/** | ||
Fetch the amqp credentials from taskcluster queue and create an amqplib | ||
connection. | ||
@return {Promise<Object>} | ||
*/ | ||
amqpConnectionString: function() { | ||
return handleResponse(this.request( | ||
'GET', | ||
this.url('/settings/amqp-connection-string') | ||
).end()); | ||
}, | ||
/** | ||
Create a new task see the {@tutorial task_factories} tutorial for usage with | ||
@@ -89,10 +58,32 @@ the `taskcluster-client/factory/task` module for utilities to construct the | ||
postTask: function(task) { | ||
var req = this.request('POST', this.url('/task/new')) | ||
.send(task) | ||
.end(); | ||
var url = formatUrl(this.options.queueUrl, API_VERSION, '/task/new', []); | ||
return handleResponse(req); | ||
return request | ||
.post(url) | ||
.send(task) | ||
.end() | ||
.then(HttpError.responseHandler); | ||
}, | ||
/** | ||
Fetch the status of the given task and return a task status structure. | ||
@param {String} taskId to fetch status of. | ||
@return {Promise<Object>} promise response. | ||
*/ | ||
taskStatus: function(taskId) { | ||
var url = formatUrl( | ||
this.options.queueUrl, | ||
API_VERSION, | ||
'/task/%s/status', | ||
[taskId] | ||
); | ||
return request | ||
.get(url) | ||
.end() | ||
.then(HttpError.responseHandler); | ||
}, | ||
/** | ||
Fetch a task definition based on its task id. | ||
@@ -104,9 +95,11 @@ | ||
getTask: function(taskId) { | ||
var url = urlJoin( | ||
this.options.tasksUrl, | ||
taskId, | ||
'task.json' | ||
var url = formatUrl( | ||
this.options.tasksUrl + '/%s/%s', | ||
[taskId, 'task.json'] | ||
); | ||
return handleResponse(request('GET', url).end()); | ||
return request | ||
.get(url) | ||
.end() | ||
.then(HttpError.responseHandler); | ||
} | ||
@@ -113,0 +106,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
28125
29
730
+ Addedsuperagent-promise@0.1.0(transitive)
- Removedsuperagent-promise@0.0.0(transitive)
Updatedsuperagent-promise@0.1.0