Я пытаюсь выполнить задание cron по расписанию с помощью npm serverless-offline-scheduler. но почему-то я получаю сообщение об ошибке «путь», даже если для расписания есть вариант пути. вот мой файл serverless.local.yml:
functions:
assignTask:
handler: src/taskHandler.run
events:
- schedule:
enabled: true
rate: rate(1 minute)
students:
name: ${self:custom.project}-${self:custom.environment}-students
handler: src/handler.handler
events:
- http:
method: any
path: /students/
cors: true
- http:
path: "/students/{proxy+}"
method: any
cors: true
Из ошибки я заметил, что путь к файлу yml - это массив путей, а не просто строка. вы видите журнал консоли, который я напечатал ниже. Вот сообщение об ошибке:
Serverless: Offline [HTTP] listening on http://localhost:5002
[srv-file] Serverless: Enter "rp" to replay the last request
[srv-students] [ 'serverless.local.yml', 'serverless.local.yml' ] ----------
[srv-students]
[srv-students] Type Error ---------------------------------------------
[srv-students]
[srv-students] TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
[srv-students] at validateString (internal/validators.js:112:11)
[srv-students] at Object.join (path.js:1039:7)
[srv-students] at Utils.findServicePath (/Volumes/E/Students-NodeJS/services/students/node_modules/serverless/lib/classes/Utils.js:111:31)
[srv-students] at new Serverless (/Volumes/E/Students-NodeJS/services/students/node_modules/serverless/lib/Serverless.js:42:18)
[srv-students] at /Volumes/E/Students-NodeJS/services/students/node_modules/serverless/bin/serverless.js:76:24
[srv-students] at tryCatcher (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/util.js:16:23)
[srv-students] at Promise._settlePromiseFromHandler (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:547:31)
[srv-students] at Promise._settlePromise (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:604:18)
[srv-students] at Promise._settlePromise0 (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:649:10)
[srv-students] at Promise._settlePromises (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:729:18)
[srv-students] at Promise._fulfill (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:673:18)
[srv-students] at Promise._resolveCallback (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:489:14)
[srv-students] at Promise._settlePromiseFromHandler (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:559:17)
[srv-students] at Promise._settlePromise (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:604:18)
[srv-students] at Promise._settlePromise0 (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:649:10)
[srv-students] at Promise._settlePromises (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:729:18)
[srv-students] at Promise._fulfill (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:673:18)
[srv-students] at Promise._resolveCallback (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:489:14)
[srv-students] at Promise._settlePromiseFromHandler (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:559:17)
[srv-students] at Promise._settlePromise (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:604:18)
[srv-students] at Promise._settlePromise0 (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:649:10)
[srv-students] at Promise._settlePromises (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:729:18)
[srv-students] at Promise._fulfill (/Volumes/E/Students-NodeJS/services/students/node_modules/bluebird/js/release/promise.js:673:18)
[srv-students] Error --------------------------------------------------
[srv-students]
[srv-students] Error: Command failed: /Users/sr/.nvm/versions/node/v12.14.1/bin/node /Volumes/E/Students-NodeJS/services/students/node_modules/.bin/serverless invoke local --function assignTask --data {"account":"123456789012","region":"serverless-offline","detail":{},"detail-type":"Scheduled Event","source":"aws.events","time":"2020-05-06T00:10:35.467Z","id":"7377b012-268a-8bff-ee44-5b517f73704b","resources":["arn:aws:events:serverless-offline:123456789012:rule/assignTask"],"isOffline":true} --config serverless.local.yml --c serverless.local.yml
[srv-students] at checkExecSyncError (child_process.js:621:11)
[srv-students] at Object.execFileSync (child_process.js:639:15)
[srv-students] at Scheduler._executeFunction (/Volumes/E/Students-NodeJS/services/students/node_modules/serverless-offline-scheduler/lib/scheduler.js:93:25)
[srv-students] at Job.job (/Volumes/E/Students-NodeJS/services/students/node_modules/serverless-offline-scheduler/lib/scheduler.js:74:16)
[srv-students] at Job.invoke (/Volumes/E/Students-NodeJS/services/students/node_modules/node-schedule/lib/schedule.js:173:10)
[srv-students] at /Volumes/E/Students-NodeJS/services/students/node_modules/node-schedule/lib/schedule.js:552:11
[srv-students] at Timeout._onTimeout (/Volumes/E/Students-NodeJS/services/students/node_modules/node-schedule/lib/schedule.js:510:7)
[srv-students] at listOnTimeout (internal/timers.js:531:17)
[srv-students] at processTimers (internal/timers.js:475:7)
мои версии пакетов:
"@types/node": "^12.12.28",
"serverless": "^1.63.0",
"serverless-dotenv-plugin": "^2.3.2",
"serverless-offline": "^5.12.1",
"serverless-offline-scheduler": "^0.4.2",
"serverless-webpack": "^5.3.1",