Skip to content

Commit

Permalink
feat: wip
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon committed Sep 20, 2024
1 parent 762ee56 commit b8145b4
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
14 changes: 13 additions & 1 deletion packages/core/src/events/handlers/createEvaluationResultJob.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@ import {
import { NotFoundError } from '../../lib'
import { createEvaluationResult } from '../../services/evaluationResults'
import { createEvaluationResultQuery } from '../../services/evaluationResults/_createEvaluationResultQuery'
import { WebsocketClient } from '../../websockets/workers'

export const createEvaluationResultJob = async ({
data: event,
}: {
data: EvaluationRunEvent
}) => {
const websockets = await WebsocketClient.getSocket()
const { evaluationId, documentLogUuid, providerLogUuid, response } =
event.data

Expand Down Expand Up @@ -46,5 +48,15 @@ export const createEvaluationResultJob = async ({
.limit(1)

const evaluationResultWithMetadata = result[0]!
return evaluationResultWithMetadata

websockets.emit('evaluationResultCreated', {
workspaceId: evaluation.workspaceId,
data: {
documentUuid: event.data.documentUuid,
workspaceId: evaluation.workspaceId,
evaluationId: evaluation.id,
evaluationResultId: evaluationResult.id,
row: evaluationResultWithMetadata,
},
})
}
1 change: 1 addition & 0 deletions packages/core/src/events/handlers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export type MembershipCreatedEvent = LatitudeEventGeneric<
export type EvaluationRunEvent = LatitudeEventGeneric<
'evaluationRun',
{
documentUuid: string
evaluationId: number
documentLogUuid: string
providerLogUuid: string
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/services/evaluations/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,11 @@ const getResultSchema = (type: EvaluationResultableType): JSONSchema7 => {
export const runEvaluation = async (
{
documentLog,
documentUuid,
evaluation,
}: {
documentLog: DocumentLog
documentUuid: string
evaluation: EvaluationDto
},
db = database,
Expand Down Expand Up @@ -105,12 +107,14 @@ export const runEvaluation = async (
output: 'object',
},
})

if (chainResult.error) return chainResult

chainResult.value.response.then((response) => {
publisher.publish({
type: 'evaluationRun',
data: {
documentUuid,
evaluationId: evaluation.id,
documentLogUuid: documentLog.uuid,
providerLogUuid: response.providerLog.uuid,
Expand Down
16 changes: 16 additions & 0 deletions packages/core/src/websockets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
// All this can be seen in the browser. If you want something private
// put in other place.

import { type EvaluationResultWithMetadata } from '../repositories'

const ONE_HOUR = 60 * 60 * 1000
const SEVEN_DAYS = 7 * 24 * ONE_HOUR

Expand Down Expand Up @@ -35,8 +37,18 @@ type EvaluationStatusArgs = {
errors: number
enqueued: number
}

type evaluationResultCreatedArgs = {
workspaceId: number
evaluationId: number
documentUuid: string
evaluationResultId: number
row: EvaluationResultWithMetadata
}

export type WebServerToClientEvents = {
evaluationStatus: (args: EvaluationStatusArgs) => void
evaluationResultCreated: (args: evaluationResultCreatedArgs) => void
joinWorkspace: (args: { workspaceId: number; userId: string }) => void
}
export type WebClientToServerEvents = {
Expand All @@ -45,7 +57,11 @@ export type WebClientToServerEvents = {

export type WorkersClientToServerEvents = {
evaluationStatus: (args: {
workspaceId: number
data: EvaluationStatusArgs
}) => void
evaluationResultCreated: (args: {
workspaceId: number
data: evaluationResultCreatedArgs
}) => void
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const runEvaluationJob = async (job: Job<RunEvaluationJobData>) => {
await runEvaluation({
documentLog,
evaluation,
documentUuid
}).then((r) => r.unwrap())

await progressTracker.incrementCompleted()
Expand Down

0 comments on commit b8145b4

Please sign in to comment.