Skip to content

Commit

Permalink
[Refactor] separate ApplicationContext
Browse files Browse the repository at this point in the history
  • Loading branch information
cdiaz committed May 8, 2018
1 parent b62319e commit 4fb6fc7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/app.context.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';

let context = null;
export const ApplicationContext = async () => {
if (!context) {
context = await NestFactory.create(AppModule);
}
return context;
}
4 changes: 2 additions & 2 deletions src/bull-queue/processors/btcprice.processor.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NestFactory } from '@nestjs/core';
import { ApplicationContext } from '../../app.context';
import { BtcPriceModule } from '../../btcprice/btcprice.module';
import { BtcPriceService } from '../../btcprice/btcprice.service';

const BtcPriceProcessor = async (job) => {

const context = await NestFactory.createApplicationContext(BtcPriceModule);
const context = await ApplicationContext();
const btcPriceService = context.get(BtcPriceService);

return await btcPriceService.fetch(job.data.currency)
Expand Down
5 changes: 2 additions & 3 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { ApplicationContext } from './app.context';
import 'dotenv/config';

async function bootstrap() {
const app = await NestFactory.create(AppModule);
const app = await ApplicationContext();
await app.listen(process.env.APP_PORT);
}

Expand Down

0 comments on commit 4fb6fc7

Please sign in to comment.