-
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.
[@dhealthdapps/backend] feat(routes): update of validationScheduler
- Loading branch information
1 parent
cd34714
commit c939088
Showing
5 changed files
with
97 additions
and
57 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
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
55 changes: 55 additions & 0 deletions
55
runtime/backend/src/common/schedulers/ValidateChallengeScheduler.ts
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,55 @@ | ||
/** | ||
* This file is part of dHealth dApps Framework shared under LGPL-3.0 | ||
* Copyright (C) 2022-present dHealth Network, All rights reserved. | ||
* | ||
* @package dHealth dApps Framework | ||
* @subpackage Backend | ||
* @author dHealth Network <[email protected]> | ||
* @license LGPL-3.0 | ||
*/ | ||
|
||
import { Injectable } from "@nestjs/common"; | ||
import { CronJob } from "cron"; | ||
import { SchedulerRegistry } from "@nestjs/schedule"; | ||
|
||
import { AuthService } from "../services"; | ||
|
||
@Injectable() | ||
export class ValidateChallengeScheduler { | ||
constructor( | ||
private readonly schedulerRegistry: SchedulerRegistry, | ||
protected readonly authService: AuthService, | ||
) {} | ||
|
||
protected job: CronJob; | ||
|
||
public addCronJob(cronExpression: string, challenge: string) { | ||
this.job = new CronJob( | ||
cronExpression, // cronTime | ||
this.validate.bind(this, challenge), // onTick | ||
undefined, // empty onComplete | ||
false, // "startNow" (done with L183) | ||
undefined, // timeZone | ||
undefined, // empty resolves to default context | ||
true, // "runOnInit" | ||
); | ||
|
||
// add cron to nest scheduler registry | ||
this.schedulerRegistry.addCronJob( | ||
`statistics:cronjobs:leaderboards:D`, | ||
this.job, | ||
); | ||
|
||
this.job.start(); | ||
|
||
console.log("VALIDATION SCHEDULER IS UP AND RUNNING!!!!!!!!!!!!!!!!!!!!!!"); | ||
} | ||
|
||
protected validate(challenge: string) { | ||
this.authService.validateChallenge(challenge); | ||
} | ||
|
||
protected stopCronJob() { | ||
this.job.stop(); | ||
} | ||
} |