Skip to content

Commit b9f8662

Browse files
authored
Merge pull request #5 from psellers89/master
patch function/NS, show errors
2 parents 9c1ff9b + 621a105 commit b9f8662

File tree

5 files changed

+69
-41
lines changed

5 files changed

+69
-41
lines changed

deploy/lib/constants.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,8 @@ const path = require('path');
33
const ROOT_PROJECT_DIRECTORY = path.resolve(__dirname, '../../../../');
44
const SERVERLESS_DIRECTORY = path.resolve(ROOT_PROJECT_DIRECTORY, '.serverless');
55

6-
// Function Configuration
7-
const DEFAULT_MEMORY_LIMIT = 128;
8-
const DEFAULT_CPU_LIMIT = 1;
9-
const DEFAULT_MIN_SCALE = 0;
10-
const DEFAULT_MAX_SCALE = 20;
116

127
module.exports = {
138
ROOT_PROJECT_DIRECTORY,
149
SERVERLESS_DIRECTORY,
15-
DEFAULT_MEMORY_LIMIT,
16-
DEFAULT_CPU_LIMIT,
17-
DEFAULT_MIN_SCALE,
18-
DEFAULT_MAX_SCALE,
1910
};

deploy/lib/createFunctions.js

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,10 @@ module.exports = {
1414
getFunctions() {
1515
const functionsUrl = `namespaces/${this.namespace.id}/functions`;
1616
return this.provider.apiManager.get(functionsUrl)
17-
.then(response => response.data.functions);
17+
.then(response => response.data.functions)
18+
.catch((err) => {
19+
throw new Error(err.response.data.message)
20+
})
1821
},
1922

2023
createOrUpdateFunctions(foundFunctions) {
@@ -36,45 +39,43 @@ module.exports = {
3639
createSingleFunction(func) {
3740
const params = {
3841
name: func.name,
39-
environment_variables: func.env || {},
42+
environment_variables: func.env,
4043
namespace_id: this.namespace.id,
41-
memory_limit: func.memoryLimit || constants.DEFAULT_MEMORY_LIMIT,
42-
cpu_limit: func.cpuLimit || constants.DEFAULT_CPU_LIMIT,
43-
min_scale: func.minScale || constants.DEFAULT_MIN_SCALE,
44-
max_scale: func.maxScale || constants.DEFAULT_MAX_SCALE,
44+
memory_limit: func.memoryLimit,
45+
min_scale: func.minScale,
46+
max_scale: func.maxScale,
4547
runtime: this.runtime,
48+
timeout: func.timeout,
49+
handler: func.handler
4650
};
47-
if (func.timeout) {
48-
params.timeout = func.timeout;
49-
}
50-
if (func.handler) {
51-
params.handler = func.handler;
52-
}
51+
5352
this.serverless.cli.log(`Creating function ${func.name}...`);
5453

5554
return this.provider.apiManager.post('functions', params)
56-
.then(response => Object.assign(response.data, { handler: func.handler }));
55+
.then(response => Object.assign(response.data, { handler: func.handler }))
56+
.catch((err) => {
57+
throw new Error(err.response.data.message)
58+
})
5759
},
5860

5961
updateFunction(func, foundFunc) {
60-
const params = {
61-
environment_variables: func.env || {},
62-
min_scale: func.minScale || foundFunc.min_scale,
63-
max_scale: func.maxScale || foundFunc.max_scale,
64-
memory_limit: func.memoryLimit || foundFunc.memory_limit,
65-
cpu_limit: func.cpuLimit || foundFunc.cpu_limit,
66-
runtime: this.runtime,
67-
redeploy: false,
68-
};
69-
if (func.timeout) {
70-
params.timeout = func.timeout;
71-
}
72-
if (func.handler) {
73-
params.handler = func.handler;
74-
}
62+
63+
const params = {};
64+
65+
params.redeploy = false;
66+
params.environment_variables = func.env;
67+
params.memory_limit = func.memoryLimit;
68+
params.min_scale = func.minScale;
69+
params.max_scale = func.maxScale;
70+
params.timeout = func.timeout;
71+
params.handler = func.handler;
72+
7573
const updateUrl = `functions/${foundFunc.id}`;
7674
this.serverless.cli.log(`Updating function ${func.name}...`);
77-
return this.provider.apiManager.put(updateUrl, params)
78-
.then(response => Object.assign(response.data, { handler: func.handler }));
75+
return this.provider.apiManager.patch(updateUrl, params)
76+
.then(response => Object.assign(response.data, { handler: func.handler }))
77+
.catch((err) => {
78+
throw new Error(err.response.data.message)
79+
})
7980
},
8081
};

deploy/lib/createNamespace.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,21 @@ module.exports = {
1515

1616
createIfNotExists(foundNamespace) {
1717
// If Space already exists -> Do not create
18+
19+
if (foundNamespace && foundNamespace.status === 'error') {
20+
throw new Error(foundNamespace.error_message)
21+
}
22+
1823
const isReady = foundNamespace && foundNamespace.status === 'ready';
1924
if (isReady) {
2025
this.saveNamespaceToProvider(foundNamespace);
26+
this.updateNamespace(foundNamespace);
2127
return BbPromise.resolve();
2228
}
2329

2430
if (foundNamespace && !isReady) {
2531
this.serverless.cli.log('Waiting for Namespace to become ready...');
32+
this.updateNamespace(foundNamespace);
2633
return this.waitNamespaceIsReady();
2734
}
2835

@@ -35,12 +42,18 @@ module.exports = {
3542

3643
return this.provider.apiManager.post('namespaces', params)
3744
.then(response => this.saveNamespaceToProvider(response.data))
45+
.catch((err) => {
46+
throw new Error(err.response.data.message)
47+
})
3848
.then(() => this.waitNamespaceIsReady());
3949
},
4050

4151
waitNamespaceIsReady() {
4252
return this.provider.apiManager.get(`namespaces/${this.namespace.id}`)
4353
.then((response) => {
54+
if (response.data.status == 'error') {
55+
throw new Error(response.data.error_message)
56+
}
4457
if (response.data.status !== 'ready') {
4558
return new Promise((resolve) => {
4659
setTimeout(() => resolve(this.waitNamespaceIsReady()), 1000);
@@ -49,4 +62,17 @@ module.exports = {
4962
return true;
5063
});
5164
},
65+
66+
updateNamespace(foundNamespace) {
67+
if (this.namespaceVariables) {
68+
69+
const params = {};
70+
params.environment_variables = this.namespaceVariables
71+
72+
return this.provider.apiManager.patch(`namespaces/${foundNamespace.id}`, params)
73+
.catch((err) => {
74+
throw new Error(err.response.data.message)
75+
})
76+
}
77+
}
5278
};

deploy/lib/deployFunctions.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,19 @@ module.exports = {
88
return BbPromise.bind(this)
99
.then(this.deployEachFunction)
1010
.then(() => this.serverless.cli.log('Waiting for function deployments, this may take multiple minutes...'))
11+
.catch((err) => {
12+
throw new Error(err.response.data.message)
13+
})
1114
.then(this.waitFunctionsAreDeployed);
1215
},
1316

1417
deployEachFunction() {
1518
const promises = this.functions.map(
16-
func => this.provider.apiManager.post(`functions/${func.id}/deploy`, {}).then(response => response.data),
19+
func => this.provider.apiManager.post(`functions/${func.id}/deploy`, {})
20+
.then(response => response.data)
21+
.catch((err) => {
22+
throw new Error(err.response.data.message)
23+
}),
1724
);
1825

1926
return Promise.all(promises);
@@ -26,6 +33,9 @@ module.exports = {
2633
let functionsAreReady = true;
2734
for (let i = 0; i < functions.length; i += 1) {
2835
const func = response.data.functions[i];
36+
if (func.status === 'error') {
37+
throw new Error(func.error_message)
38+
}
2939
if (func.status !== 'ready') {
3040
functionsAreReady = false;
3141
break;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "serverless-scaleway-functions",
3-
"version": "0.1.3",
3+
"version": "0.1.4",
44
"description": "Provider plugin for the Serverless Framework v1.x which adds support for Scaleway Functions.",
55
"main": "index.js",
66
"author": "scaleway.com",

0 commit comments

Comments
 (0)