Setting values in extended class in tryLock
sloan-dog opened this issue · comments
sloan-dog commented
Instance properties in tryLock which are defined on subclass are never read properly in tryLock...please help i feel like i broke javascript
class ScheduleService extends NestDistributedSchedule {
private runJobs = true
constructor() {
super()
}
async tryLock() {
console.log(this.runJobs) // Always true even if setRunJobsFalse called
}
setRunJobsFalse() {
this.runJobs = false;
console.log(this.runJobs) // False
}
}
Miaow commented
Maybe your code has other wrong, can you give me some more details.
import { NestDistributedSchedule, Interval } from 'nest-schedule';
import { Injectable } from "@nestjs/common";
@Injectable()
export class ScheduleService extends NestDistributedSchedule {
private runJobs = true;
private count = 0;
constructor() {
super()
}
@Interval(2000)
do() {
console.log('job: ', this.count++);
this.setRunJobsFalse();
}
async tryLock() {
console.log('job: ', this.count, 'lock: ', this.runJobs); // Always true even if setRunJobsFalse called
return null;
}
setRunJobsFalse() {
this.runJobs = false;
console.log('set run job: ', this.runJobs); // False
}
}
log:
job: 0 lock: true
job: 0
set run job: false
job: 1 lock: false
job: 1
set run job: false