Skip to content

Commit

Permalink
Merge pull request #53 from Klimatbyran/feat/redisInsteadOfElasticsearch
Browse files Browse the repository at this point in the history
feat: use redis instead of elastic for noew
  • Loading branch information
schweinryder authored Mar 21, 2024
2 parents 85e7df5 + 0c1b9a5 commit 8c27e13
Show file tree
Hide file tree
Showing 9 changed files with 224 additions and 233 deletions.
10 changes: 0 additions & 10 deletions k8s/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,6 @@ spec:
secretKeyRef:
name: env
key: OPENAI_ORG_ID
- name: ELASTIC_NODE_URL
valueFrom:
secretKeyRef:
name: env
key: ELASTIC_NODE_URL
- name: ELASTIC_INDEX_NAME
valueFrom:
secretKeyRef:
name: env
key: ELASTIC_INDEX_NAME
# - name: CHROMA_TOKEN
# valueFrom:
# secretKeyRef:
Expand Down
133 changes: 133 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"dependencies": {
"@bull-board/api": "^5.12.0",
"@bull-board/express": "^5.12.0",
"@elastic/elasticsearch": "^8.12.1",
"@google/generative-ai": "^0.1.3",
"@hugocxl/react-to-image": "^0.0.9",
"bullmq": "^5.1.1",
Expand All @@ -25,6 +24,7 @@
"node-html-to-image": "^4.0.0",
"openai": "^4.24.3",
"pdf-parse": "^1.1.1",
"redis": "^4.6.13",
"typescript": "^5.3.3"
},
"devDependencies": {
Expand Down
4 changes: 0 additions & 4 deletions src/config/elasticsearch.ts

This file was deleted.

58 changes: 58 additions & 0 deletions src/db.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import config from './config/redis'
import { createClient } from 'redis'
import * as crypto from 'crypto'

class Db {
client: any

constructor(config: any) {
try {
this.client = createClient(config)
} catch (error) {
console.error('Redis constructor error:', error)
}
}

public hashPdf(pdfBuffer: Buffer): string {
return crypto.createHash('sha256').update(pdfBuffer).digest('hex')
}

async indexReport(pdfHash: string, reportData: string, url: string) {
try {
const response = await this.client.set(
pdfHash,
JSON.stringify({
url: url,
pdfHash: pdfHash,
report: reportData,
state: 'pending',
timestamp: new Date(),
})
)
console.log(`Report data added. Document ID: ${pdfHash}`)
return pdfHash
} catch (error) {
console.error(`Error adding report data:`, error)
}
}

async updateDocumentState(documentId: string, newState: string) {
try {
const existing = await this.client.get(documentId)
if (!existing) {
console.error(`Document ID ${documentId} not found.`)
return
}
existing.state = newState
await this.client.set(documentId, JSON.stringify(existing))
console.log(`Document ${documentId} state updated to ${newState}.`)
} catch (error) {
console.error(
`Error updating document state for Document ID ${documentId}:`,
error
)
}
}
}

export default new Db(config)
Loading

0 comments on commit 8c27e13

Please sign in to comment.