verita84 2020-12-18 18:00:12 +00:00
parent e5e1852e6f
commit c18f16032c

@ -1,7 +1,45 @@
With this feature, applications can spin up containers themselves and retrieve data from the PiCluster server. Lets explore how this works.
With this feature, applications can spin up containers themselves and retrieve data from the PiCluster server. Lets explore how this works. First, upload ```function-sample.zip``` from ```picluster/example/x86_64/ubuntu``` in the ```Image``` -> ```Manage``` -> ```Upload``` section of the PiCluster Web Console. Next, create a function as shown below.
![Pic](https://verita84.com/git/verita84/picluster/raw/branch/master/images/faas-2.png)
Below is the sample code for the function. It is a simple Node.js application that sends ```Hello, World!``` back to the server as the output.
```
var request = require('request');
var server = process.env.SERVER;
var token = process.env.TOKEN;
var uuid = process.env.UUID;
var output = '';
function sendOutput(what) {
const body = JSON.stringify({
token,
output: what,
uuid
});
const options = {
url: server + '/function',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': body.length
},
body
};
request(options, (error, response) => {
if (error) {
console.log('An error has occurred.' + error);
}
});
}
sendOutput('Hello, World!');
```
When a function is finished running, the container is automatically deleted and the output is stored on the server. When the application requests the data from the server, the data is removed as well.
![Pic](https://verita84.com/git/verita84/picluster/raw/branch/master/images/faas-0.png)