Express 正在计划localhost无服务器cron:无法在注册表中解析模型
我正在AWS Lambda上使用无服务器框架托管一个ExpressJS/NodeJS API。API使用Knex.js和Bookshelf.js ORM 我想测试在本地调度cron作业。我正在使用Express 正在计划localhost无服务器cron:无法在注册表中解析模型,express,aws-lambda,serverless-framework,knex.js,bookshelf.js,Express,Aws Lambda,Serverless Framework,Knex.js,Bookshelf.js,我正在AWS Lambda上使用无服务器框架托管一个ExpressJS/NodeJS API。API使用Knex.js和Bookshelf.js ORM 我想测试在本地调度cron作业。我正在使用无服务器脱机计划程序来执行此操作 问题:如果我从客户端调用API,它运行良好,但是如果我通过无服务器调度器调用函数,它会抱怨注册表中没有模型。为什么会这样?我已经明确地在OrderService.js文件的顶部包含了所有必要的模型 { "errorMessage": &quo
无服务器脱机计划程序来执行此操作
问题:如果我从客户端调用API,它运行良好,但是如果我通过无服务器调度器调用函数,它会抱怨注册表中没有模型。为什么会这样?我已经明确地在OrderService.js文件的顶部包含了所有必要的模型
{
"errorMessage": "The model User could not be resolved from the registry plugin.",
"errorType": "Error",
"stackTrace": [
"Error: The model User could not be resolved from the registry plugin.",
" at new ModelNotResolved (/Users/danielturcotte/Sites/d2c/api_v4/node_modules/bookshelf/lib/plugins/registry.js:70:133)",
Serverless.yml:
functions:
app:
handler: handler.handler
events: ...
dequeue:
handler: ./services/OrderService.dequeue // Call dequeue function
events:
- schedule: rate(1 minute)
处理程序调用root/services/OrderService.dequeue
函数,该函数包含
...
const dequeue = async function() {
await checkQueuedOrders();
};
module.exports = {
dequeue,
};
在我的knexService.js
文件中,我将书架模型注册到注册表以删除循环依赖项:
const knexfile = require('./knexfile');
const config = require('./environment');
const environment = config.env.NODE_ENV || 'development';
const knex = require('knex')(knexfile[environment]);
knex.client.pool.numPendingCreates();
const bookshelf = require('bookshelf')(knex);
bookshelf.plugin('registry'); // Resolve circular dependencies with relations
bookshelf.plugin('visibility');
bookshelf.plugin('pagination');
module.exports.knex = knex;
module.exports.bookshelf = bookshelf;
您是如何使用和定义这些模型的?您是如何使用和定义这些模型的?