Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
debug('Channel was closed unexpectedly');
that.emit('error', new Error(
'Channel closed unexpectedly, likely server initiated shutdown'
));
});
return channel.prefetch(that._options.prefetch);
});
// Find queue name and decide if this is an exclusive queue
var exclusive = !this._options.queueName;
// Construct queue name
this._queueName = [
'queue', // Required by pulse security model
this._connection.namespace, // Required by pulse security model
this._options.queueName || 'exclusive/' + slugid.v4(),
].join('/');
// Create queue
var queueCreated = channelCreated.then(function() {
var opts = {
exclusive: exclusive,
durable: !exclusive,
autoDelete: exclusive,
};
// Set max length if provided
if (that._options.maxLength) {
opts.maxLength = that._options.maxLength;
}
return channel.assertQueue(that._queueName, opts);
});
let timeToDeadline = secondsTo(task.deadline);
// If deadline is reached, we don't care to publish a message about the task
// being pending.
if (timeToDeadline === 0) {
// This should not happen, but if timing is right it is possible.
console.log('runId: %s of taskId: %s became pending after deadline, ' +
'skipping pending message publication to azure queue',
runId, task.taskId);
return;
}
// Put message queue
return this._putMessage(queueNames[task.priority], {
taskId: task.taskId,
runId: runId,
hintId: slugid.v4(),
}, {
ttl: timeToDeadline,
visibility: 0,
});
}
debug("Connection error in AMQPListener: ", err.stack);
that.emit('error', err);
});
return that._conn.createConfirmChannel();
}).then(function(channel_) {
channel = channel_;
channel.on('error', function(err) {
debug("Channel error in AMQPListener: ", err.stack);
that.emit('error', err);
});
return channel.prefetch(that._options.prefetch);
});
// Find queue name and decide if this is an exclusive queue
var exclusive = !this._options.queueName;
this._queueName = this._options.queueName || slugid.v4();
// Create queue
var queueCreated = channelCreated.then(function() {
var opts = {
exclusive: exclusive,
durable: !exclusive,
autoDelete: exclusive,
};
// Set max length if provided
if (that._options.maxLength) {
opts.maxLength = that._options.maxLength;
}
return channel.assertQueue(that._queueName, opts);
});
// Create bindings
Promise.from(null).then(function() {
// Create client if requested
if (req.body.updateOrCreate == 'create') {
return Client.create({
version: '0.2.0',
name: req.body.name,
clientId: slugid.v4(),
accessToken: slugid.v4() + slugid.v4() + slugid.v4(),
scopes: JSON.parse(req.body.scopes),
expires: new Date(req.body.expires),
details: {
notes: req.body.notes
}
});
}
// Update WorkerType if requested
if (req.body.updateOrCreate == 'update') {
return Client.load(req.body.clientId).then(function(client) {
return client.modify(function() {
this.name = req.body.name;
this.scopes = JSON.parse(req.body.scopes);
this.expires = new Date(req.body.expires);
this.details = {notes: req.body.notes};
Promise.from(null).then(function() {
// Create client if requested
if (req.body.updateOrCreate == 'create') {
return Client.create({
version: '0.2.0',
name: req.body.name,
clientId: slugid.v4(),
accessToken: slugid.v4() + slugid.v4() + slugid.v4(),
scopes: JSON.parse(req.body.scopes),
expires: new Date(req.body.expires),
details: {
notes: req.body.notes
}
});
}
// Update WorkerType if requested
if (req.body.updateOrCreate == 'update') {
return Client.load(req.body.clientId).then(function(client) {
return client.modify(function() {
this.name = req.body.name;
this.scopes = JSON.parse(req.body.scopes);
this.expires = new Date(req.body.expires);
userConfig[serviceName] = userConfig[serviceName] || {};
userConfig[serviceName].taskcluster_access_token = accessToken;
}
const rootUrl = answer.rootUrl || userConfig.rootUrl;
// The following are some hacks for now until we can do all of this in a
// nicer way (presumably?)
setDefault('worker_manager.providers', {});
// TODO: Figure out what any of these should be set to
setDefault('web_server.public_url', rootUrl);
setDefault('web_server.additional_allowed_cors_origin', '');
setDefault('web_server.ui_login_strategies', {});
setDefault('web_server.session_secret', slugid.v4());
//TODO: These github things can/should be questions in this setup thing
setDefault('github.bot_username', '???');
setDefault('github.github_private_pem', '???');
setDefault('github.github_app_id', '???');
setDefault('github.webhook_secret', []);
// TODO: These can/should be generated by dev:init aws setup
setDefault('queue.public_blob_artifact_bucket', 'fake_until_needed');
setDefault('queue.private_blob_artifact_bucket', 'fake_until_needed');
setDefault('queue.blob_artifact_region', 'fake_until_needed');
// TODO: This eventually should just build these from rootUrl itself probably
setDefault('ui.graphql_subscription_endpoint', `${rootUrl}/subscription`);
setDefault('ui.graphql_endpoint', `${rootUrl}/graphql`);
function _newIdentifier() {
var type = arguments.length <= 0 || arguments[0] === undefined ? 'c' : arguments[0];
return type + '-' + slugid.v4();
}
const timer = setInterval(() => setCode(v4()), 2 * 60 * 1000)
return () => clearInterval(timer)
async getMessages(name, {visibilityTimeout, numberOfMessages}) {
const {queue} = this._queue(name);
const rv = [];
const now = new Date();
const visibilityTime = taskcluster.fromNow(`${visibilityTimeout} seconds`);
for (let msg of queue) {
if (now > msg._visibleAfter && now <= msg._expiresAfter) {
msg._visibleAfter = visibilityTime;
msg._popReceipt = slugid.v4();
rv.push({
messageText: msg.messageText,
messageId: msg.messageId,
popReceipt: msg._popReceipt,
});
if (rv.length === numberOfMessages) {
break;
}
}
}
return rv;
}