Browse Source

query node - members and workers bootstrapping II

ondratra 3 years ago
parent
commit
db11675567
2 changed files with 12 additions and 7 deletions
  1. 9 4
      query-node/mappings/bootstrap/index.ts
  2. 3 3
      query-node/mappings/bootstrap/workers.ts

+ 9 - 4
query-node/mappings/bootstrap/index.ts

@@ -9,18 +9,24 @@ import { FindConditions } from 'typeorm'
 import fs from 'fs'
 import path from 'path'
 
-
+// run bootstrap
 init()
 
+// bootstrap flow
 async function init() {
+    // prepare database and import data
     const [databaseManager, connection] = await createDatabaseManager()
-    const data = loadData()
 
+    // escape if db is already initialized
     if (await isDbInitialized(databaseManager)) {
         await connection.close()
         return
     }
 
+    // load import data
+    const data = loadData()
+
+    // bootstrap entities
     await bootMembers(databaseManager, data.members)
     await bootWorkers(databaseManager, data.workers)
 
@@ -38,14 +44,13 @@ async function isDbInitialized(db: DatabaseManager): Promise<boolean> {
     return !!membership
 }
 
-
-//async function createDatabaseManager(): Promise<DatabaseManager> {
 async function createDatabaseManager(): Promise<[DatabaseManager, Connection]> {
     // paths in `entities` should be the same as `entities` set in `manifest.yml`
     const entities = [
         'generated/graphql-server/dist/**/*.model.js'
     ]
 
+    // connect to db and create manager
     const connection = await createDBConnection(entities)
     const entityManager = getManager(connection.name)
     const databaseManager = makeDatabaseManager(entityManager)

+ 3 - 3
query-node/mappings/bootstrap/workers.ts

@@ -8,7 +8,7 @@ export interface IBootstrapWorkers {
 }
 
 export interface IBootstrapWorker {
-  role_account_id: string
+  id: string
 }
 
 export async function bootWorkers(db: DatabaseManager, workers: IBootstrapWorkers): Promise<void> {
@@ -25,7 +25,7 @@ export async function bootWorkersInGroup(db: DatabaseManager, workers: IBootstra
     // create new membership
     const worker = new Worker({
       // main data
-      workerId: rawWorker.role_account_id,
+      workerId: rawWorker.id,
       type: workerType,
       isActive: true,
     })
@@ -34,6 +34,6 @@ export async function bootWorkersInGroup(db: DatabaseManager, workers: IBootstra
     await db.save<Worker>(worker)
 
     // emit log event
-    logger.info('Worker has been bootstrapped', {id: rawWorker.role_account_id, workerType})
+    logger.info('Worker has been bootstrapped', {id: rawWorker.id, workerType})
   }
 }