-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic plugin hook to trigger on package
- Loading branch information
Showing
9 changed files
with
8,270 additions
and
5 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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/node_modules | ||
src/**.js | ||
dist |
Large diffs are not rendered by default.
Oops, something went wrong.
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,14 +1,22 @@ | ||
{ | ||
"name": "lambda-cron", | ||
"version": "0.0.3", | ||
"description": "A simple plugin to schedule cronjobs for lambdas", | ||
"main": "index.js", | ||
"description": "Super light weight Serverless Plugin to simplify adding cron jobs to functions", | ||
"main": "index.ts", | ||
"type": "module", | ||
"module": "commonjs", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "levi", | ||
"repository": { | ||
"url": "https://github.com/levi-20/lambda-cron" | ||
}, | ||
"license": "MIT" | ||
"license": "MIT", | ||
"devDependencies": { | ||
"serverless": "^3.0.0", | ||
"@types/aws-lambda": "^8.10.145", | ||
"@types/serverless": "^3.12.23", | ||
"@types/node": "22.10.7" | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
/** @format */ | ||
|
||
export const dailyAt = (dailyTime: number) => { | ||
return `cron(0 ${dailyTime} * * ? *)`; | ||
}; | ||
|
||
// export const every = (time: number, rate: any) { | ||
|
||
// } |
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,5 @@ | ||
/** @format */ | ||
|
||
import LambdaCronJobs from './lambda-cron'; | ||
|
||
module.exports = LambdaCronJobs; |
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,27 @@ | ||
/** @format */ | ||
|
||
import Serverless from 'serverless'; | ||
import { Functions, Hooks, PluginConfig } from './types'; | ||
|
||
export const CONFIG_ROOT_KEY = 'lambdaCronJobs'; | ||
export const BEFORE_PACKAGE_HOOK = 'before:package:initialize'; | ||
|
||
export default class LambdaCronJobs { | ||
functions: Functions; | ||
provider: any; | ||
log: any; | ||
pluginConfig: PluginConfig; | ||
hooks: Hooks; | ||
|
||
constructor(serverless: Serverless, options: Serverless.Options) { | ||
// this.log = log; | ||
this.functions = serverless.service?.functions; | ||
this.provider = serverless.getProvider('aws'); | ||
this.pluginConfig = serverless.service?.custom[CONFIG_ROOT_KEY]; | ||
this.hooks = { [BEFORE_PACKAGE_HOOK]: () => this.beforePackage() }; | ||
} | ||
|
||
private beforePackage() { | ||
this.log.info('plugin hook called'); | ||
} | ||
} |
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,39 @@ | ||
/** @format */ | ||
|
||
import Serverless from 'serverless'; | ||
|
||
export interface Functions { | ||
[key: string]: | ||
| Serverless.FunctionDefinitionHandler | ||
| Serverless.FunctionDefinitionImage; | ||
} | ||
export interface PluginConfigItem { | ||
rate: Rate; | ||
input?: Record<string, unknown>; | ||
} | ||
|
||
export interface PluginConfig { | ||
[key: string]: PluginConfigItem[]; | ||
} | ||
|
||
export interface FunctionCronJobConfig { | ||
functionName: string; | ||
cronJobConfig: PluginConfigItem[]; | ||
} | ||
|
||
export type SlsLog = Serverless['cli']['log']; | ||
|
||
export interface Rate { | ||
time: number; | ||
rate: RateString; | ||
} | ||
|
||
export enum RateString { | ||
'minute', | ||
'hour', | ||
'month', | ||
} | ||
|
||
export interface Hooks { | ||
[key: string]: () => void; | ||
} |
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,13 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "ES2019", | ||
"strict": true, | ||
"module": "ESNext", | ||
"esModuleInterop": true, | ||
"moduleResolution": "node", | ||
"outDir": "dist", | ||
"rootDir": "src" | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules"] | ||
} |