-
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.
- Loading branch information
1 parent
cf54872
commit 3bc4c1d
Showing
6 changed files
with
69 additions
and
25 deletions.
There are no files selected for viewing
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,22 @@ | ||
import { Process, Processor } from '@nestjs/bull'; | ||
import { Injectable } from '@nestjs/common'; | ||
import { InjectRepository } from '@nestjs/typeorm'; | ||
import { Job } from 'bull'; | ||
import { UserActivity } from 'src/entities/user-activity.entity'; | ||
import { CreateUserActivityInput } from 'src/models/dtos/create-user-activity.input'; | ||
import { Repository } from 'typeorm'; | ||
|
||
@Injectable() | ||
@Processor('user-activity') | ||
export class UserActivityConsumer { | ||
constructor( | ||
@InjectRepository(UserActivity) | ||
private readonly userActivityRepository: Repository<UserActivity>, | ||
) {} | ||
|
||
@Process('user-activity') | ||
async processUserActivityJob(job: Job<CreateUserActivityInput>) { | ||
const { data } = job; | ||
await this.userActivityRepository.save(data); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,27 @@ | ||
import { BullModule } from '@nestjs/bull'; | ||
import { Module } from '@nestjs/common'; | ||
import { TypeOrmModule } from '@nestjs/typeorm'; | ||
import { UserActivityConsumer } from 'src/consumers/user-activity.consumer'; | ||
import { UserController } from 'src/controllers/user.controller'; | ||
import { UserActivity } from 'src/entities/user-activity.entity'; | ||
import { User } from 'src/entities/user.entity'; | ||
import { UserStatsView } from 'src/entities/views/user-stats.view'; | ||
import { StorageClientService } from 'src/providers/storage-client.service'; | ||
import { UserService } from '../providers/user.service'; | ||
import { UserResolver } from '../resolvers/user.resolver'; | ||
import { UserController } from 'src/controllers/user.controller'; | ||
import { StorageClientService } from 'src/providers/storage-client.service'; | ||
import { BullModule } from '@nestjs/bull'; | ||
import { UserActivity } from 'src/entities/user-activity.entity'; | ||
|
||
@Module({ | ||
imports: [ | ||
TypeOrmModule.forFeature([User, UserStatsView, UserActivity]), | ||
BullModule.registerQueue({ | ||
name: 'user-activity', | ||
}), | ||
BullModule.registerQueue({ | ||
name: 'online-users', | ||
}), | ||
], | ||
controllers: [UserController], | ||
providers: [UserResolver, UserService, StorageClientService], | ||
providers: [UserResolver, UserService, StorageClientService, UserActivityConsumer], | ||
exports: [UserService, StorageClientService], | ||
}) | ||
export class UserModule {} |
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
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