-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #89 from MinaFoundation/feature/ocv-vote-async-worker
Feature/ocv vote async worker
- Loading branch information
Showing
12 changed files
with
1,578 additions
and
836 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
prisma/migrations/20241213201554_add_ocv_votes/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
-- CreateEnum | ||
CREATE TYPE "WorkerStatus" AS ENUM ('RUNNING', 'COMPLETED', 'FAILED', 'NOT_STARTED'); | ||
|
||
-- AlterTable | ||
ALTER TABLE "User" ADD COLUMN "oCVConsiderationVoteId" INTEGER; | ||
|
||
-- CreateTable | ||
CREATE TABLE "OCVConsiderationVote" ( | ||
"id" SERIAL NOT NULL, | ||
"proposalId" INTEGER NOT NULL, | ||
"voteData" JSONB NOT NULL, | ||
"updatedAt" TIMESTAMP(3) NOT NULL, | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "OCVConsiderationVote_pkey" PRIMARY KEY ("id") | ||
); | ||
|
||
-- CreateTable | ||
CREATE TABLE "WorkerHeartbeat" ( | ||
"jobId" TEXT NOT NULL, | ||
"lastHeartbeat" TIMESTAMP(3) NOT NULL, | ||
"status" "WorkerStatus" NOT NULL DEFAULT 'RUNNING', | ||
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, | ||
|
||
CONSTRAINT "WorkerHeartbeat_pkey" PRIMARY KEY ("jobId") | ||
); | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "OCVConsiderationVote_proposalId_key" ON "OCVConsiderationVote"("proposalId"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "OCVConsiderationVote_proposalId_idx" ON "OCVConsiderationVote"("proposalId"); | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "User" ADD CONSTRAINT "User_oCVConsiderationVoteId_fkey" FOREIGN KEY ("oCVConsiderationVoteId") REFERENCES "OCVConsiderationVote"("id") ON DELETE SET NULL ON UPDATE CASCADE; | ||
|
||
-- AddForeignKey | ||
ALTER TABLE "OCVConsiderationVote" ADD CONSTRAINT "OCVConsiderationVote_proposalId_fkey" FOREIGN KEY ("proposalId") REFERENCES "Proposal"("id") ON DELETE RESTRICT ON UPDATE CASCADE; |
18 changes: 18 additions & 0 deletions
18
prisma/migrations/20241219115548_heartbeat_name_label/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/* | ||
Warnings: | ||
- The primary key for the `WorkerHeartbeat` table will be changed. If it partially fails, the table could be left without primary key constraint. | ||
- You are about to drop the column `jobId` on the `WorkerHeartbeat` table. All the data in the column will be lost. | ||
- The required column `id` was added to the `WorkerHeartbeat` table with a prisma-level default value. This is not possible if the table is not empty. Please add this column as optional, then populate it before making it required. | ||
- Added the required column `name` to the `WorkerHeartbeat` table without a default value. This is not possible if the table is not empty. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "WorkerHeartbeat" DROP CONSTRAINT "WorkerHeartbeat_pkey", | ||
DROP COLUMN "jobId", | ||
ADD COLUMN "id" UUID NOT NULL, | ||
ADD COLUMN "name" VARCHAR(100) NOT NULL, | ||
ADD CONSTRAINT "WorkerHeartbeat_pkey" PRIMARY KEY ("id"); | ||
|
||
-- CreateIndex | ||
CREATE INDEX "WorkerHeartbeat_name_status_idx" ON "WorkerHeartbeat"("name", "status"); |
2 changes: 2 additions & 0 deletions
2
prisma/migrations/20241219120409_add_worker_heartbeat_metadata/migration.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
-- AlterTable | ||
ALTER TABLE "WorkerHeartbeat" ADD COLUMN "metadata" JSONB; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import Bree from 'bree'; | ||
import Graceful from '@ladjs/graceful'; | ||
import logger from '@/logging'; | ||
import path from 'path'; | ||
|
||
const bree = new Bree({ | ||
root: path.join(process.cwd(), 'dist', 'tasks'), | ||
jobs: [ | ||
{ | ||
name: 'ocv-vote-counting', | ||
path: path.join(process.cwd(), 'dist', 'tasks', 'ocv-vote-counting.js'), | ||
interval: '10m', // run every 10 minutes | ||
timeout: 0, // start immediatly when this script is run | ||
closeWorkerAfterMs: 9 * 60 * 1000 // Kill after 9 minutes if stuck | ||
} | ||
], | ||
errorHandler: (error, workerMetadata) => { | ||
logger.error(`[Bree Runner] Worker ${workerMetadata.name} encountered an error:`, error); | ||
}, | ||
workerMessageHandler: (name, message) => { | ||
logger.error(`[Bree Runner] Message from worker ${name}`); | ||
} | ||
}); | ||
|
||
const graceful = new Graceful({ brees: [bree] }); | ||
graceful.listen(); | ||
|
||
(async () => { | ||
await bree.start(); | ||
logger.info('Bree started successfully'); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.