miaowing / nest-schedule

A cron-like and not-cron-like job distributed scheduler for Nest.js by decorators.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dynamic cron job supporting locks - doens't seem to work ?

iangregsondev opened this issue · comments

Hi,

I tried implementing the locks uisng decorators, this worked great but then i need to change to a dynamic cron job - so i can control when if it starts or not.. so i did

@Injectable()
export class CleanDbScheduleService extends NestDistributedSchedule {
  lock: boolean = false

  constructor(
    private readonly tokenService: TokenService,
    @InjectSchedule() private readonly schedule: Schedule,
    private readonly configService: ConfigService
  ) {
    super()
  }

  async tryLock(method: string): Promise<TryRelease> {
    console.log("inside trylock")
    if (this.lock) {
      return false
    }
    console.log("locking")
    this.lock = true
    return (): void => {
      console.log("releaseing")
      this.lock = false
    }
  }

  createJob(): void {
    this.schedule.scheduleIntervalJob("my-job", ms(this.configService.jobCleanDbInterval), () => this.cronJob())
  }

Works great, the job executes, but the locks are NOT being called.

Any ideas ?

Thanks

Thanks, but the locks dont seem to be executed, i get no console logs.

The job executes and i can see the console.log from my job but not the locks.

This is a dynamic module that I call using createJob but I extend NestDistributedSchedule, maybe this is the issue.

The 2 are not compatible ?

commented

Thanks, but the locks dont seem to be executed, i get no console logs.

The job executes and i can see the console.log from my job but not the locks.

This is a dynamic module that I call using createJob but I extend NestDistributedSchedule, maybe this is the issue.

The 2 are not compatible ?

Sorry. The dynamic job not supports distributed locks, now. I will resolve it in future version.

OK, great. Thanks for the confirmation