serverless-offline-scheduler
Advanced tools
Comparing version 0.1.4 to 0.1.5
@@ -22,3 +22,3 @@ 'use strict'; | ||
'schedule:run': () => this.scheduler.run(), | ||
'offline:start:init': () => this.scheduler.run() | ||
'after:offline:start:init': () => this.scheduler.run() | ||
}; | ||
@@ -25,0 +25,0 @@ } |
@@ -9,13 +9,14 @@ 'use strict'; | ||
const pathBases = [ | ||
'', | ||
'.webpack' | ||
]; | ||
class Scheduler { | ||
constructor(serverless) { | ||
this.serverless = serverless; | ||
this.location = ''; | ||
} | ||
run() { | ||
const offlinePlugin = this.serverless.pluginManager.getPlugins() | ||
.find(p => p.constructor && p.constructor.name === 'Offline') | ||
if (offlinePlugin) { | ||
this.location = offlinePlugin.options.location; | ||
} | ||
this.funcConfigs = this._getFuncConfigs(); | ||
@@ -26,11 +27,12 @@ for(const i in this.funcConfigs) { | ||
const scheduleEvent = fConfig.events[j]; | ||
const func = this._requireFunction(fConfig.id); | ||
if (!func) { | ||
continue; | ||
} | ||
this._setEnvironmentVars(fConfig.id); //TODO: Set this individually for each schedule | ||
this.serverless.cli.log(`scheduling ${fConfig.id} with ${scheduleEvent}`); | ||
this.serverless.cli.log(`scheduler: scheduling ${fConfig.id} with ${scheduleEvent}`); | ||
schedule.scheduleJob(scheduleEvent, () => { | ||
this.serverless.cli.log(`Running scheduled job: ${fConfig.id}`) | ||
const func = this._requireFunction(fConfig.id); | ||
if (!func) { | ||
this.serverless.cli.log(`scheduler: unable to find source for ${fName}`); | ||
return; | ||
} | ||
this.serverless.cli.log(`scheduler: running scheduled job: ${fConfig.id}`) | ||
func( | ||
@@ -52,9 +54,6 @@ this._getEvent(), | ||
const handlerFunction = handlerParts[1]; | ||
for (const base of pathBases) { | ||
const funcPath = path.join(this.serverless.config.servicePath, base, filename); | ||
if (fs.existsSync(funcPath)) { | ||
return require(funcPath)[handlerFunction]; | ||
} | ||
const funcPath = path.join(this.serverless.config.servicePath, this.location, filename); | ||
if (fs.existsSync(funcPath)) { | ||
return require(funcPath)[handlerFunction]; | ||
} | ||
this.serverless.cli.log(`Unable to find source for ${fName}:${filename}`); | ||
return null; | ||
@@ -100,7 +99,7 @@ } | ||
if (scheduleEvent.startsWith('rate(')) { | ||
this.serverless.cli.log('Rate syntax not currently supported, will not schedule') | ||
this.serverless.cli.log('scheduler: rate syntax not currently supported, will not schedule') | ||
return null; | ||
} | ||
this.serverless.cli.log('Invalid, schedule syntax'); | ||
this.serverless.cli.log('scheduler: invalid, schedule syntax'); | ||
return null; | ||
@@ -107,0 +106,0 @@ } |
{ | ||
"name": "serverless-offline-scheduler", | ||
"version": "0.1.4", | ||
"version": "0.1.5", | ||
"description": "Serverless plugin to run scheduled lambdas with serverless offline", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
113432