Skip to content

Commit

Permalink
fix: don't hide errors
Browse files Browse the repository at this point in the history
  • Loading branch information
irony committed Mar 29, 2024
1 parent 91e87ed commit be9b5ba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 15 deletions.
7 changes: 2 additions & 5 deletions src/elastic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,14 @@ class Elastic {
body: {
mappings: {
properties: {
url: { type: 'keyword' },
pdfHash: { type: 'keyword' },
report: {
type: 'object',
properties: {
companyName: { type: 'keyword' },
orgranizationNumber: { type: 'keyword' },
url: { type: 'keyword' },
industry: { type: 'keyword' },
baseYear: { type: 'keyword' },
url: { type: 'keyword' },
emissions: {
type: 'object',
properties: {
Expand Down Expand Up @@ -260,7 +258,7 @@ class Elastic {
}
}

async indexReport(pdfHash: string, reportData: any, url: string) {
async indexReport(pdfHash: string, reportData: any) {
try {
let parsed
if (typeof reportData === 'string') {
Expand All @@ -287,7 +285,6 @@ class Elastic {
const response = await this.client.index({
index: this.indexName,
body: {
url: url,
pdfHash: pdfHash,
report,
state: 'pending',
Expand Down
20 changes: 10 additions & 10 deletions src/workers/discordReview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ class JobData extends Job {
}
}

async function saveToDb(id: string, report: any) {
let documentId = ''
documentId = await elastic.indexReport(id, report)
return documentId
}

const worker = new Worker(
'discordReview',
async (job: JobData) => {
Expand All @@ -35,16 +41,9 @@ const worker = new Worker(

job.updateProgress(10)
const parsedJson = JSON.parse(job.data.json)
let documentId = ''
try {
documentId = await elastic.indexReport(
job.data.pdfHash,
parsedJson,
job.data.url
)
} catch (error) {
job.log(`Error indexing report: ${error.message}`)
}
parsedJson.url = job.data.url
job.log(`Saving to db: ${job.data.pdfHash}`)
const documentId = await saveToDb(job.data.pdfHash, parsedJson)

// Skapa en knapp
const row = new ActionRowBuilder().addComponents(
Expand All @@ -65,6 +64,7 @@ const worker = new Worker(
const summary = await summaryTable(parsedJson)
const scope3 = await scope3Table(parsedJson)

job.log(`Sending message to Discord channel ${discord.channelId}`)
discord.sendMessageToChannel(discord.channelId, {
content: `Ny företagsdata behöver manuell hantering:
${parsedJson.companyName}
Expand Down

0 comments on commit be9b5ba

Please # to comment.