- 浏览: 2550780 次
- 性别:
- 来自: 成都
文章分类
最新评论
-
nation:
你好,在部署Mesos+Spark的运行环境时,出现一个现象, ...
Spark(4)Deal with Mesos -
sillycat:
AMAZON Relatedhttps://www.godad ...
AMAZON API Gateway(2)Client Side SSL with NGINX -
sillycat:
sudo usermod -aG docker ec2-use ...
Docker and VirtualBox(1)Set up Shared Disk for Virtual Box -
sillycat:
Every Half an Hour30 * * * * /u ...
Build Home NAS(3)Data Redundancy -
sillycat:
3 List the Cron Job I Have>c ...
Build Home NAS(3)Data Redundancy
Serverless with NodeJS and TencentCloud 2020(1)Running with Component
More configuration here
https://github.com/serverless-components/tencent-scf/blob/master/docs/configure.md
Check this file
> vi ~/.tencent.credentials
cat ~/.tencent.credentials
[default]
tencent_secret_id=AKIDNccOxHLLagcxxxxx
tencent_secret_key=uZzGI5dw2tU17Axxxxx
API gateway trigger Cloud Lambda
My serverless.yml is as follow:
taskmanager:
component: "@serverless/tencent-scf"
inputs:
name: taskmanager
codeUri: ./
handler: handler.main_handler
runtime: Nodejs8.9
region: ap-shanghai
description: Task Manager to Fetch Tasks
memorySize: 128
timeout: 60
exclude:
- .gitignore
- .git/**
- .serverless
- .env
- app.js
- .DS_Stone
events:
#- timer:
# name: timer
# parameters:
# cronExpression: '*/5 * * * *'
# enable: true
- apigw:
name: manager_trigger
parameters:
protocols:
- http
description: Manager all Tasks
environment: release
endpoints:
- path: /manager
method: GET
My nodeJS code handler.js is as follow:
'use strict';
const {OrderService} = require('./src/service');
const {DB} = require('async-mysql-wrapper');
exports.main_handler = async (event, context, callback) => {
console.log("main_hander, event:" + JSON.stringify(event));
DB.init({
dbConnectionConfig: {
host: process.env.MYSQL_DB_ADDRESS,
user: process.env.MYSQL_DB_USER,
database: process.env.MYSQL_DB_NAME,
password: process.env.MYSQL_DB_PASSWORD,
connectionLimit: process.env.MYSQL_DB_POOL_SIZE || 2,
waitForConnections: true,
dateStrings: true,
},
logLevel: 'debug'
});
await OrderService.calculateOrderInfo();
return "success";
};
The service codes is like this index.js
const OrderService = require('./order-service');
module.exports = {
OrderService,
}
The service codes is just normal business logic order-service.js
const {OrderDAO} = require('../model');
const LambdaService = require('./lambda-service');
const DateUtil = require('../util/date-util');
const _ = require('lodash');
const lookBackDays = process.env.LOOKBACK_DAYS || 30;
const batchSize = process.env.BATCH_SIZE || 2;
const Bottleneck = require('bottleneck');
const limiter = new Bottleneck({
maxConcurrent: 1,
minTime: process.env.RATE_TIME || 1000
});
class OrderService {
static async calculateOrderInfo() {
console.log("calculate get invoked at time: " + DateUtil.currentTime());
const startDate = DateUtil.lookBackDays(lookBackDays);
const endDate = DateUtil.lookBackDays(1);
console.log("loading date between " + startDate + " " + endDate);
const items = await OrderDAO.loadIDRange(startDate, endDate);
if (items && items.length > 0) {
console.log("start to send orders " + items.length);
const chunks = _.chunk(items, batchSize);
for(const chunk of chunks) {
const ids = _.map(chunk, "id");
const idStr = _.join(ids, ",");
await limiter.schedule(() => LambdaService.callRunner('taskrunner', 'Event', { "message": idStr }) );
}
}
console.log("All data were sent to runners at time: " + DateUtil.currentTime());
}
}
module.exports = OrderService;
The sample project is services.task_runner.zip and services.task_manager.zip
The package.json dependencies looks like this:
{
"name": "task-manager",
"version": "1.0.0",
"description": "Data Calculate Manager",
"repository": {
"type": "git",
"url": "https://github.com/luohuazju/sales-services.git"
},
"license": "UNLICENSED",
"scripts": {},
"author": "Yiyi Kang",
"dependencies": {
"async-mysql-wrapper": "https://github.com/luohuazju/async-mysql-wrapper",
"bottleneck": "2.19.5",
"lodash": "4.17.15",
"moment": "2.24.0",
"mysql": "2.18.1",
"tencentcloud-sdk-nodejs": "^3.0.117"
},
"devDependencies": {
"dotenv": "6.2.0",
"serverless-tencent-scf": "^0.1.36"
}
}
The DAO layer will be simple after that index.js
const OrderDAO = require('./order-model');
module.exports = {
OrderDAO,
}
The domain layer order-model.js is as follow:
const {Repository} = require('async-mysql-wrapper')
class OrderDAO extends Repository {
constructor() {
super('order', 'id', {
'gmt_create': 'gmtCreate',
'gmt_modified': 'gmtModified',
'brand_id': 'brandID',
'product_id': 'productID',
'channel_id': 'channelID',
'event_id': 'eventID',
'employee_id': 'employeeID'
})
}
async loadIDRange(startDate, endDate) {
//select id, date from sales.order where date >='2019-12-20' and date < '2019-12-21';
const query = `SELECT id FROM ?? WHERE date >= ? and date < ?`;
return await this.selectList(query, [this.tableName, startDate, endDate]);
}
}
module.exports = new OrderDAO();
References:
https://github.com/tencentyun/serverless-tencent-scf
Demo Project
https://github.com/tencentyun/scf-demo-repo
More configuration here
https://github.com/serverless-components/tencent-scf/blob/master/docs/configure.md
Check this file
> vi ~/.tencent.credentials
cat ~/.tencent.credentials
[default]
tencent_secret_id=AKIDNccOxHLLagcxxxxx
tencent_secret_key=uZzGI5dw2tU17Axxxxx
API gateway trigger Cloud Lambda
My serverless.yml is as follow:
taskmanager:
component: "@serverless/tencent-scf"
inputs:
name: taskmanager
codeUri: ./
handler: handler.main_handler
runtime: Nodejs8.9
region: ap-shanghai
description: Task Manager to Fetch Tasks
memorySize: 128
timeout: 60
exclude:
- .gitignore
- .git/**
- .serverless
- .env
- app.js
- .DS_Stone
events:
#- timer:
# name: timer
# parameters:
# cronExpression: '*/5 * * * *'
# enable: true
- apigw:
name: manager_trigger
parameters:
protocols:
- http
description: Manager all Tasks
environment: release
endpoints:
- path: /manager
method: GET
My nodeJS code handler.js is as follow:
'use strict';
const {OrderService} = require('./src/service');
const {DB} = require('async-mysql-wrapper');
exports.main_handler = async (event, context, callback) => {
console.log("main_hander, event:" + JSON.stringify(event));
DB.init({
dbConnectionConfig: {
host: process.env.MYSQL_DB_ADDRESS,
user: process.env.MYSQL_DB_USER,
database: process.env.MYSQL_DB_NAME,
password: process.env.MYSQL_DB_PASSWORD,
connectionLimit: process.env.MYSQL_DB_POOL_SIZE || 2,
waitForConnections: true,
dateStrings: true,
},
logLevel: 'debug'
});
await OrderService.calculateOrderInfo();
return "success";
};
The service codes is like this index.js
const OrderService = require('./order-service');
module.exports = {
OrderService,
}
The service codes is just normal business logic order-service.js
const {OrderDAO} = require('../model');
const LambdaService = require('./lambda-service');
const DateUtil = require('../util/date-util');
const _ = require('lodash');
const lookBackDays = process.env.LOOKBACK_DAYS || 30;
const batchSize = process.env.BATCH_SIZE || 2;
const Bottleneck = require('bottleneck');
const limiter = new Bottleneck({
maxConcurrent: 1,
minTime: process.env.RATE_TIME || 1000
});
class OrderService {
static async calculateOrderInfo() {
console.log("calculate get invoked at time: " + DateUtil.currentTime());
const startDate = DateUtil.lookBackDays(lookBackDays);
const endDate = DateUtil.lookBackDays(1);
console.log("loading date between " + startDate + " " + endDate);
const items = await OrderDAO.loadIDRange(startDate, endDate);
if (items && items.length > 0) {
console.log("start to send orders " + items.length);
const chunks = _.chunk(items, batchSize);
for(const chunk of chunks) {
const ids = _.map(chunk, "id");
const idStr = _.join(ids, ",");
await limiter.schedule(() => LambdaService.callRunner('taskrunner', 'Event', { "message": idStr }) );
}
}
console.log("All data were sent to runners at time: " + DateUtil.currentTime());
}
}
module.exports = OrderService;
The sample project is services.task_runner.zip and services.task_manager.zip
The package.json dependencies looks like this:
{
"name": "task-manager",
"version": "1.0.0",
"description": "Data Calculate Manager",
"repository": {
"type": "git",
"url": "https://github.com/luohuazju/sales-services.git"
},
"license": "UNLICENSED",
"scripts": {},
"author": "Yiyi Kang",
"dependencies": {
"async-mysql-wrapper": "https://github.com/luohuazju/async-mysql-wrapper",
"bottleneck": "2.19.5",
"lodash": "4.17.15",
"moment": "2.24.0",
"mysql": "2.18.1",
"tencentcloud-sdk-nodejs": "^3.0.117"
},
"devDependencies": {
"dotenv": "6.2.0",
"serverless-tencent-scf": "^0.1.36"
}
}
The DAO layer will be simple after that index.js
const OrderDAO = require('./order-model');
module.exports = {
OrderDAO,
}
The domain layer order-model.js is as follow:
const {Repository} = require('async-mysql-wrapper')
class OrderDAO extends Repository {
constructor() {
super('order', 'id', {
'gmt_create': 'gmtCreate',
'gmt_modified': 'gmtModified',
'brand_id': 'brandID',
'product_id': 'productID',
'channel_id': 'channelID',
'event_id': 'eventID',
'employee_id': 'employeeID'
})
}
async loadIDRange(startDate, endDate) {
//select id, date from sales.order where date >='2019-12-20' and date < '2019-12-21';
const query = `SELECT id FROM ?? WHERE date >= ? and date < ?`;
return await this.selectList(query, [this.tableName, startDate, endDate]);
}
}
module.exports = new OrderDAO();
References:
https://github.com/tencentyun/serverless-tencent-scf
Demo Project
https://github.com/tencentyun/scf-demo-repo
发表评论
-
Stop Update Here
2020-04-28 09:00 315I will stop update here, and mo ... -
NodeJS12 and Zlib
2020-04-01 07:44 474NodeJS12 and Zlib It works as ... -
Docker Swarm 2020(2)Docker Swarm and Portainer
2020-03-31 23:18 367Docker Swarm 2020(2)Docker Swar ... -
Docker Swarm 2020(1)Simply Install and Use Swarm
2020-03-31 07:58 367Docker Swarm 2020(1)Simply Inst ... -
Traefik 2020(1)Introduction and Installation
2020-03-29 13:52 335Traefik 2020(1)Introduction and ... -
Portainer 2020(4)Deploy Nginx and Others
2020-03-20 12:06 429Portainer 2020(4)Deploy Nginx a ... -
Private Registry 2020(1)No auth in registry Nginx AUTH for UI
2020-03-18 00:56 434Private Registry 2020(1)No auth ... -
Docker Compose 2020(1)Installation and Basic
2020-03-15 08:10 373Docker Compose 2020(1)Installat ... -
VPN Server 2020(2)Docker on CentOS in Ubuntu
2020-03-02 08:04 454VPN Server 2020(2)Docker on Cen ... -
Buffer in NodeJS 12 and NodeJS 8
2020-02-25 06:43 384Buffer in NodeJS 12 and NodeJS ... -
NodeJS ENV Similar to JENV and PyENV
2020-02-25 05:14 475NodeJS ENV Similar to JENV and ... -
Prometheus HA 2020(3)AlertManager Cluster
2020-02-24 01:47 421Prometheus HA 2020(3)AlertManag ... -
Serverless with NodeJS and TencentCloud 2020(5)CRON and Settings
2020-02-24 01:46 336Serverless with NodeJS and Tenc ... -
GraphQL 2019(3)Connect to MySQL
2020-02-24 01:48 246GraphQL 2019(3)Connect to MySQL ... -
GraphQL 2019(2)GraphQL and Deploy to Tencent Cloud
2020-02-24 01:48 450GraphQL 2019(2)GraphQL and Depl ... -
GraphQL 2019(1)Apollo Basic
2020-02-19 01:36 325GraphQL 2019(1)Apollo Basic Cl ... -
Serverless with NodeJS and TencentCloud 2020(4)Multiple Handlers and Running wit
2020-02-19 01:19 312Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(3)Build Tree and Traverse Tree
2020-02-19 01:19 317Serverless with NodeJS and Tenc ... -
Serverless with NodeJS and TencentCloud 2020(2)Trigger SCF in SCF
2020-02-19 01:18 291Serverless with NodeJS and Tenc ... -
Nginx Deal with OPTIONS in HTTP Protocol
2020-02-15 01:33 355Nginx Deal with OPTIONS in HTTP ...
相关推荐
无服务器Node.js项目框架 AWS Lambda上的Node.js无服务器项目的程序包... 使用以下命令克隆此存储库的主分支$ git clone --single-branch git@github.com:makenew/serverless-nodejs.git <new>$ cd (可选)使用$ gi
《Python库 TencentCloud SDK Python详解》 在Python的开发中,使用第三方库可以极大地提高我们的工作效率,TencentCloud SDK Python便是这样一个重要的工具。这个库专为Python开发者设计,旨在简化与腾讯云服务的...
Serverless Web Applications with React and Firebase 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
Serverless Design Patterns and Best Practices: Build, secure, and deploy enterprise ready serverless applications with AWS to improve developer productivity
用法Docker运行命令 # running Serverless version 1.72.0$ docker run --rm amaysim/serverless:1.72.0 serverless --help在本地构建图像如果您要构建和使用自己的本地映像 # build image locally with latest ...
serverless-nodejs-starter 具有Webpack,自定义域和单元测试支持的无服务器框架的Node.js入门 安装后,您可以在几分钟之内创建和部署具有最新ES6功能的功能,并加入棉绒和格式。 使用插件和 。 它支持: 处理...
Serverless Architectures with AWS begins with an introduction to the serverless model and helps you get started with AWS and AWS Lambda....serverless applications with and without Lambda.
The benefits of cloud-hosted serverless web apps are undeniable: lower complexity, quicker time to market, and easier scalability than traditional, server-dependent designs. And thanks to JavaScript ...
Serverless Application with Nodes.js 全英文 2019出版 Serverless Applications with Node.js walks you through building serverless apps on AWS using JavaScript. Inside, you’ll discover what Claudia.js ...
paced journey through building real-time applications with Firebase features such as Cloud Storage, Cloud Function, Hosting and the Realtime Database. We will learn how to secure our application by ...
Serverless computing with Azure and .NET 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
在本地运行API网关使用serverless offline start 支持单元测试运行npm test以运行测试 正确错误消息的源映射 错误消息显示正确的行号 使用CloudWatch进行生产 使用ESLint整理代码 为您的阶段添加环境变量 无需管理...
《PyPI官网下载的tencentcloud-sdk-python-tsf-3.0.286.1.tar.gz:深入了解腾讯云TSF SDK》 在Python的世界里,PyPI(Python Package Index)是开发者们发布和获取Python软件包的重要平台。标题中的"PyPI 官网下载 ...