From 1d41a9e0a1bd2c48faeb61ce3b8fc09a41406f74 Mon Sep 17 00:00:00 2001 From: pragnagopa Date: Fri, 17 Feb 2017 09:52:28 -0800 Subject: [PATCH] Work around for kudu sync triggers issue --- deploy/lib/createFunction.js | 3 ++- deploy/lib/createFunctions.js | 3 ++- provider/azureProvider.js | 31 +++++++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 2 deletions(-) diff --git a/deploy/lib/createFunction.js b/deploy/lib/createFunction.js index a0c22700..5ddd9d64 100644 --- a/deploy/lib/createFunction.js +++ b/deploy/lib/createFunction.js @@ -8,6 +8,7 @@ module.exports = { const metaData = utils.getFunctionMetaData(functionName, this.provider.getParsedBindings(), this.serverless); return this.provider.createZipObject(functionName, metaData.entryPoint, metaData.handlerPath, metaData.params) - .then(() => this.provider.createAndUploadZipFunctions()); + .then(() => this.provider.createAndUploadZipFunctions()) + .then(() => this.provider.syncTriggers()); } }; diff --git a/deploy/lib/createFunctions.js b/deploy/lib/createFunctions.js index 9247ce0d..e1960681 100644 --- a/deploy/lib/createFunctions.js +++ b/deploy/lib/createFunctions.js @@ -14,6 +14,7 @@ module.exports = { }); return BbPromise.all(createFunctionPromises) - .then(() => this.provider.createAndUploadZipFunctions()); + .then(() => this.provider.createAndUploadZipFunctions()) + .then(() => this.provider.syncTriggers()); } }; diff --git a/provider/azureProvider.js b/provider/azureProvider.js index b5ed7543..8c6b9243 100644 --- a/provider/azureProvider.js +++ b/provider/azureProvider.js @@ -473,6 +473,33 @@ return new BbPromise((resolve, reject) => { } + syncTriggers () { + let options = {}; + const requestUrl = ` https://management.azure.com/subscriptions/${subscriptionId}/resourceGroups/${resourceGroupName}/providers/Microsoft.Web/sites/${functionAppName}/functions/synctriggers?api-version=2015-08-01`; + options = { + 'host': 'management.azure.com', + 'method': 'post', + 'body': {}, + 'url': requestUrl, + 'json': true, + 'headers': { + 'Authorization': constants.bearer + principalCredentials.tokenCache._entries[0].accessToken, + 'Accept': 'application/json,*/*' + } + }; + +return new BbPromise((resolve, reject) => { + request(options, (err, res, body) => { + if (err) { + reject(err); + } + this.serverless.cli.log(`Syncing Triggers....Response statuscode: ${res.statusCode}`); + resolve(res); + }); + }); + + } + cleanUpFunctionsBeforeDeploy (serverlessFunctions) { const deleteFunctionPromises = []; @@ -516,6 +543,10 @@ return new BbPromise((resolve, reject) => { const folderForJSFunction = path.join(functionsFolder, functionName); const handlerPath = path.join(this.serverless.config.servicePath, filePath); + if (!fs.existsSync(functionsFolder)) { + fs.mkdirSync(functionsFolder); + } + if (!fs.existsSync(folderForJSFunction)) { fs.mkdirSync(folderForJSFunction); }