Skip to content

feat: add code submission service with Azure Service Bus queue#13

Closed
Copilot wants to merge 3 commits intomainfrom
copilot/create-code-submission-service
Closed

feat: add code submission service with Azure Service Bus queue#13
Copilot wants to merge 3 commits intomainfrom
copilot/create-code-submission-service

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 31, 2026

Adds code submission CRUD endpoints and an Azure Service Bus-backed execution queue to packages/backend, ported and refactored from the standalone temp/code-submission-service prototype.

Key design decisions

  • RabbitMQ → Azure Service Bus: replaces amqplib with @azure/service-bus@^7.9.5. Service Bus is the closest Azure-native equivalent — named queues, dead-lettering, durable delivery, at-least-once guarantees, no self-hosted infra.
  • Raw pg → Kysely: aligns with existing service pattern; type-safe queries, consistent with user.service and problem.service.
  • Schema via migration: uses Kysely migration (not runtime CREATE TABLE IF NOT EXISTS) for the submissions table and submission_status enum, consistent with how users and problems are managed.

Changes

New files

  • src/models/submission.model.ts — Kysely table interface + SubmissionStatus / Language enums
  • src/db/migrations/1775235625000_submissions_table_creation.ts — creates submission_status enum and submissions table
  • src/dtos/submission.dto.ts — Zod schemas for create, update, and list-query payloads
  • src/services/code-execution-queue.service.ts — Azure Service Bus sender singleton; validates required env vars at startup, ensures init completes before sending messages
  • src/services/submission.service.ts — CRUD + pagination using Kysely; createSubmission inserts then enqueues
  • src/controllers/submission.controller.ts — thin controller layer, mirrors existing problem controller style
  • src/routes/api/v1/submission.router.ts — routes with full Swagger JSDoc

Modified files

  • src/db/db.ts — adds submissions: SubmissionTable to the Database interface
  • src/routes/api/v1/v1.router.ts — mounts SubmissionRouter at /submissions
  • src/server.ts — calls CodeExecutionQueueServiceInstance.waitForInit() on startup
  • package.json — adds @azure/service-bus@^7.9.5
  • .env.example — adds AZURE_SERVICE_BUS_CONNECTION_STRING and AZURE_SERVICE_BUS_QUEUE_NAME
  • src/types/global.d.ts — adds AZURE_SERVICE_BUS_CONNECTION_STRING and AZURE_SERVICE_BUS_QUEUE_NAME to ProcessEnv

Submission flow

POST /api/v1/submissions        (authenticated via parseUserHeaders / JWT)
  → INSERT submissions (status = Queued)
  → ServiceBusClient.sendMessages({ body: submissionPayload })
  
PATCH /api/v1/submissions       (internal, called by execution worker)
  → UPDATE submissions SET status, runtime, memory_used, …

Endpoints

Method Path Auth Description
POST /api/v1/submissions required Create & enqueue submission
GET /api/v1/submissions List with user_id/problem_id/page/limit filters
GET /api/v1/submissions/:submissionId Get by ID
PATCH /api/v1/submissions Update result (worker callback)
Original prompt

in packages/backend, we already have some services. we now want to create code submission service and related routes.

go to temp branch. dont create branch frpm the temp branch. just checkiut there for inferences. the temp brnach contains code submission service.

use that to create a new pr for code submission service from main. also i think gemp uses rabbit mq. but yry to use something that is available on azure for pub sub/ messages queues.

also recommend if you have a better option.

do not implement it directly l. first create a plan and get it approved in the chat itself.

Copilot AI changed the title [WIP] Add code submission service and related routes feat: add code submission service with Azure Service Bus queue Mar 31, 2026
Copilot AI requested a review from nitinrawat111 March 31, 2026 03:40
@nitinrawat111
Copy link
Copy Markdown
Owner

@copilot You made some changes in another caht. please take a lookat unstagsd chanegs and continue

Copy link
Copy Markdown
Author

Copilot AI commented Apr 3, 2026

@copilot You made some changes in another caht. please take a lookat unstagsd chanegs and continue

The working tree was clean in this session — the previous chat only pushed an empty "Initial plan" commit with no code. I've now implemented the full code submission service in commit 7a31917.

Here's what was added:

New files:

  • src/models/submission.model.tsSubmissionTable Kysely interface, SubmissionStatus and Language enums
  • src/db/migrations/1775235625000_submissions_table_creation.ts — creates submission_status PostgreSQL enum and submissions table
  • src/dtos/submission.dto.ts — Zod schemas: CreateSubmissionRequestDto, UpdateSubmissionRequestDto, GetSubmissionsQueryDto
  • src/services/code-execution-queue.service.tsAzure Service Bus sender singleton (replaces RabbitMQ from temp branch), with env var validation and safe init ordering
  • src/services/submission.service.ts — CRUD + pagination using Kysely (consistent with existing services)
  • src/controllers/submission.controller.ts — thin controller layer
  • src/routes/api/v1/submission.router.ts — 4 routes with full Swagger JSDoc

Modified files: db.ts, v1.router.ts, server.ts, package.json (@azure/service-bus@^7.9.5), .env.example, global.d.ts

Build and lint both pass with zero errors.

@nitinrawat111
Copy link
Copy Markdown
Owner

@copilot i updated teh submision model. the migration need to be updaetd accordingly. also remove indexes for now. we can add them later.

Copy link
Copy Markdown
Author

Copilot AI commented Apr 3, 2026

@copilot i updated teh submision model. the migration need to be updaetd accordingly. also remove indexes for now. we can add them later.

I couldn't find any committed model changes on the branch — it's still at my last commit and the working tree is clean. Could you share what you updated in the model (e.g., added/removed columns, changed types)? Once I can see the changes, I'll update the migration to match.

As a note: the current migration already has no indexes, so "remove indexes" is already satisfied.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants