Update for async v2

async.auto / async.waterfall now take the callback as the last argument in functions with dependencies.

Async is modularized so eachLimit can be required specifically
This commit is contained in:
Ray Schamp 2019-07-12 11:44:52 -04:00
parent 287b2de09d
commit 03e6a49b44
2 changed files with 15 additions and 15 deletions

View file

@ -37,11 +37,11 @@ async.auto({
} }
}); });
}, },
recvCustomVCL: ['version', function (cb, results) { recvCustomVCL: ['version', function (results, cb) {
// For all the routes in routes.json, construct a varnish-style regex that matches // For all the routes in routes.json, construct a varnish-style regex that matches
// on any of those route conditions. // on any of those route conditions.
var notPassStatement = fastlyConfig.getAppRouteCondition('../build/*', routes, extraAppRoutes, __dirname); var notPassStatement = fastlyConfig.getAppRouteCondition('../build/*', routes, extraAppRoutes, __dirname);
// For a non-pass condition, point backend at s3 // For a non-pass condition, point backend at s3
var recvCondition = '' + var recvCondition = '' +
'if (' + notPassStatement + ') {\n' + 'if (' + notPassStatement + ') {\n' +
@ -74,7 +74,7 @@ async.auto({
' return(pass);\n' + ' return(pass);\n' +
' }\n' + ' }\n' +
'}\n'; '}\n';
fastly.setCustomVCL( fastly.setCustomVCL(
results.version, results.version,
@ -83,14 +83,14 @@ async.auto({
cb cb
); );
}], }],
fetchCustomVCL: ['version', function (cb, results) { fetchCustomVCL: ['version', function (results, cb) {
var passStatement = fastlyConfig.negateConditionStatement( var passStatement = fastlyConfig.negateConditionStatement(
fastlyConfig.getAppRouteCondition('../build/*', routes, extraAppRoutes, __dirname) fastlyConfig.getAppRouteCondition('../build/*', routes, extraAppRoutes, __dirname)
); );
var ttlCondition = fastlyConfig.setResponseTTL(passStatement); var ttlCondition = fastlyConfig.setResponseTTL(passStatement);
fastly.setCustomVCL(results.version, 'fetch-condition', ttlCondition, cb); fastly.setCustomVCL(results.version, 'fetch-condition', ttlCondition, cb);
}], }],
appRouteRequestConditions: ['version', function (cb, results) { appRouteRequestConditions: ['version', function (results, cb) {
var conditions = {}; var conditions = {};
async.forEachOf(routes, function (route, id, cb2) { async.forEachOf(routes, function (route, id, cb2) {
var condition = { var condition = {
@ -110,7 +110,7 @@ async.auto({
cb(null, conditions); cb(null, conditions);
}); });
}], }],
appRouteHeaders: ['version', 'appRouteRequestConditions', function (cb, results) { appRouteHeaders: ['version', 'appRouteRequestConditions', function (results, cb) {
var headers = {}; var headers = {};
async.forEachOf(routes, function (route, id, cb2) { async.forEachOf(routes, function (route, id, cb2) {
if (route.redirect) { if (route.redirect) {
@ -133,7 +133,7 @@ async.auto({
}; };
fastly.setResponseObject(results.version, responseObject, cb3); fastly.setResponseObject(results.version, responseObject, cb3);
}, },
redirectHeader: ['responseCondition', function (cb3, redirectResults) { redirectHeader: ['responseCondition', function (redirectResults, cb3) {
var header = { var header = {
name: fastlyConfig.getHeaderNameForRoute(route), name: fastlyConfig.getHeaderNameForRoute(route),
action: 'set', action: 'set',
@ -172,7 +172,7 @@ async.auto({
cb(null, headers); cb(null, headers);
}); });
}], }],
tipbarRedirectHeaders: ['version', function (cb, results) { tipbarRedirectHeaders: ['version', function (results, cb) {
async.auto({ async.auto({
requestCondition: function (cb2) { requestCondition: function (cb2) {
var condition = { var condition = {
@ -192,7 +192,7 @@ async.auto({
}; };
fastly.setCondition(results.version, condition, cb2); fastly.setCondition(results.version, condition, cb2);
}, },
responseObject: ['requestCondition', function (cb2, redirectResults) { responseObject: ['requestCondition', function (redirectResults, cb2) {
var responseObject = { var responseObject = {
name: 'redirects/?tip_bar=', name: 'redirects/?tip_bar=',
status: 301, status: 301,
@ -201,7 +201,7 @@ async.auto({
}; };
fastly.setResponseObject(results.version, responseObject, cb2); fastly.setResponseObject(results.version, responseObject, cb2);
}], }],
redirectHeader: ['responseCondition', function (cb2, redirectResults) { redirectHeader: ['responseCondition', function (redirectResults, cb2) {
var header = { var header = {
name: 'redirects/?tip_bar=', name: 'redirects/?tip_bar=',
action: 'set', action: 'set',
@ -218,7 +218,7 @@ async.auto({
cb(null, redirectResults); cb(null, redirectResults);
}); });
}], }],
embedRedirectHeaders: ['version', function (cb, results) { embedRedirectHeaders: ['version', function (results, cb) {
async.auto({ async.auto({
requestCondition: function (cb2) { requestCondition: function (cb2) {
var condition = { var condition = {
@ -238,7 +238,7 @@ async.auto({
}; };
fastly.setCondition(results.version, condition, cb2); fastly.setCondition(results.version, condition, cb2);
}, },
responseObject: ['requestCondition', function (cb2, redirectResults) { responseObject: ['requestCondition', function (redirectResults, cb2) {
var responseObject = { var responseObject = {
name: 'redirects/projects/embed', name: 'redirects/projects/embed',
status: 301, status: 301,
@ -247,7 +247,7 @@ async.auto({
}; };
fastly.setResponseObject(results.version, responseObject, cb2); fastly.setResponseObject(results.version, responseObject, cb2);
}], }],
redirectHeader: ['responseCondition', function (cb2, redirectResults) { redirectHeader: ['responseCondition', function (redirectResults, cb2) {
var header = { var header = {
name: 'redirects/projects/embed', name: 'redirects/projects/embed',
action: 'set', action: 'set',

View file

@ -1,6 +1,6 @@
const defaults = require('lodash.defaults'); const defaults = require('lodash.defaults');
const keyMirror = require('keymirror'); const keyMirror = require('keymirror');
const async = require('async'); const eachLimit = require('async/eachLimit');
const mergeWith = require('lodash.mergewith'); const mergeWith = require('lodash.mergewith');
const uniqBy = require('lodash.uniqby'); const uniqBy = require('lodash.uniqby');
@ -524,7 +524,7 @@ module.exports.getCommentById = (projectId, commentId, ownerUsername, isAdmin, t
module.exports.getReplies = (projectId, commentIds, offset, ownerUsername, isAdmin, token) => (dispatch => { module.exports.getReplies = (projectId, commentIds, offset, ownerUsername, isAdmin, token) => (dispatch => {
dispatch(module.exports.setFetchStatus('replies', module.exports.Status.FETCHING)); dispatch(module.exports.setFetchStatus('replies', module.exports.Status.FETCHING));
const fetchedReplies = {}; const fetchedReplies = {};
async.eachLimit(commentIds, 10, (parentId, callback) => { eachLimit(commentIds, 10, (parentId, callback) => {
api({ api({
uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${parentId}/replies`, uri: `${isAdmin ? '/admin' : `/users/${ownerUsername}`}/projects/${projectId}/comments/${parentId}/replies`,
authentication: token ? token : null, authentication: token ? token : null,