-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🎸 add chainsync(background task)
- Loading branch information
1 parent
e9aa70d
commit 6d8adb4
Showing
2 changed files
with
27 additions
and
1 deletion.
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { RootController } from './root/root.controller'; | ||
import { RootService } from './root/root.service'; | ||
import { ChainsyncService } from './chainsync/chainsync.service'; | ||
|
||
@Module({ | ||
imports: [], | ||
controllers: [RootController], | ||
providers: [RootService], | ||
providers: [RootService, ChainsyncService], | ||
}) | ||
export class AppModule {} |
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'; | ||
|
||
@Injectable() | ||
export class ChainsyncService implements OnModuleInit { | ||
async onModuleInit() { | ||
await this.startBackgroundTask(); | ||
} | ||
|
||
private async startBackgroundTask() { | ||
while (true) { | ||
try { | ||
console.log( | ||
'Always craw the lastest tipset ,blockMessages and messages ', | ||
); | ||
await this.delay(1000); | ||
} catch (error) { | ||
console.error('Error in background task:', error); | ||
} | ||
} | ||
} | ||
|
||
private async delay(ms: number): Promise<void> { | ||
return new Promise((resolve) => setTimeout(resolve, ms)); | ||
} | ||
} |