@1mill/journal 中文文档教程
@1mill/journal
Context
Install
npm install @1mill/journal
// * index.js
const { Journal } = require('@1mill/journal')
const journal = new Journal({
name: 'my-journal-db' || process.env.MILL_JOURNAL_NAME,
table: 'my-collection' || process.env.MILL_JOURNAL_TABLE,
uri: 'mongodb://...:27017' || process.env.MILL_JOURNAL_URI,
})
export.handler = async (cloudevent, ctx) => {
// * https://www.jeremydaly.com/reuse-database-connections-aws-lambda/
ctx.callbackWaitsForEmptyEventLoop = false
try {
const { skip } = await journal.entry({ cloudevent })
if (skip) return // * Already being performed by another lambda
// * Perform business logic
// ...
} catch (err) {
console.error(err)
// * Erase entry on business logic failure (e.g. fetch to
// * third-party API failed)
await journal.erase({ cloudevent })
throw new Error(err) // * Requeue event to run again
}
}
@1mill/journal
Context
Install
npm install @1mill/journal
// * index.js
const { Journal } = require('@1mill/journal')
const journal = new Journal({
name: 'my-journal-db' || process.env.MILL_JOURNAL_NAME,
table: 'my-collection' || process.env.MILL_JOURNAL_TABLE,
uri: 'mongodb://...:27017' || process.env.MILL_JOURNAL_URI,
})
export.handler = async (cloudevent, ctx) => {
// * https://www.jeremydaly.com/reuse-database-connections-aws-lambda/
ctx.callbackWaitsForEmptyEventLoop = false
try {
const { skip } = await journal.entry({ cloudevent })
if (skip) return // * Already being performed by another lambda
// * Perform business logic
// ...
} catch (err) {
console.error(err)
// * Erase entry on business logic failure (e.g. fetch to
// * third-party API failed)
await journal.erase({ cloudevent })
throw new Error(err) // * Requeue event to run again
}
}
更多
你可能也喜欢
- 18plus-imager 中文文档教程
- 3rdweb-contracts 中文文档教程
- 7s-aura-lwc-eslint-parser 中文文档教程
- @0xproject/order-watcher 中文文档教程
- @0yi0/remix-debug 中文文档教程
- @11ty/eleventy-plugin-rss 中文文档教程
- @1stquad/react-bootstrap-datetimepicker 中文文档教程
- @3asoft/web-crypto-js 中文文档教程
- @44north/unitconverter 中文文档教程
- @4geit/rct-notification-component 中文文档教程