Skip to content

Instantly share code, notes, and snippets.

View mr-pascal's full-sized avatar

Pascal mr-pascal

View GitHub Profile
@mr-pascal
mr-pascal / main.go
Created July 3, 2021 05:47
main.go file of our local `models` module
package models
type MyEvent struct {
Type string
SecondParam string
}
func MyPublicFunc() int {
return 5
}
@mr-pascal
mr-pascal / main.go
Last active July 3, 2021 05:40
main file of the service module
package main
import (
"log"
// Import local 'models' module
"models"
)
func main() {
// Create new "MyEvent" struct
@mr-pascal
mr-pascal / go.mod
Created July 3, 2021 05:30
go.mod file of the service module
module service
go 1.15
require (
models v1.0.0
)
replace (
models v1.0.0 => ../models
function mySlowFunction(baseNumber) {
let result = 0;
for (var i = Math.pow(baseNumber, 7); i >= 0; i--) {
result += Math.atan(i) * Math.tan(i);
};
}
app.get('/highcpu', (req,res)=>{
mySlowFunction(10);
app.get('/longrunning', (req, res) => {
// Simply wait for 5 seconds before returning.
// Simulating some long but CPU inexpensive Operation.
const sleep = 5000;
setTimeout(() => {
res.status(200).send().end();
}, sleep)
});
runtime: nodejs14
service: my-app
instance_class: F2
automatic_scaling:
# Default 0 | 0 to 1000
min_instances: 0
# Default 0 | 0 to 2147483647
max_instances: 100
# Default: automatic | 1 to 1000
max_idle_instances: automatic
/**
*
* @param {Table} table
* @param {string} rowKey
* @param {RawFilter} filter
* @returns {Promise<Row>}
*/
const getRow = async (table, rowKey, filter) => {
const [singleRow] = await table.row(rowKey).get({ filter });
return singleRow;
/**
*
* @param {Object} el
* @param {string} el.key
* @param {number} el.value
* @returns
*/
const createSimpleRow = (el) => ({
key: el.key,
data: {
/**
*
* @param {Instance} instance Bigtable instance
* @param {string} tableId ID of the table to create
* @returns {Promise<Table>}
*/
const createTable = async (instance, tableId) => {
const table = instance.table(tableId);
const tableOptions = {
families: [{
/**
* Delete the instance provided by the instanceId
* @param {string} instanceId
*/
const deleteInstance = async (instanceId) => {
const instance = bigtable.instance(instanceId);
console.log('Deleting Instance');
await instance.delete();
console.log(`Instance deleted: '${instance.id}'`);
}