Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d76a2c5
commit e0c15e3
Showing
24 changed files
with
144 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
export interface Trigger { | ||
useCallback: boolean; | ||
toArgs(): any; | ||
getEvent(): any; | ||
delegate(invokeWrapper: (invokeArgs: any[]) => any): any; | ||
close(); | ||
createCallback(cb); | ||
createContext(); | ||
} | ||
|
||
export class BaseTrigger implements Trigger { | ||
triggerOptions: any; | ||
useCallback = false; | ||
|
||
constructor(triggerOptions?: any) { | ||
this.triggerOptions = triggerOptions || {}; | ||
} | ||
|
||
async toArgs(): Promise<any[]> { | ||
return Promise.resolve([]); | ||
const event = this.getEvent(); | ||
return Promise.resolve([event, this.createContext()]); | ||
} | ||
|
||
async close() {} | ||
|
||
createCallback(handler) { | ||
return (err, result) => { | ||
handler(err, result); | ||
}; | ||
} | ||
|
||
async delegate(invokeWrapper: (invokeArgs: any[]) => any): Promise<any> {} | ||
|
||
async close() {} | ||
|
||
getEvent() {} | ||
|
||
createContext() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export * from '@midwayjs/faas-typings'; | ||
export * from './dist/index'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 15 additions & 3 deletions
18
packages-serverless/serverless-app/test/fixtures/faas-v2/src/event.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,23 @@ | ||
import { Provide, Func, Inject } from '@midwayjs/decorator'; | ||
import { Provide, Inject, ServerlessTrigger, ServerlessTriggerType, App } from '@midwayjs/decorator'; | ||
import { FC } from '@midwayjs/faas-typings'; | ||
import * as assert from 'assert'; | ||
import { Application } from '../../../../src'; | ||
|
||
@Provide() | ||
export class EventService { | ||
@Inject() | ||
ctx; | ||
|
||
@Func('event.handler') | ||
handler(event?: any) { | ||
@App() | ||
app: Application; | ||
|
||
@ServerlessTrigger(ServerlessTriggerType.TIMER, { | ||
type: 'cron', | ||
value: '* * * * 4', | ||
payload: 'test' | ||
}) | ||
async handler(event: FC.TimerEvent): Promise<FC.TimerEvent> { | ||
assert(this.app.getInitializeContext()); | ||
return event; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,20 @@ | ||
import { FCBaseTrigger } from './base'; | ||
|
||
import * as extend from 'extend2'; | ||
import { FC } from '@midwayjs/faas-typings'; | ||
/** | ||
* https://help.aliyun.com/document_detail/62922.html | ||
*/ | ||
export class TimerTrigger extends FCBaseTrigger { | ||
handler; | ||
|
||
async toArgs(): Promise<any[]> { | ||
const event = { | ||
triggerTime: '2019-12-01T16:00:00Z', | ||
getEvent() { | ||
return { | ||
triggerTime: new Date().toJSON(), | ||
triggerName: 'timer', | ||
payload: '', | ||
}; | ||
return [event, this.createContext()]; | ||
} | ||
} | ||
export const timer = TimerTrigger; | ||
export const createTimerEvent = (data: any = {}): FC.TimerEvent => { | ||
const result = {}; | ||
return extend(true, result, new TimerTrigger().getEvent(), data); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.