-
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
80fc423
commit cba7d63
Showing
2 changed files
with
30 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { Injectable, OnModuleInit } from '@nestjs/common'; | ||
import { Config } from 'src/components/config/config'; | ||
import { Logger } from '../../../components/utils/logger'; | ||
|
||
@Injectable() | ||
export class Scheduler implements OnModuleInit { | ||
constructor( | ||
private readonly config: Config, | ||
private readonly logger: Logger, | ||
) {} | ||
|
||
async onModuleInit(): Promise<void> { | ||
setTimeout(this.job.bind(this), this.getMsUntilNextHour()); | ||
} | ||
|
||
private async job(): Promise<void> { | ||
this.logger.info('Scheduler job'); | ||
} | ||
|
||
private getMsUntilNextHour(): number { | ||
const now = new Date(); | ||
const nextHour = new Date(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours() + 1); | ||
return nextHour.getTime() - now.getTime(); | ||
} | ||
} |
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,11 +1,14 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { UserService } from '../architecture/service/main/user'; | ||
import { RepositoryModule } from './repository'; | ||
import { Scheduler } from '../architecture/service/main/scheduler'; | ||
import { ConfigModule } from './config'; | ||
import { InfrastructureModule } from './infrastructure'; | ||
|
||
@Module({ | ||
imports: [RepositoryModule], | ||
imports: [ConfigModule, InfrastructureModule, RepositoryModule], | ||
controllers: [], | ||
providers: [UserService], | ||
providers: [UserService, Scheduler], | ||
exports: [UserService], | ||
}) | ||
export class ServiceModule {} |