Skip to content

Commit

Permalink
Enable connection and add console.logs to debug websockets in workers (
Browse files Browse the repository at this point in the history
  • Loading branch information
andresgutgon authored Sep 19, 2024
1 parent df38a01 commit df7651d
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions apps/infra/src/deployments/gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const taskDefinition = pulumi
networkMode: 'awsvpc',
requiresCompatibilities: ['FARGATE'],
executionRoleArn: ecsTaskExecutionRole,
taskRoleArn: ecsTaskExecutionRole,
containerDefinitions: JSON.stringify([
{
name: containerName,
Expand Down Expand Up @@ -128,6 +129,7 @@ new aws.ecs.Service('LatitudeLLMGateway', {
desiredCount: 2,
launchType: 'FARGATE',
forceNewDeployment: true,
enableExecuteCommand: true,
networkConfiguration: {
subnets: privateSubnets.ids,
assignPublicIp: false,
Expand Down
2 changes: 2 additions & 0 deletions apps/infra/src/deployments/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ const taskDefinition = pulumi
networkMode: 'awsvpc',
requiresCompatibilities: ['FARGATE'],
executionRoleArn: ecsTaskExecutionRole,
taskRoleArn: ecsTaskExecutionRole,
containerDefinitions: JSON.stringify([
{
name: containerName,
Expand Down Expand Up @@ -175,6 +176,7 @@ new aws.ecs.Service('LatitudeLLMApp', {
desiredCount: 2,
launchType: 'FARGATE',
forceNewDeployment: true,
enableExecuteCommand: true,
networkConfiguration: {
subnets: privateSubnets.ids,
assignPublicIp: false,
Expand Down
2 changes: 2 additions & 0 deletions apps/infra/src/deployments/websockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ const taskDefinition = pulumi
networkMode: 'awsvpc',
requiresCompatibilities: ['FARGATE'],
executionRoleArn: ecsTaskExecutionRole,
taskRoleArn: ecsTaskExecutionRole,
containerDefinitions: JSON.stringify([
{
name: containerName,
Expand Down Expand Up @@ -128,6 +129,7 @@ new aws.ecs.Service('LatitudeLLMWebsockets', {
desiredCount: 1,
launchType: 'FARGATE',
forceNewDeployment: true,
enableExecuteCommand: true,
networkConfiguration: {
subnets: privateSubnets.ids,
assignPublicIp: false,
Expand Down
4 changes: 4 additions & 0 deletions apps/websockets/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ workers.use(async (socket, next) => {
workers.on('connection', (socket) => {
console.log('DEBUG: Worker connected')

socket.on('pingFromWorkers', () => {
console.log('DEBUG: Ping from workers')
})

socket.on('evaluationStatus', (args) => {
console.log('DEBUG: Evaluation STATUS %s', JSON.stringify(args))
const { workspaceId, data } = args
Expand Down
11 changes: 9 additions & 2 deletions apps/workers/src/server.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import http from 'http'

import { WebsocketClient } from '@latitude-data/core/websockets/workers'

import { captureException, captureMessage } from './utils/sentry'
import startWorkers from './workers'

Expand All @@ -8,8 +10,13 @@ const workers = startWorkers()
console.log('Workers started')

const port = process.env.WORKERS_PORT || 3002
const server = http.createServer((req, res) => {
if (req.url === '/health' && req.method === 'GET') {
const server = http.createServer(async (req, res) => {
const websockets = await WebsocketClient.getSocket()

if (req.url === '/ping' && req.method === 'GET') {
websockets.emit('pingFromWorkers')
res.end(JSON.stringify({ status: 'OK', message: 'Pong' }))
} else if (req.url === '/health' && req.method === 'GET') {
res.writeHead(200, { 'Content-Type': 'application/json' })
res.end(JSON.stringify({ status: 'OK', message: 'Workers are healthy' }))
} else {
Expand Down
1 change: 1 addition & 0 deletions packages/core/src/websockets/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,5 @@ export type WorkersClientToServerEvents = {
data: EvaluationStatusArgs
workspaceId: number
}) => void
pingFromWorkers: () => void
}

0 comments on commit df7651d

Please sign in to comment.