Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: Fix database not connect #395

Merged
merged 2 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions packages/mina-service/src/service/task-service.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { logger } from '@helper';
import { config, logger } from '@helper';
import { Proof } from '@domain';
import { withCompoundTransaction } from '@zkdb/storage';
import { DatabaseEngine, withCompoundTransaction } from '@zkdb/storage';

export class TaskService {
private maxRetries: number;
Expand Down Expand Up @@ -58,5 +58,21 @@ export class TaskService {

export const TASK_SERVICE = {
clusterName: 'task',
payload: new TaskService().run,
payload: async () => {
// Connect to db
const serverlessDb = DatabaseEngine.getInstance(config.MONGODB_URL);
const proofDb = DatabaseEngine.getInstance(config.PROOF_MONGODB_URL);

if (!serverlessDb.isConnected()) {
await serverlessDb.connect();
}

if (!proofDb.isConnected()) {
await proofDb.connect();
}

const taskService = new TaskService();

await taskService.run();
},
};
16 changes: 14 additions & 2 deletions packages/mina-service/src/service/transaction-service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { logger } from '@helper';
import { config, logger } from '@helper';
import { Fill } from '@orochi-network/queue';
import { ETransactionStatus } from '@zkdb/common';
import { MinaNetwork } from '@zkdb/smart-contract';
import { ModelTransaction } from '@zkdb/storage';
import { DatabaseEngine, ModelTransaction } from '@zkdb/storage';
import { schedule } from 'node-cron';

// Base on Mina protocol blockscan we divide to 10
Expand All @@ -13,6 +13,18 @@ export const SERVICE_TRANSACTION = {
payload: async () => {
let isRunning = false;

// Connect to db
const serverlessDb = DatabaseEngine.getInstance(config.MONGODB_URL);
const proofDb = DatabaseEngine.getInstance(config.PROOF_MONGODB_URL);

if (!serverlessDb.isConnected()) {
await serverlessDb.connect();
}

if (!proofDb.isConnected()) {
await proofDb.connect();
}

schedule(CRON_SCHEDULE, async () => {
if (isRunning) {
logger.debug('Task skipped to prevent overlap:', new Date());
Expand Down