Skip to content

Commit

Permalink
add local schedule script
Browse files Browse the repository at this point in the history
  • Loading branch information
Meemaw committed Aug 11, 2019
1 parent ea624ef commit 6c3ba03
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 8 deletions.
33 changes: 33 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -14,7 +14,8 @@
"test:coveralls": "jest --coverage --runInBand && cat ./coverage/lcov.info | ./node_modules/.bin/coveralls && rm -rf ./coverage",
"lint": "concurrently \"npm run prettier\" \"npm run eslint\"",
"prettier": "prettier -l 'src/**/*'",
"eslint": "eslint --max-warnings 0 --ext .ts 'src/**/*'"
"eslint": "eslint --max-warnings 0 --ext .ts 'src/**/*'",
"dev:schedule": "ts-node scripts/schedule.ts"
},
"keywords": [
"serverless",
Expand Down Expand Up @@ -44,6 +45,7 @@
"pretty-quick": "^1.11.1",
"sinon": "^7.4.1",
"ts-jest": "^24.0.2",
"ts-node": "^8.3.0",
"typescript": "^3.5.3"
},
"husky": {
Expand Down
21 changes: 21 additions & 0 deletions scripts/schedule.ts
@@ -0,0 +1,21 @@
import OfflineScheduler from '../src/scheduler';

const offlineScheduler = new OfflineScheduler({
functionProvider: () => ({
'schedule-function': {
handler: 'src/functions/schedule-function.handler',
events: [
{
schedule: {
name: '1-minute',
rate: 'rate(1 minute)',
input: { scheduler: '1-minute' },
},
},
],
name: 'my-service-dev-schedule-function',
},
}),
});

offlineScheduler.scheduleEventsStandalone();
10 changes: 5 additions & 5 deletions src/scheduler.ts
Expand Up @@ -41,12 +41,12 @@ class OfflineScheduler {
this.log(`Scheduling [${functionName}] cron: [${cron}] input: ${JSON.stringify(input)}`);

schedule.scheduleJob(cron, () => {
const func = slsInvokeFunction(functionName, input);
if (func === undefined) {
this.log(`Unable to find source for function [${functionName}]`);
return;
try {
slsInvokeFunction(functionName, input);
this.log(`Succesfully invoked scheduled function: [${functionName}]`);
} catch (err) {
this.log(`Failed to execute scheduled function: [${functionName}] Error: ${err}`);
}
this.log(`Succesfully invoked scheduled function: [${functionName}]`);
});
});
};
Expand Down
2 changes: 1 addition & 1 deletion tsconfig.build.json
@@ -1,4 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["**/*.spec.ts"]
"exclude": ["**/*.spec.ts", "scripts"]
}
3 changes: 2 additions & 1 deletion tsconfig.json
Expand Up @@ -4,7 +4,8 @@
"rootDir": ".",
"target": "es6",
"outDir": "dist",
"esModuleInterop": true
"esModuleInterop": true,
"typeRoots": ["./typings", "node_modules/@types"]
},
"exclude": ["node_modules"]
}
File renamed without changes.

0 comments on commit 6c3ba03

Please sign in to comment.