Skip to content

Commit

Permalink
feat: 云函数支持 method 参数;
Browse files Browse the repository at this point in the history
  • Loading branch information
maslow committed Jun 9, 2021
1 parent 30b1f98 commit 560f4e8
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/lib/faas/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ export class FunctionEngine {
ctx: {
query: incomingCtx.query,
body: incomingCtx.body,
method: incomingCtx.method,
extra: incomingCtx.extra,
auth: incomingCtx.auth,
requestId: requestId,
},
Expand Down
1 change: 1 addition & 0 deletions src/lib/faas/engine2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class FunctionEngine {
body: incomingCtx.body,
auth: incomingCtx.auth,
extra: incomingCtx.extra,
method: incomingCtx.method,
requestId: requestId,
},
module: _module,
Expand Down
6 changes: 5 additions & 1 deletion src/lib/faas/invoke.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ function createCloudSdk(): CloudSdkInterface {
throw new Error(`invoke() failed to get function: ${name}`)
}

const result = await invokeFunction(func, param ?? {})
if (param?.method) {
param.method = param.method ?? 'call'
}
const result = await invokeFunction(func, param ?? { method: 'call' })

// 将云函数调用日志存储到数据库
{
Expand Down Expand Up @@ -63,6 +66,7 @@ export async function invokeFunction(func: CloudFunctionStruct, param: FunctionC
body: body,
auth: auth,
extra: param.extra,
method: param.method,
less: createCloudSdk()
})

Expand Down
2 changes: 2 additions & 0 deletions src/lib/faas/trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export class TriggerScheduler {
logger.debug(`TriggerScheduler.emit -> ${event} - executing function : ${tri.func_id}`)
const param: FunctionContext = {
extra: data,
method: 'trigger',
requestId: `trigger_${tri.id}`
}
this.executeFunction(tri.func_id, param, tri)
Expand Down Expand Up @@ -259,6 +260,7 @@ export class TriggerScheduler {
logger.debug(`TriggerScheduler.timer-loop -> trigger(${tri.id})- executing function : ${tri.func_id}`)
const param: FunctionContext = {
extra: tri,
method: 'trigger',
requestId: `trigger_${tri.id}`
}
// 执行任务函数
Expand Down
3 changes: 2 additions & 1 deletion src/lib/faas/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ export interface FunctionContext {
body?: any,
auth?: any,
requestId?: string,
extra?: any
extra?: any,
method?: string
}

// param for engine.run()
Expand Down
2 changes: 1 addition & 1 deletion src/router/function/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async function handleInvokeFunction(req: Request, res: Response) {
}

// 调用函数
const ctx: FunctionContext = { query: req.query, body: req.body, auth: req['auth'], requestId }
const ctx: FunctionContext = { query: req.query, body: req.body, auth: req['auth'], requestId, method: req.method }
const result = await invokeFunction(func, ctx)

// 将云函数调用日志存储到数据库
Expand Down

0 comments on commit 560f4e8

Please sign in to comment.