Skip to content

Commit

Permalink
chore: role and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
oott123 committed Oct 23, 2021
1 parent 4d10f9d commit ee084bd
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 11 deletions.
26 changes: 24 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ curl \

### OCR 识别文字(TBD)

如果启用 OCR 队列,识别和入库可以在不同的实例上完成。
如果启用 OCR 队列,那么你需要部署一个 RabbitMQ 实例,并配置第三方识别服务。识别流程如下:

```mermaid
sequenceDiagram
Expand All @@ -130,10 +130,32 @@ sequenceDiagram
Bot实例->>-MeiliSearch: 入库
```

图片下载和文本入库将在 Bot 实例上完成,OCR 实例仅需访问 OCR 服务即可。
识别和入库可以在不同的角色实例上完成:图 0 片下载和文本入库将在 Bot 实例上完成,OCR 实例仅需访问 OCR 服务即可。

这样的设计使得维护者可以设计离线式的集中识别(例如使用抢占式实例运行识别服务,队列清空后关机),降低识别成本。

如果你使用的是第三方云服务,可以直接关闭 OCR 队列,或是在同一个实例中开启 Bot 和 OCR 角色。

#### 识别服务

##### Google Cloud Visor

参考 [Google Cloud Visor 文本识别文档](https://cloud.google.com/vision/docs/ocr)[Google Cloud Visor 计费规则](https://cloud.google.com/vision/pricing)。配置如下:

```bash
OCR_DRIVER=google
OCR_ENDPOINT=eu-vision.googleapis.com # 或者 us-vision.googleapis.com ,决定 Google 在何处存储处理数据
GOOGLE_APPLICATION_CREDENTIALS=/path/to/google/credentials.json # 从 GCP 后台下载的 json 鉴权文件
```

#### 启动不同角色

```bash
docker run [...] dist/main ocr,bot
# or
node dist/main ocr,bot
```

## 开发

```bash
Expand Down
25 changes: 16 additions & 9 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ process.on('unhandledRejection', (reason) => {
async function bootstrap() {
debug('bootstrapping app')

const [role] = process.argv.slice(2)
const roles = role ? role.split(',') : ['bot', 'ocr']

debug('creating app')
const app = await NestFactory.create<NestFastifyApplication>(
AppModule,
Expand All @@ -39,20 +42,24 @@ async function bootstrap() {
const httpCfg = app.get<ConfigType<typeof httpConfig>>(httpConfig.KEY)
app.setGlobalPrefix(httpCfg.globalPrefix)

debug('creating bot')
const bot = app.get(BotService)
await bot.start()
if (roles.includes('bot')) {
debug('creating bot')
const bot = app.get(BotService)
await bot.start()

debug('migrating search')
const search = app.get(MeiliSearchService)
await search.migrate()
await search.recoverFromCache()
debug('migrating search')
const search = app.get(MeiliSearchService)
await search.migrate()
await search.recoverFromCache()
}

debug('enable shutdown hooks')
app.enableShutdownHooks()

debug('starting http')
await app.listen(httpCfg.port, httpCfg.host)
if (roles.includes('bot')) {
debug('starting http')
await app.listen(httpCfg.port, httpCfg.host)
}
}

bootstrap().catch((err) => {
Expand Down

0 comments on commit ee084bd

Please sign in to comment.